이 프로그램을 실행하면 Cloud Profiler 인터페이스의 기능을 탐색하는 데 사용할 수 있는 프로파일링 데이터를 빠르게 만들 수 있습니다.
이러한 샘플의 복사본을 수정하고 다시 배포한 후 Cloud Profiler 인터페이스를 사용하여 변경사항이 미치는 영향을 분석할 수도 있습니다.
시작하기 전에
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
프로젝트의 Google Cloud Console 페이지 상단에 있는 Cloud Shell 활성화를 클릭합니다.
Console 하단의 새 프레임에서 Cloud Shell 세션이 열리고 메시지 두 개와 명령줄 프롬프트가 표시됩니다. 첫 번째 메시지에는 Cloud Shell 세션의 Google Cloud 프로젝트가 나열됩니다. 두 번째 메시지는 세션 프로젝트를 변경하는 방법을 알려줍니다.
셸 세션이 초기화되는 데 몇 초 정도 걸릴 수 있습니다.
profiler_quickstart 샘플은 hello-profiler 서비스를 실행하도록 구성됩니다. Profiler 빠른 시작에서는 이 샘플을 사용합니다.
hello-profiler를 시작하려면 다음을 수행합니다.
profiler_quickstart 디렉터리로 변경합니다.
cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/profiler_quickstart
다음 명령어를 실행하여 서비스를 시작합니다.
gorunmain.go
서비스를 시작하고 몇 초 후에 Cloud Shell 세션에 profiler has started 메시지가 표시됩니다. 프로필이 Google Cloud 프로젝트에 업로드될 때마다 새 메시지가 표시됩니다.
서비스를 중지하려면 Ctrl-C를 입력합니다.
hotapp
hotapp 샘플에서는 함수 두 개를 호출하는 무한 루프를 사용한 후 Go 스케줄러를 사용합니다. 이 샘플은 -local_work 플래그 설정을 지원합니다. 이 플래그가 true이면 루프 형식의 작업이 개별 함수에 추가됩니다. 기본적으로 이 플래그는 false로 설정되어 있습니다.
hotapp 샘플을 실행하려면 다음을 수행합니다.
hotapp 디렉터리로 변경합니다.
cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/hotapp
다음 명령어를 실행하여 서비스를 시작합니다.
gorunmain.go
Cloud Profiler 문서에 표시된 데이터와 일치하는 프로필 데이터를 생성하려면 다음 호출을 사용합니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["# Documentation application\n=========================\n\nThis page provides guidance on using Cloud Shell to download\nand run samples from the GitHub\n[golang-samples/profiler](https://github.com/GoogleCloudPlatform/golang-samples/tree/master/profiler)\nrepository. You can also run these samples outside of\nGoogle Cloud. For the additional configuration steps required in this case,\nsee [Profiling applications running outside of Google Cloud](/profiler/docs/profiling-external).\n\nIf you choose to run these programs, you can quickly create profiling data that\nyou can use to explore the capabilities of the Cloud Profiler interface.\nYou can also modify your copy of these samples, then redeploy and analyze the\nimpact of your changes using the Cloud Profiler interface.\n\nBefore you begin\n----------------\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n\n\n Enable the Cloud Profiler API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=cloudprofiler.googleapis.com&redirect=https://console.cloud.google.com)\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n\n\n Enable the Cloud Profiler API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=cloudprofiler.googleapis.com&redirect=https://console.cloud.google.com)\n\n\u003cbr /\u003e\n\nStart Cloud Shell\n-----------------\n\nAt the top of the Google Cloud console page for your project, click\n**Activate Cloud Shell**:\n\nA Cloud Shell session opens inside a new frame at the bottom of the\nconsole and displays two messages and a command-line prompt. The first\nmessage lists the Google Cloud project for your Cloud Shell\nsession. The second message tells you how to change the session project.\nIt can take a few seconds for the shell session to be initialized:\n\nGet a program to profile\n------------------------\n\nFrom Cloud Shell, retrieve the package of Go samples: \n\n git clone https://github.com/GoogleCloudPlatform/golang-samples.git\n\nThe package retrieval takes a few moments to complete.\n\n### profiler_quickstart\n\nThe sample `profiler_quickstart` is configured to run the `hello-profiler`\nservice. The [Profiler quickstart](/profiler/docs/measure-app-performance)\nuses this sample.\n\nTo start `hello-profiler`, do the following:\n\n1. Change to the `profiler_quickstart` directory:\n\n cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/profiler_quickstart\n\n2. Start the service by running the following command:\n\n go run main.go\n\nThe message `profiler has started` is displayed in your Cloud Shell\nsession a few seconds after you start the service. New messages are displayed\neach time a profile is uploaded to your Google Cloud\nproject.\n\nTo stop the service, enter Ctrl-C.\n\n### hotapp\n\nThe sample `hotapp` uses an infinite loop that calls two functions, and then\nthe Go scheduler. The sample supports setting the flag `-local_work`. When this\nflag is `true`, work, in the form of for loops, is added to individual\nfunctions. By default, this flag is set to `false`.\n\nTo run the `hotapp` sample, do the following:\n\n1. Change to the `hotapp` directory:\n\n cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/hotapp\n\n2. Start the service by running the following command:\n\n go run main.go\n\n If you wish to generate profile data that is consistent with\n data shown in the Cloud Profiler documentation,\n then use the following invocation: \n\n go run main.go -service=docdemo-service -local_work -skew=75 -version=1.75.0\n\nThe message `profiler has started` is displayed in your Cloud Shell\nsession a few seconds after you start the service. New messages are displayed\neach time a profile is uploaded to your Google Cloud\nproject.\n\nTo stop the service, enter Ctrl-C.\n\nThe section on [comparing profiles](/profiler/docs/comparing-profiles) used\ntwo different deployments of the `docdemo-service`. In one deployment, the\n`skew` and `version` were set as previously described. In the second\ndeployment, the `skew` was set to `25` and the `version` was set to `1.25.0`.\n\nTroubleshooting\n---------------\n\nIf you receive a permission denied error message after starting the service,\nsee\n[Errors with your Google Cloud project configuration](/profiler/docs/troubleshooting#errors-configuration)."]]