Calling Start will start a goroutine to collect profiles and upload to
the profiler server, at the rhythm specified by the server.
The caller must provide the service string in the config, and may provide
other information as well. See Config for details.
Profiler has CPU, heap and goroutine profiling enabled by default. Mutex
profiling can be enabled in the config. Note that goroutine and mutex
profiles are shown as "threads" and "contention" profiles in the profiler
UI.
Start starts a goroutine to collect and upload profiles. The
caller must provide the service string in the config. See
Config for details. Start should only be called once. Any
additional calls will be ignored.
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}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eprofiler\u003c/code\u003e package is a client for the Cloud Profiler service, allowing users to collect and upload profiles to the profiler server.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eStart\u003c/code\u003e function initiates a goroutine to collect profiles, with the service string being a mandatory configuration parameter.\u003c/p\u003e\n"],["\u003cp\u003eBy default, CPU, heap, and goroutine profiling are enabled, while mutex profiling can be optionally activated in the configuration.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eConfig\u003c/code\u003e struct allows detailed customization of profiling, including service name, version, debugging options, and enabling/disabling specific profiling types such as CPU, heap, goroutine, and mutex.\u003c/p\u003e\n"],["\u003cp\u003eThe latest package version is 0.4.2, and older versions are available, accessible through links in the content provided.\u003c/p\u003e\n"]]],[],null,["# Cloud Profiler - Package cloud.google.com/go/profiler (v0.4.2)\n\nVersion latestkeyboard_arrow_down\n\n- [0.4.2 (latest)](/go/docs/reference/cloud.google.com/go/profiler/latest)\n- [0.4.1](/go/docs/reference/cloud.google.com/go/profiler/0.4.1)\n- [0.3.1](/go/docs/reference/cloud.google.com/go/profiler/0.3.1)\n- [0.2.0](/go/docs/reference/cloud.google.com/go/profiler/0.2.0)\n- [0.1.2](/go/docs/reference/cloud.google.com/go/profiler/0.1.2) \n**Note:** To get more information about this package, such as access to older versions, view [this package on pkg.go.dev](https://pkg.go.dev/cloud.google.com/go/profiler). \n\u003cbr /\u003e\n\nPackage profiler is a client for the Cloud Profiler service.\n\nUsage example: \n\n```go\nimport \"cloud.google.com/go/profiler\"\n...\nif err := profiler.Start(profiler.Config{Service: \"my-service\"}); err != nil {\n // TODO: Handle error.\n}\n```\n\n\u003cbr /\u003e\n\nCalling Start will start a goroutine to collect profiles and upload to\nthe profiler server, at the rhythm specified by the server.\n\nThe caller must provide the service string in the config, and may provide\nother information as well. See Config for details.\n\nProfiler has CPU, heap and goroutine profiling enabled by default. Mutex\nprofiling can be enabled in the config. Note that goroutine and mutex\nprofiles are shown as \"threads\" and \"contention\" profiles in the profiler\nUI. \n\nFunctions\n---------\n\n### func Start\n\n func Start(cfg #cloud_google_com_go_profiler_Config, options ...https://pkg.go.dev/google.golang.org/api/option.https://pkg.go.dev/google.golang.org/api/option#ClientOption) https://pkg.go.dev/builtin#error\n\nStart starts a goroutine to collect and upload profiles. The\ncaller must provide the service string in the config. See\nConfig for details. Start should only be called once. Any\nadditional calls will be ignored. \n\n#### Example\n\n package main\n\n import (\n \t\"cloud.google.com/go/profiler\"\n )\n\n func main() {\n \tif err := profiler.https://cloud.google.com/go/docs/reference/cloud.google.com/go/profiler/latest/index.html#cloud_google_com_go_profiler_Start(profiler.https://cloud.google.com/go/docs/reference/cloud.google.com/go/profiler/latest/index.html#cloud_google_com_go_profiler_Config{Service: \"my-service\", ServiceVersion: \"v1\"}); err != nil {\n \t\t//TODO: Handle error.\n \t}\n }\n\nConfig\n------\n\n type Config struct {\n \t// Service must be provided to start the profiler. It specifies the name of\n \t// the service under which the profiled data will be recorded and exposed at\n \t// the Profiler UI for the project. You can specify an arbitrary string, but\n \t// see Deployment.target at\n \t// https://github.com/googleapis/googleapis/blob/master/google/devtools/cloudprofiler/v2/profiler.proto\n \t// for restrictions. If the parameter is not set, the agent will probe\n \t// GAE_SERVICE environment variable which is present in Google App Engine\n \t// environment.\n \t// NOTE: The string should be the same across different replicas of\n \t// your service so that the globally constant profiling rate is\n \t// maintained. Do not put things like PID or unique pod ID in the name.\n \tService https://pkg.go.dev/builtin#string\n\n \t// ServiceVersion is an optional field specifying the version of the\n \t// service. It can be an arbitrary string. Profiler profiles\n \t// once per minute for each version of each service in each zone.\n \t// ServiceVersion defaults to GAE_VERSION environment variable if that is\n \t// set, or to empty string otherwise.\n \tServiceVersion https://pkg.go.dev/builtin#string\n\n \t// DebugLogging enables detailed debug logging from profiler. It\n \t// defaults to false.\n \tDebugLogging https://pkg.go.dev/builtin#bool\n\n \t// DebugLoggingOutput is where the logger will write debug logs to, if enabled.\n \t// It defaults to os.Stderr.\n \tDebugLoggingOutput https://pkg.go.dev/io.https://pkg.go.dev/io#Writer\n\n \t// MutexProfiling enables mutex profiling. It defaults to false.\n \t// Note that mutex profiling is not supported by Go versions older\n \t// than Go 1.8.\n \tMutexProfiling https://pkg.go.dev/builtin#bool\n\n \t// When true, collecting the CPU profiles is disabled.\n \tNoCPUProfiling https://pkg.go.dev/builtin#bool\n\n \t// When true, collecting the allocation profiles is disabled.\n \tNoAllocProfiling https://pkg.go.dev/builtin#bool\n\n \t// AllocForceGC forces garbage collection before the collection of each heap\n \t// profile collected to produce the allocation profile. This increases the\n \t// accuracy of allocation profiling. It defaults to false.\n \tAllocForceGC https://pkg.go.dev/builtin#bool\n\n \t// When true, collecting the heap profiles is disabled.\n \tNoHeapProfiling https://pkg.go.dev/builtin#bool\n\n \t// When true, collecting the goroutine profiles is disabled.\n \tNoGoroutineProfiling https://pkg.go.dev/builtin#bool\n\n \t// When true, the agent sends all telemetries via OpenCensus exporter, which\n \t// can be viewed in Cloud Trace and Cloud Monitoring.\n \t// Default is false.\n \tEnableOCTelemetry https://pkg.go.dev/builtin#bool\n\n \t// ProjectID is the Cloud Console project ID to use instead of the one set by\n \t// GOOGLE_CLOUD_PROJECT environment variable or read from the VM metadata\n \t// server.\n \t//\n \t// Set this if you are running the agent in your local environment\n \t// or anywhere else outside of Google Cloud Platform.\n \tProjectID https://pkg.go.dev/builtin#string\n\n \t// APIAddr is the HTTP endpoint to use to connect to the profiler\n \t// agent API. Defaults to the production environment, overridable\n \t// for testing.\n \tAPIAddr https://pkg.go.dev/builtin#string\n\n \t// Instance is the name of Compute Engine instance the profiler agent runs\n \t// on. This is normally determined from the Compute Engine metadata server\n \t// and doesn't need to be initialized. It needs to be set in rare cases where\n \t// the metadata server is present but is flaky or otherwise misbehave.\n \tInstance https://pkg.go.dev/builtin#string\n\n \t// Zone is the zone of Compute Engine instance the profiler agent runs\n \t// on. This is normally determined from the Compute Engine metadata server\n \t// and doesn't need to be initialized. It needs to be set in rare cases where\n \t// the metadata server is present but is flaky or otherwise misbehave.\n \tZone https://pkg.go.dev/builtin#string\n \t// contains filtered or unexported fields\n }\n\nConfig is the profiler configuration."]]