-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add support for profiling (#3704)
- Loading branch information
1 parent
9a960f2
commit e9786a3
Showing
6 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package telemetry | ||
|
||
import ( | ||
"os" | ||
"runtime" | ||
|
||
pyroscope "github.com/grafana/pyroscope-go" | ||
) | ||
|
||
const ( | ||
MutexProfileFractionRate = 5 // it samples 1/5 of data | ||
BlockProfileFractionRate = 5 | ||
) | ||
|
||
func StartProfiler(applicationName, telemetryServer string, samplingPercentage int) { | ||
samplingRate := 100 / samplingPercentage | ||
|
||
runtime.SetMutexProfileFraction(samplingRate) | ||
runtime.SetBlockProfileRate(samplingRate) | ||
|
||
pyroscope.Start(pyroscope.Config{ | ||
ApplicationName: applicationName, | ||
|
||
// replace this with the address of pyroscope server | ||
ServerAddress: telemetryServer, | ||
|
||
// you can disable logging by setting this to nil | ||
Logger: pyroscope.StandardLogger, | ||
|
||
// you can provide static tags via a map: | ||
Tags: map[string]string{ | ||
"hostname": os.Getenv("HOSTNAME"), | ||
}, | ||
|
||
ProfileTypes: []pyroscope.ProfileType{ | ||
// these profile types are enabled by default: | ||
pyroscope.ProfileCPU, | ||
pyroscope.ProfileAllocObjects, | ||
pyroscope.ProfileAllocSpace, | ||
pyroscope.ProfileInuseObjects, | ||
pyroscope.ProfileInuseSpace, | ||
|
||
// these profile types are optional: | ||
pyroscope.ProfileGoroutines, | ||
pyroscope.ProfileMutexCount, | ||
pyroscope.ProfileMutexDuration, | ||
pyroscope.ProfileBlockCount, | ||
pyroscope.ProfileBlockDuration, | ||
}, | ||
}) | ||
} |