Documentation application
This page provides guidance on using Cloud Shell to download and run samples from the GitHub golang-samples/profiler repository. You can also run these samples outside of Google Cloud. For the additional configuration steps required in this case, see Profiling applications running outside of Google Cloud.
If you choose to run these programs, you can quickly create profiling data that you can use to explore the capabilities of the Cloud Profiler interface. You can also modify your copy of these samples, then redeploy and analyze the impact of your changes using the Cloud Profiler interface.
Before you begin
- 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.
-
Enable the Cloud Profiler API.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Enable the Cloud Profiler API.
Start Cloud Shell
At the top of the Google Cloud console page for your project, click Activate Cloud Shell:
A Cloud Shell session opens inside a new frame at the bottom of the console and displays two messages and a command-line prompt. The first message lists the Google Cloud project for your Cloud Shell session. The second message tells you how to change the session project. It can take a few seconds for the shell session to be initialized:
Get a program to profile
From Cloud Shell, retrieve the package of Go samples:
git clone https://github.com/GoogleCloudPlatform/golang-samples.git
The package retrieval takes a few moments to complete.
profiler_quickstart
The sample profiler_quickstart
is configured to run the hello-profiler
service. The Profiler quickstart
uses this sample.
To start hello-profiler
, do the following:
Change to the
profiler_quickstart
directory:cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/profiler_quickstart
Start the service by running the following command:
go run main.go
The message profiler has started
is displayed in your Cloud Shell
session a few seconds after you start the service. New messages are displayed
each time a profile is uploaded to your Google Cloud
project.
To stop the service, enter Ctrl-C.
hotapp
The sample hotapp
uses an infinite loop that calls two functions, and then
the Go scheduler. The sample supports setting the flag -local_work
. When this
flag is true
, work, in the form of for loops, is added to individual
functions. By default, this flag is set to false
.
To run the hotapp
sample, do the following:
Change to the
hotapp
directory:cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/hotapp
Start the service by running the following command:
go run main.go
If you wish to generate profile data that is consistent with data shown in the Cloud Profiler documentation, then use the following invocation:
go run main.go -service=docdemo-service -local_work -skew=75 -version=1.75.0
The message profiler has started
is displayed in your Cloud Shell
session a few seconds after you start the service. New messages are displayed
each time a profile is uploaded to your Google Cloud
project.
To stop the service, enter Ctrl-C.
The section on comparing profiles used
two different deployments of the docdemo-service
. In one deployment, the
skew
and version
were set as previously described. In the second
deployment, the skew
was set to 25
and the version
was set to 1.25.0
.
Troubleshooting
If you receive a permission denied error message after starting the service, see Errors with your Google Cloud project configuration.