about summary refs log tree commit diff
path: root/home/scripts/perf-flamegraph.nix
blob: f379591f40712bd781328587a2df1bcd89c48a3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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 ];
  };
}