From 91bea68d1611cb2b083f98c4dcd62a86d183eb09 Mon Sep 17 00:00:00 2001 From: sh2 Date: Fri, 20 Sep 2024 08:37:13 +0800 Subject: [PATCH] chore: include heap profile into benchmark report and add notes for profiles (#4284) include heap profile into benchmark report and add notes for profiles Signed-off-by: shawnh2 --- test/benchmark/suite/render.go | 17 +++++++++++++++-- tools/make/kube.mk | 5 +---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/test/benchmark/suite/render.go b/test/benchmark/suite/render.go index 199476f3e99..69992fb69ee 100644 --- a/test/benchmark/suite/render.go +++ b/test/benchmark/suite/render.go @@ -77,7 +77,7 @@ func RenderReport(writer io.Writer, name, description string, titleLevel int, re writeSection(writer, "Metrics", titleLevel+1, "") renderMetricsTable(writer, reports) - writeSection(writer, "Profiles", titleLevel+1, "") + writeSection(writer, "Profiles", titleLevel+1, renderProfilesNote()) renderProfilesTable(writer, "Memory", "heap", titleLevel+2, reports) return nil @@ -149,6 +149,18 @@ func renderMetricsTable(writer io.Writer, reports []*BenchmarkReport) { _ = table.Flush() } +func renderProfilesNote() string { + return fmt.Sprintf(`The profiles at different scales are stored under %s directory in report, with name %s. + +You can visualize them in a web page by running: + +%s + +Currently, the supported profile types are: +- heap +`, "`/profiles`", "`{ProfileType}.{TestCase}.pprof`", "```shell\ngo tool pprof -http=: path/to/your.pprof\n```") +} + func renderProfilesTable(writer io.Writer, target, key string, titleLevel int, reports []*BenchmarkReport) { writeSection(writer, target, titleLevel, "") @@ -156,7 +168,8 @@ func renderProfilesTable(writer io.Writer, target, key string, titleLevel int, r // The image is not be rendered yet, so it is a placeholder for the path. // The image will be rendered after the test has finished. writeSection(writer, report.Name, titleLevel+1, - fmt.Sprintf("![%s-%s](%s.png)", key, report.Name, report.ProfilesPath[key])) + fmt.Sprintf("![%s-%s](%s.png)", key, report.Name, + strings.TrimSuffix(report.ProfilesPath[key], ".pprof"))) } } diff --git a/tools/make/kube.mk b/tools/make/kube.mk index dd5cd74c6d6..2344a3b868d 100644 --- a/tools/make/kube.mk +++ b/tools/make/kube.mk @@ -174,10 +174,7 @@ run-benchmark: install-benchmark-server ## Run benchmark tests go test -v -tags benchmark -timeout $(BENCHMARK_TIMEOUT) ./test/benchmark --rps=$(BENCHMARK_RPS) --connections=$(BENCHMARK_CONNECTIONS) --duration=$(BENCHMARK_DURATION) --report-save-dir=$(BENCHMARK_REPORT_DIR) # render benchmark profiles into image dot -V - @for profile in $(wildcard test/benchmark/$(BENCHMARK_REPORT_DIR)/profiles/*.pprof); do \ - $(call log, "Rendering profile image for: $${profile}"); \ - go tool pprof -png $${profile} > $${profile}.png; \ - done + find test/benchmark/$(BENCHMARK_REPORT_DIR)/profiles -name "*.pprof" -type f -exec sh -c 'go tool pprof -png "$$1" > "$${1%.pprof}.png"' _ {} \; .PHONY: install-benchmark-server install-benchmark-server: ## Install nighthawk server for benchmark test