about summary refs log tree commit diff
path: root/home/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'home/scripts')
-rw-r--r--home/scripts/default.nix5
-rw-r--r--home/scripts/perf-flamegraph.nix22
2 files changed, 27 insertions, 0 deletions
diff --git a/home/scripts/default.nix b/home/scripts/default.nix
new file mode 100644
index 0000000..bc19e44
--- /dev/null
+++ b/home/scripts/default.nix
@@ -0,0 +1,5 @@
+{ ... }:
+
+{
+  imports = [ ./perf-flamegraph.nix ];
+}
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 ];
+  };
+}
+