Skip to content

Commit 73bb3db

Browse files
committed
add pprof rule for profiling VictoriaLogs
1 parent 2ba1344 commit 73bb3db

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

Makefile

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,30 @@ release-vlutils-windows-goarch: \
270270
vlagent-windows-$(GOARCH)-prod.exe \
271271
vlogscli-windows-$(GOARCH)-prod.exe
272272

273-
pprof-cpu:
274-
go tool pprof -trim_path=github.com/VictoriaMetrics/VictoriaLogs $(PPROF_FILE)
273+
# Define the list of paths where pprof can find the source code.
274+
# Start with the current working directory.
275+
SOURCE_PATH := $(shell pwd)
276+
277+
# Add path to the Go standard library source code.
278+
SOURCE_PATH := $(SOURCE_PATH):$(shell go env GOROOT)/src
279+
280+
# Add the directory that contains project dependencies.
281+
SOURCE_PATH := $(SOURCE_PATH):$(shell go env GOMODCACHE)
282+
283+
# Special case: file names with uppercase letters in the GOMODCACHE directory are escaped.
284+
# For example, a module named 'github.com/VictoriaMetrics/VictoriaMetrics' will be placed at the following path:
285+
# $GOMODCACHE/github.com/!victoria!metrics/!victoria!metrics
286+
# Since pprof does not perform this escaping when searching for the source code,
287+
# we need to completely remove this prefix and set the SOURCE_PATH to the root of the VictoriaMetrics source code.
288+
# TRIM_PATH must be synced with go.mod
289+
# See: https://pkg.go.dev/golang.org/x/mod/module#hdr-Escaped_Paths
290+
SOURCE_PATH := $(SOURCE_PATH):$(shell pwd)/vendor/github.com/VictoriaMetrics/VictoriaMetrics
291+
TRIM_PATH := github.com/VictoriaMetrics/[email protected]
292+
293+
PPROF_FILE ?= cpu.pprof
294+
295+
pprof:
296+
go tool pprof -trim_path $(TRIM_PATH) -source_path $(SOURCE_PATH) $(PPROF_FILE)
275297

276298
fmt:
277299
gofmt -l -w -s ./lib

0 commit comments

Comments
 (0)