- 0.115.1 (latest)
- 0.115.0
- 0.114.0
- 0.113.0
- 0.112.2
- 0.111.0
- 0.110.10
- 0.109.0
- 0.108.0
- 0.107.0
- 0.106.0
- 0.105.0
- 0.104.0
- 0.103.0
- 0.102.1
- 0.101.1
- 0.100.2
- 0.99.0
- 0.98.0
- 0.97.0
- 0.96.0
- 0.95.0
- 0.94.1
- 0.93.3
- 0.92.3
- 0.91.1
- 0.90.0
- 0.89.0
- 0.88.0
- 0.87.0
- 0.86.0
- 0.85.0
- 0.84.0
- 0.83.0
- 0.82.0
- 0.81.0
- 0.80.0
- 0.79.0
- 0.78.0
- 0.77.0
- 0.76.0
- 0.75.0
Package profiler is a client for the Cloud Profiler service.
Usage example:
import "cloud.google.com/go/profiler" ... if err := profiler.Start(profiler.Config{Service: "my-service"}); err != nil { // TODO: Handle error. }
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.
Functions
func Start
func Start(cfg Config, options ...option.ClientOption) error
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.
Example
package main
import (
"cloud.google.com/go/profiler"
)
func main() {
if err := profiler.Start(profiler.Config{Service: "my-service", ServiceVersion: "v1"}); err != nil {
//TODO: Handle error.
}
}
Config
type Config struct {
// 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.
Service string
// 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.
ServiceVersion string
// DebugLogging enables detailed debug logging from profiler. It
// defaults to false.
DebugLogging bool
// MutexProfiling enables mutex profiling. It defaults to false.
// Note that mutex profiling is not supported by Go versions older
// than Go 1.8.
MutexProfiling bool
// When true, collecting the CPU profiles is disabled.
NoCPUProfiling bool
// When true, collecting the allocation profiles is disabled.
NoAllocProfiling bool
// 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.
AllocForceGC bool
// When true, collecting the heap profiles is disabled.
NoHeapProfiling bool
// When true, collecting the goroutine profiles is disabled.
NoGoroutineProfiling bool
// When true, the agent sends all telemetries via OpenCensus exporter, which
// can be viewed in Cloud Trace and Cloud Monitoring.
// Default is false.
EnableOCTelemetry bool
// 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.
ProjectID string
// APIAddr is the HTTP endpoint to use to connect to the profiler
// agent API. Defaults to the production environment, overridable
// for testing.
APIAddr string
// 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.
Instance string
// 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.
Zone string
// contains filtered or unexported fields
}
Config is the profiler configuration.