Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
The profiler is shipped within Datadog tracing libraries. If you are already using APM to collect traces for your application, you can skip installing the library and go directly to enabling the profiler.
err:=profiler.Start(profiler.WithService("<SERVICE_NAME>"),profiler.WithEnv("<ENVIRONMENT>"),profiler.WithVersion("<APPLICATION_VERSION>"),profiler.WithTags("<KEY1>:<VALUE1>","<KEY2>:<VALUE2>"),profiler.WithProfileTypes(profiler.CPUProfile,profiler.HeapProfile,// The profiles below are disabled by default to keep overhead
// low, but can be enabled as needed.
// profiler.BlockProfile,
// profiler.MutexProfile,
// profiler.GoroutineProfile,
),)iferr!=nil{log.Fatal(err)}deferprofiler.Stop()
If you automatically instrument your Go application with Orchestrion, it adds the continuous profiler code to your application. To enable the profiler at run time, set the environment variable DD_PROFILING_ENABLED=true.
By default, Go’s CPU profiler only shows detailed information for Go code. If your program calls C code, the time spent running C code is reflected in the profile, but the call stacks only show Go function calls.
To add detailed C function call information to CPU profiles, you may opt to use library such as ianlancetaylor/cgosymbolizer. To use this library:
Download the package:
go get github.com/ianlancetaylor/cgosymbolizer@latest
Add the following import anywhere in your program:
import_"github.com/ianlancetaylor/cgosymbolizer"
Note: This library is considered experimental. It can cause (infrequent) deadlocks in programs that use C++ exceptions, or that use libraries such as tcmalloc, which also collect call stacks.
Starting Go 1.21, the Go compiler supports Profile-Guided Optimization (PGO). PGO enables additional optimizations on code identified as hot by CPU profiles of production workloads. This is compatible with Datadog Go Continuous Profiler and can be used for production builds.
The Getting Started with Profiler guide takes a sample service with a performance problem and shows you how to use Continuous Profiler to understand and fix the problem.