Involved Source Filesheap.gomutex.go
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.
Package-Level Type Names (total 4, in which 1 are exported)
/* sort exporteds by: | */
Config is the profiler configuration.
APIAddr is the HTTP endpoint to use to connect to the profiler
agent API. Defaults to the production environment, overridable
for testing.
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.
DebugLogging enables detailed debug logging from profiler. It
defaults to false.
When true, the agent sends all telemetries via OpenCensus exporter, which
can be viewed in Cloud Trace and Cloud Monitoring.
Default is false.
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.
MutexProfiling enables mutex profiling. It defaults to false.
Note that mutex profiling is not supported by Go versions older
than Go 1.8.
When true, collecting the allocation profiles is disabled.
When true, collecting the CPU profiles is disabled.
When true, collecting the goroutine profiles is disabled.
When true, collecting the heap profiles is disabled.
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.
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.
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.
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.
numProfiles is the number of profiles which should be collected before
the profile collection loop exits.When numProfiles is 0, profiles will
be collected for the duration of the program. For testing only.
func Start(cfg Config, options ...option.ClientOption) error
func initializeConfig(cfg Config) error
func start(cfg Config, options ...option.ClientOption) error
var config
allowUntilSuccess is an object that will perform action till
it succeeds once.
This is a modified form of Go's sync.Once
doneuint32msync.Mutex
do calls function f only if it hasnt returned nil previously.
Once f returns nil, do will not call function f any more.
This is a modified form of Go's sync.Once.Do
var startOnce
Package-Level Functions (total 15, in which 1 are exported)
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.
abortedBackoffDuration retrieves the retry duration from gRPC trailing
metadata, which is set by the profiler server.
allocProfile collects a single heap profile, and removes all metrics but
allocation metrics.
deltaAllocProfile collects an allocation profile by gathering a heap profile,
sleeping for the specified duration, gathering another heap profile and
subtracting the initial one from that. It then drops the in-use metrics from
the profile. If requested, it forces the GC before taking each of the heap
profiles, which improves the profile accuracy (see docs in
https://golang.org/src/runtime/mprof.go on why).
deltaMutexProfile writes mutex profile changes over a time period specified
with 'duration' to 'prof'.
goHeapProfile collects a heap profile. It returns an error if the metrics
in the collected heap profile do not match the expected metrics.
heapProfile collects an in-use heap profile. The heap profiles returned by
the runtime also include the heap allocation metrics. We zero those out
since all allocations since program start are recorded, so these make the
profile large and there is a separate alloc profile type which shows
allocations from a set duration.
initializeAgent initializes the profiling agent. It returns an error if
profile collection should not be started because collection is disabled
for all profile types.
withXGoogHeader sets the name and version of the application in
the `x-goog-api-client` header passed on each request. Intended for
use by Google-written clients.
Package-Level Variables (total 14, none are exported)
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.