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.
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-18。"],[],[],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)."]]