Cloud Profiler - Package cloud.google.com/go/profiler (v0.4.3)

Note: To get more information about this package, such as access to older versions, viewthis package on pkg.go.dev.

Package profiler is a client for the Cloud Profiler service.

Usage example:

import"cloud.google.com/go/profiler"...iferr:=profiler.Start(profiler.Config{Service:"my-service"});err!=nil{// TODO: Handle error.}

Calling Start will start a goroutine to collect profiles and upload tothe profiler server, at the rhythm specified by the server.

The caller must provide the service string in the config, and may provideother information as well. See Config for details.

Profiler has CPU, heap and goroutine profiling enabled by default. Mutexprofiling can be enabled in the config. Note that goroutine and mutexprofiles are shown as "threads" and "contention" profiles in the profilerUI.

Functions

func Start

funcStart(cfgConfig,options...option.ClientOption)error

Start starts a goroutine to collect and upload profiles. Thecaller must provide the service string in the config. SeeConfig for details. Start should only be called once. Anyadditional calls will be ignored.

Example

packagemainimport("cloud.google.com/go/profiler")funcmain(){iferr:=profiler.Start(profiler.Config{Service:"my-service",ServiceVersion:"v1"});err!=nil{//TODO: Handle error.}}

Config

typeConfigstruct{// Service must be provided to start the profiler. It specifies the name of// the service under which the profiled data will be recorded and exposed at// the Profiler UI for the project. You can specify an arbitrary string, but// see Deployment.target at// https://github.com/googleapis/googleapis/blob/master/google/devtools/cloudprofiler/v2/profiler.proto// for restrictions. If the parameter is not set, the agent will probe// GAE_SERVICE environment variable which is present in Google App Engine// environment.// NOTE: The string should be the same across different replicas of// your service so that the globally constant profiling rate is// maintained. Do not put things like PID or unique pod ID in the name.Servicestring// ServiceVersion is an optional field specifying the version of the// service. It can be an arbitrary string. Profiler profiles// once per minute for each version of each service in each zone.// ServiceVersion defaults to GAE_VERSION environment variable if that is// set, or to empty string otherwise.ServiceVersionstring// DebugLogging enables detailed debug logging from profiler. It// defaults to false.DebugLoggingbool// DebugLoggingOutput is where the logger will write debug logs to, if enabled.// It defaults to os.Stderr.DebugLoggingOutputio.Writer// MutexProfiling enables mutex profiling. It defaults to false.// Note that mutex profiling is not supported by Go versions older// than Go 1.8.MutexProfilingbool// When true, collecting the CPU profiles is disabled.NoCPUProfilingbool// When true, collecting the allocation profiles is disabled.NoAllocProfilingbool// AllocForceGC forces garbage collection before the collection of each heap// profile collected to produce the allocation profile. This increases the// accuracy of allocation profiling. It defaults to false.AllocForceGCbool// When true, collecting the heap profiles is disabled.NoHeapProfilingbool// When true, collecting the goroutine profiles is disabled.NoGoroutineProfilingbool// When true, the agent sends all telemetries via OpenCensus exporter, which// can be viewed in Cloud Trace and Cloud Monitoring.// Default is false.EnableOCTelemetrybool// ProjectID is the Cloud Console project ID to use instead of the one set by// GOOGLE_CLOUD_PROJECT environment variable or read from the VM metadata// server.//// Set this if you are running the agent in your local environment// or anywhere else outside of Google Cloud Platform.ProjectIDstring// APIAddr is the HTTP endpoint to use to connect to the profiler// agent API. Defaults to the production environment, overridable// for testing.APIAddrstring// Instance is the name of Compute Engine instance the profiler agent runs// on. This is normally determined from the Compute Engine metadata server// and doesn't need to be initialized. It needs to be set in rare cases where// the metadata server is present but is flaky or otherwise misbehave.Instancestring// Zone is the zone of Compute Engine instance the profiler agent runs// on. This is normally determined from the Compute Engine metadata server// and doesn't need to be initialized. It needs to be set in rare cases where// the metadata server is present but is flaky or otherwise misbehave.Zonestring// contains filtered or unexported fields}

Config is the profiler configuration.

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 2025-10-30 UTC.