Files
greptimedb/docs/how-to/how-to-profile-cpu.md
luofucong 1e37847f48 x
2025-01-02 15:21:29 +08:00

1.2 KiB

Profiling CPU

HTTP API

Sample at 99 Hertz, for 5 seconds, output report in protobuf format.

curl -X POST -s '0:4000/debug/prof/cpu' > /tmp/pprof.out

Then you can use pprof command with the protobuf file.

go tool pprof -top /tmp/pprof.out

Sample at 99 Hertz, for 60 seconds, output report in flamegraph format.

curl -X POST -s '0:4000/debug/prof/cpu?seconds=60&output=flamegraph' > /tmp/pprof.svg

Sample at 49 Hertz, for 10 seconds, output report in text format.

curl -X POST -s '0:4000/debug/prof/cpu?seconds=10&frequency=49&output=text' > /tmp/pprof.txt

Using perf

First find the pid of GreptimeDB:

Using perf record to profile GreptimeDB, at the sampling frequency of 99 hertz, and a duration of 60 seconds:

perf record -p <pid> --call-graph dwarf -F 99 -- sleep 60

The result will be saved to file perf.data.

Then

perf script --no-inline > perf.out

Produce a flame graph out of it:

git clone https://github.com/brendangregg/FlameGraph

FlameGraph/stackcollapse-perf.pl perf.out > perf.folded

FlameGraph/flamegraph.pl perf.folded > perf.svg