官方开发文档: https://pyroscope.io/docs/developer-guide/
但实际上仅按照其官方文档能够编译出完整功能的 pyroscope 还是有些问题的,这个时候参照其 Makefile
就显得非常重要: https://github.com/pyroscope-io/pyroscope/blob/main/Makefile
No package 'pixman-1' found
sudo apt install libpixman-1-dev libcairo2-dev libpango1.0-dev libjpeg8-dev libgif-dev
No spy xxx found
这是由于没有前置编译,导致一些功能没有编译进来,下面是从 https://github.com/pyroscope-io/pyroscope/blob/main/Makefile 里面知道的:
ENABLED_SPIES_RELEASE=ebpfspy make build-release
make build-libbpf
make build-bcc
make build-profile-bpf
sudo apt-get install libelf-dev cmake
llvm https://mirrors.tuna.tsinghua.edu.cn/help/llvm-apt/
sudo ln -s /usr/bin/clang-15 /usr/bin/clang
sudo ln -s /usr/bin/clang++-15 /usr/bin/clang++
EXTRA_GO_TAGS=,embedassets,ebpfspy make build
make[1]: Entering directory '/home/user/projects_go/src/pyroscope'
CGO_CFLAGS=" -I/home/user/projects_go/src/pyroscope/third_party/libbpf/lib/include -I/home/user/projects_go/src/pyroscope/third_party/bcc/lib/include" \
CGO_LDFLAGS=" -L/home/user/projects_go/src/pyroscope/third_party/libbpf/lib/lib64 -lbpf -L/home/user/projects_go/src/pyroscope/third_party/bcc/lib/lib -lbcc-syms -lstdc++ -lelf -lz" \
go build -trimpath -tags "none,embedassets,ebpfspy" -ldflags " -X github.com/pyroscope-io/pyroscope/pkg/build.Time=2023-01-01T06:18:30Z -X github.com/pyroscope-io/pyroscope/pkg/build.Version=v0.36.0 -X github.com/pyroscope-io/pyroscope/pkg/build.GitSHA=0ce78390 -X github.com/pyroscope-io/pyroscope/pkg/build.GitDirtyStr=0 -X github.com/pyroscope-io/pyroscope/pkg/build.RbspyGitSHA= -X github.com/pyroscope-io/pyroscope/pkg/build.PyspyGitSHA= -X github.com/pyroscope-io/pyroscope/pkg/build.PhpspyGitSHA=be3abd72e8e2dd5dd4e61008fcd702f90c6eb238" -o ./bin/pyroscope ./cmd/pyroscope
make[1]: Leaving directory '/home/user/projects_go/src/pyroscope'
export LD_LIBRARY_PATH="/home/user/projects_go/src/pyroscope/third_party/bcc/src/build"
export LD_LIBRARY_PATH="/home/user/projects_go/src/pyroscope/third_party/libbpf/lib/lib64":$LD_LIBRARY_PATH
# 设置环境亦是
export PYROSCOPE_APPLICATION_NAME='my.ebpf.program{host=server-node-1,region=us-west-1,tag2=val2}'
export PYROSCOPE_SERVER_ADDRESS=http://127.0.0.1:4040/
export PYROSCOPE_SERVER_ADDRESS=http://192.168.253.1:4040/
export PYROSCOPE_SPY_NAME=ebpfspy
# 测试
ab -n 10000 -c 100 http://127.0.0.1/
# 运行(库)
export LD_LIBRARY_PATH="/home/user/projects_go/src/pyroscope/third_party/bcc/src/build"
export LD_LIBRARY_PATH="/home/user/projects_go/src/pyroscope/third_party/libbpf/lib/lib64":$LD_LIBRARY_PATH
$ cat .vscode/launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
// "program": "${fileDirname}",
"program": "${workspaceRoot}/cmd/pyroscope",
"asRoot": true,
"console": "integratedTerminal",
"env": {
"CGO_CFLAGS": " -I/home/user/projects_go/src/pyroscope/third_party/libbpf/lib/include -I/home/user/projects_go/src/pyroscope/third_party/bcc/lib/include -O0 -g",
"CGO_LDFLAGS": " -L/home/user/projects_go/src/pyroscope/third_party/libbpf/lib/lib64 -lbpf -L/home/user/projects_go/src/pyroscope/third_party/bcc/lib/lib -lbcc-syms -lstdc++ -lelf -lz -O0 -g",
"PYROSCOPE_APPLICATION_NAME": "my.ebpf.program",
"PYROSCOPE_SERVER_ADDRESS":"http://address-of-pyroscope-server:4040/",
"PYROSCOPE_SPY_NAME": "ebpfspy",
"LD_LIBRARY_PATH":"/home/user/projects_go/src/pyroscope/third_party/libbpf/lib/lib64:/home/user/projects_go/src/pyroscope/third_party/bcc/src/build",
},
"buildFlags": "-tags='none,embedassets,ebpfspy' -ldflags=' -X github.com/pyroscope-io/pyroscope/pkg/build.Time=2023-01-01T06:18:30Z -X github.com/pyroscope-io/pyroscope/pkg/build.Version=v0.36.0 -X github.com/pyroscope-io/pyroscope/pkg/build.GitSHA=0ce78390 -X github.com/pyroscope-io/pyroscope/pkg/build.GitDirtyStr=0 -X github.com/pyroscope-io/pyroscope/pkg/build.RbspyGitSHA= -X github.com/pyroscope-io/pyroscope/pkg/build.PyspyGitSHA= -X github.com/pyroscope-io/pyroscope/pkg/build.PhpspyGitSHA=be3abd72e8e2dd5dd4e61008fcd702f90c6eb238'",
// "args":["connect", "--pid", "799"]
"args":["server"]
}
]
}
ERRO[2023-01-01T19:44:20.267667] agent/upstream/remote/remote.go:176 upload profile: do http request: Post "http://127.0.0.1:4040/ingest?aggregationType=sum&from=1672573440&name=my.ebpf.program.cpu%7B%7D&sampleRate=100&spyName=ebpfspy&units=samples&until=1672573450": context deadline exceeded (Client.Timeout exceeded while awaiting headers)