aboutsummaryrefslogtreecommitdiff
path: root/home/scripts/perf-flamegraph.nix
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-05-19 17:39:13 -0700
committerFranck Cuny <franck@fcuny.net>2022-05-19 17:39:13 -0700
commitd14055a019b7266a3ed38ddb19c018275a13f4d1 (patch)
tree3a4a9184b86644b5f406986396621076699ff8db /home/scripts/perf-flamegraph.nix
parentfeat(git): add a template for commit messages (diff)
downloadinfra-d14055a019b7266a3ed38ddb19c018275a13f4d1.tar.gz
feat(home): add a script to create flamegraph from a process
This script (`perf-flamegraph-process') takes a process as an argument, and will run it with `perf' to capture the call graph, and will generate the flamegraph from it. The SVG is saved under `~/workspace/tmp/flamegraph'.
Diffstat (limited to 'home/scripts/perf-flamegraph.nix')
-rw-r--r--home/scripts/perf-flamegraph.nix22
1 files changed, 22 insertions, 0 deletions
diff --git a/home/scripts/perf-flamegraph.nix b/home/scripts/perf-flamegraph.nix
new file mode 100644
index 0000000..f379591
--- /dev/null
+++ b/home/scripts/perf-flamegraph.nix
@@ -0,0 +1,22 @@
+{ pkgs, config, ... }:
+let
+ perf-flamegraph-process =
+ pkgs.writeShellScriptBin "perf-flamegraph-process" ''
+ set -euo pipefail
+
+ OUT_DIR="''${HOME}/workspace/tmp/flamegraph"
+ OUT_SVG="''${OUT_DIR}/$(date +%y%m%d-%H%M%S).svg"
+
+ mkdir -p ''${OUT_DIR}
+
+ ${pkgs.linuxPackages.perf}/bin/perf record -g --call-graph dwarf -F max "$@"
+ ${pkgs.linuxPackages.perf}/bin/perf script \
+ | ${pkgs.flamegraph}/bin/stackcollapse-perf.pl \
+ | ${pkgs.flamegraph}/bin/flamegraph.pl > "''${OUT_SVG}"
+ '';
+in {
+ config = {
+ home.packages = with pkgs; [ flamegraph perf-flamegraph-process ];
+ };
+}
+