# Documentation application

This page provides guidance on using Cloud Shell to download
and run samples from the GitHub
[golang-samples/profiler](https://github.com/GoogleCloudPlatform/golang-samples/tree/master/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](https://docs.cloud.google.com/profiler/docs/profiling-external.md.txt).

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

<br />

## Start Cloud Shell

At the top of the Google Cloud console page for your project, click
**Activate Cloud Shell**:

![Activate Cloud Shell.](https://docs.cloud.google.com/static/profiler/docs/images/startcloudshell1.png)

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:

![Cloud Shell session.](https://docs.cloud.google.com/static/profiler/docs/images/startcloudshell2.png)

## 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](https://docs.cloud.google.com/profiler/docs/measure-app-performance.md.txt)
uses this sample.

To start `hello-profiler`, do the following:

1. Change to the `profiler_quickstart` directory:

       cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/profiler_quickstart

2. 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:

1. Change to the `hotapp` directory:

       cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/hotapp

2. 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](https://docs.cloud.google.com/profiler/docs/comparing-profiles.md.txt) 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](https://docs.cloud.google.com/profiler/docs/troubleshooting.md.txt#errors-configuration).