From 04ae2933607eaed32c9d99eb3949953a88e63460 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Wed, 15 Jul 2020 09:54:18 -0400 Subject: feat(tools): Add script to flamegraph a command 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 Tested-by: BuildkiteCI --- tools/perf-flamegraph.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tools/perf-flamegraph.nix (limited to 'tools') diff --git a/tools/perf-flamegraph.nix b/tools/perf-flamegraph.nix new file mode 100644 index 0000000000..fe5c9a1d59 --- /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 +'' -- cgit 1.4.1