go torch で FlameGraph を描くための準備 - okashoi/isucon-cheat-sheet GitHub Wiki

https://github.com/uber-archive/go-torch

$ go get github.com/uber/go-torch

/home/isucon/go/bin に PATH を通すように /home/isucon/.bashrc を編集(go-torch を実行できるようにする)。 もとから $GOPATH/bin に PATH が通っていれば不要。

export PATH=$PATH:/home/isucon/go/bin

flamegraph を描くやつのインストール

$ cd /usr/local/bin
$ sudo wget https://raw.githubusercontent.com/brendangregg/FlameGraph/master/flamegraph.pl
$ sudo chmod +x flamegraph.pl

あとは(pprof がアプリケーション側に設定されていれば)以下のコマンドを実行すれば OK。

$ go-torch --url http://localhost:6060/debug/pprof/profile -p > torch.svg

よくこんな Make ターゲットを作ったりする。

TIMESTAMP := $(shell date "+%Y%m%d%H%M%S")
torch:
	go-torch --url http://localhost:6060/debug/pprof/profile -p > /<path-to-document-root>/public/torch-$(TIMESTAMP).svg
	ln -sf /<path-to-document-root>/public/torch-$(TIMESTAMP).svg /<path-to-document-root>/public/torch.svg