Measure app performance

This document shows you how to set up and use Cloud Profiler. You usethe Cloud Shell todownload a sample Go program, run it with profiling enabled, and thenuse the Profiler interface to explore the captured data.

If you plan to profile applications that are running outside ofGoogle Cloud, then you need to perform some configuration steps that aren'tdiscussed in this document. For information about these steps, seeProfiling applications running outside Google Cloud.

Before you begin

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    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.

    Go to project selector

  3. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    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.

    Go to project selector

  4. Enable the required API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the API

  5. To open the Cloud Shell, in the Google Cloud console toolbar, clickActivate Cloud Shell:

    Activate Cloud Shell.

    After a few moments, a Cloud Shell session opens inside theGoogle Cloud console:

    Cloud Shell session.

Get a program to profile

The sample program,main.go, is in thegolang-samples repository onGitHub. To get it, in the Cloud Shell, run the following commandto retrieve the package of Go samples:

git clone https://github.com/GoogleCloudPlatform/golang-samples.git

The package retrieval takes a few moments to complete.

Profile the code

In the Cloud Shell, goto the directory of sample code for Profiler in the retrievedpackage:

cd golang-samples/profiler/profiler_quickstart

Themain.go program creates a CPU-intensive workload to provide data tothe profiler. In the Cloud Shell, run the following command tostart the program, and leave it running:

gorunmain.go

This program is designed to load the CPU as it runs. It is configuredto use Profiler, which collects profiling data from the programas it runs and periodically saves it.

A few seconds after you start the program, you see the messageprofiler has started. In about a minute, two more messages are displayed:

successfullycreatedprofileCPUstartuploadingprofile

These messages indicate that a profile was created and uploaded to yourCloud Storage project. The program continues to emit the last two messages,about one time per minute, for as long as it runs.

If you receive a permission denied error message after starting the service,seeErrors with your Google Cloud project configuration.

Profiler interface

A few moments after you start the application, Profilerdisplays the initial profile data. The interface offers an array of controlsand a flame graph for exploring the profiling data:

Profiler interface with the sample code.

In addition to time controls, there are options that let you choose the setof profile data to use. When you are profiling multiple applications, you useService to select the origin of the profiled data.Profile type lets you choose the kindof profile data to display.Zone name andVersion let you restrictdisplay to data fromCompute Engine zones or versions ofthe application.Weight lets you select profiles captured during peakresource consumption.

To refine how the flame graph displays the profiles you've selected to analyze,you add filters. In the previous screenshot, the filter bar showsone filter. This filter option isMetric and the filter value isCPU time.

Exploring the data

The flame graph displays the call stacks of the program. The flame graphrepresents each function with a frame.The width of the frame represents the proportion of resource consumptionby that function.The top frame represents the entire program. This frame always shows 100%of the resource consumption. This frame also lists how many profiles areaveraged together in this graph.

The sample program doesn't have a complicated set of call stacks;in the preceding screenshot, you see 5 frames:

  • The gray frame represents the entire executable, which accounts for 100% ofthe resources being consumed.
  • The greenmain frame is the Goruntime.main.
  • The orangemain frame is themain routine of the sample program.
  • The orangebusyloop frame is a routine called from the sample'smain.
  • The orangemain.load frame is a routine called from the sample'smain.

The filter selector lets you do things like filter out functions that matchsome name. For example, if there is a standard library of utility functions,you can remove them from the graph. You can also remove call stacksoriginating at a certain method or simplify the graph in other ways.Themain.go application is simple, so there isn't much tofilter out.

Even for a simple application, filters let you hide uninteresting frames sothat you can more clearly view interesting frames. For example, in theprofiling screenshot for the sample code, the gray frame is slightlylarger than the firstmain frame under it. Why? Is there something elsegoing on that's not immediately apparent because themain call stackconsumes such an overwhelming percentage of the resources?To view what is occurring outside of the application'smain routine,add a filter that hides the call stack of themain routine.Only 0.227% of the resource consumption occurs outside ofmain:

Hiding stacks in the sample program.

For more information on filtering and other ways to explore the profilingdata, seeSelect the profiles to analyze.

Note: If the Profiler agent hasn't uploaded any profiles when youstart the interface, Profiler displays the messageNo data to show. The message is automatically replaced with theProfiler interface after profile data is available.

What's next

For general information about profiling, see the following documents:

For information on running the Cloud Profiler agent, see:

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.