# Profiling What is flame graph http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html ## Profiling on local 若是你的 binary 有開啟 pprof, 並指定 6900 port ```go import ( _ "net/http/pprof" //http profiling ) ``` ```bash go tool pprof http://127.0.0.1:6900/debug/pprof/profile -seconds 30 go tool pprof -http=:8081 /Users/jimmy/pprof/pprof.samples.cpu.001.pb.gz ``` ![](https://i.imgur.com/G9WB52R.png) ## Profiling on gcp Just added that on your main binary, then open profiler on gcp console. ```go // snippets is an example of starting cloud.google.com/go/profiler. package main import ( "cloud.google.com/go/profiler" ) func main() { // Profiler initialization, best done as early as possible. if err := profiler.Start(profiler.Config{ Service: "myservice", ServiceVersion: "1.0.0", // ProjectID must be set if not running on GCP. // ProjectID: "my-project", }); err != nil { // TODO: Handle error. } } ``` ### Reference 1. Profiler https://console.cloud.google.com/profiler 2. Real time profiling on gcp https://medium.com/google-cloud/continuous-profiling-of-go-programs-96d4416af77b ![](https://i.imgur.com/wtihAGq.png) 3. GCP profiling https://cloud.google.com/profiler/docs/profiling-go?hl=zh-TW#gke