dd-trace-go.v1: gopkg.in/DataDog/dd-trace-go.v1/profiler Index | Examples | Files

package profiler

import "gopkg.in/DataDog/dd-trace-go.v1/profiler"

Package profiler periodically collects and sends profiles to the Datadog API. Use Start to start the profiler. An API key needs to be specified by means of the WithAPIKey option.

This example illustrates how to run (and later stop) the Datadog Profiler.


err := profiler.Start(
if err != nil {
defer profiler.Stop()

// ...



Package Files

doc.go options.go profile.go profiler.go upload.go


const (
    // DefaultMutexFraction specifies the mutex profile fraction to be used with the mutex profiler.
    // For more information or for changing this value, check runtime.SetMutexProfileFraction.
    DefaultMutexFraction = 10

    // DefaultBlockRate specifies the default block profiling rate used by the block profiler.
    // For more information or for changing this value, check runtime.SetBlockProfileRate.
    DefaultBlockRate = 100

    // DefaultPeriod specifies the default period at which profiles will be collected.
    DefaultPeriod = time.Minute

    // DefaultDuration specifies the default length of the CPU profile snapshot.
    DefaultDuration = time.Second * 15

func Start Uses

func Start(opts ...Option) error

Start starts the profiler. It may return an error if an API key is not provided by means of the WithAPIKey option, or if a hostname is not found.

func Stop Uses

func Stop()

Stop stops the profiler.

type Option Uses

type Option func(*config)

An Option is used to configure the profiler's behaviour.

func CPUDuration Uses

func CPUDuration(d time.Duration) Option

CPUDuration specifies the length at which to collect CPU profiles.

func WithAPIKey Uses

func WithAPIKey(key string) Option

WithAPIKey specifies the API key to use when connecting to the Datadog API directly, skipping the agent.

func WithAgentAddr Uses

func WithAgentAddr(hostport string) Option

WithAgentAddr specifies the address to use when reaching the Datadog Agent.

func WithEnv Uses

func WithEnv(env string) Option

WithEnv specifies the environment to which these profiles should be registered.

func WithPeriod Uses

func WithPeriod(d time.Duration) Option

WithPeriod specifies the interval at which to collect profiles.

func WithProfileTypes Uses

func WithProfileTypes(types ...ProfileType) Option

WithProfileTypes specifies the profile types to be collected by the profiler.

func WithService Uses

func WithService(name string) Option

WithService specifies the service name to attach to a profile.

func WithSite Uses

func WithSite(site string) Option

WithSite specifies the datadog site (datadoghq.com, datadoghq.eu, etc.) which profiles will be sent to.

func WithStatsd Uses

func WithStatsd(client StatsdClient) Option

WithStatsd specifies an optional statsd client to use for metrics. By default, no metrics are sent.

func WithTags Uses

func WithTags(tags ...string) Option

WithTags specifies a set of tags to be attached to the profiler. These may help filter the profiling view based on various information.

func WithURL Uses

func WithURL(url string) Option

WithURL specifies the HTTP URL for the Datadog Profiling API.

func WithVersion Uses

func WithVersion(version string) Option

WithVersion specifies the service version tag to attach to profiles

type ProfileType Uses

type ProfileType int

ProfileType represents a type of profile that the profiler is able to run.

const (
    // HeapProfile reports memory allocation samples; used to monitor current
    // and historical memory usage, and to check for memory leaks.
    HeapProfile ProfileType = iota
    // CPUProfile determines where a program spends its time while actively consuming
    // CPU cycles (as opposed to while sleeping or waiting for I/O).
    // BlockProfile shows where goroutines block waiting on synchronization primitives
    // (including timer channels). Block profile is not enabled by default.
    // MutexProfile reports the lock contentions. When you think your CPU is not fully utilized due
    // to a mutex contention, use this profile. Mutex profile is not enabled by default.
    // GoroutineProfile reports stack traces of all current goroutines

func (ProfileType) String Uses

func (t ProfileType) String() string

type StatsdClient Uses

type StatsdClient interface {
    // Count counts how many times an event happened, at the given rate using the given tags.
    Count(event string, times int64, tags []string, rate float64) error
    // Timing creates a distribution of the values registered as the duration of a certain event.
    Timing(event string, duration time.Duration, tags []string, rate float64) error

StatsdClient implementations can count and time certain event occurrences that happen in the profiler.

Package profiler imports 22 packages (graph) and is imported by 1 packages. Updated 2020-08-06. Refresh now. Tools for package owners.