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