about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2020-07-15T13·54-0400
committerglittershark <grfn@gws.fyi>2020-07-15T20·21+0000
commit04ae2933607eaed32c9d99eb3949953a88e63460 (patch)
treece58d6e6feb8dae4f6e0733588f429f298b07de3 /tools
parent3fcebfdaa1bedea6d40fe90cdf4885c2b5d36da2 (diff)
feat(tools): Add script to flamegraph a command r/1304
Add tools.perf-flamegraph, which collects the base case execution of
perf piped through stackcollapse-perf and flamegraph to flamegraph the
execution of an external command via perf.

Change-Id: I671fe254dc374b6cd7deca2d3bdea266164de025
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1176
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
Diffstat (limited to 'tools')
-rw-r--r--tools/perf-flamegraph.nix12
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/perf-flamegraph.nix b/tools/perf-flamegraph.nix
new file mode 100644
index 000000000000..fe5c9a1d5959
--- /dev/null
+++ b/tools/perf-flamegraph.nix
@@ -0,0 +1,12 @@
+# Script that collects perf timing for the execution of a command and writes a
+# flamegraph to stdout
+{ pkgs, ... }:
+
+pkgs.writeShellScriptBin "perf-flamegraph" ''
+  set -euo pipefail
+
+  ${pkgs.linuxPackages.perf}/bin/perf record -g -a -F max "$@"
+  ${pkgs.linuxPackages.perf}/bin/perf script \
+    | ${pkgs.flamegraph}/bin/stackcollapse-perf.pl \
+    | ${pkgs.flamegraph}/bin/flamegraph.pl
+''