sane-profile: init

This commit is contained in:
2025-07-22 00:07:31 +00:00
parent 1411add8ba
commit b1cdf9b63e
3 changed files with 28 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ in
"sane-scripts.dev" = declPackageSet [ "sane-scripts.dev" = declPackageSet [
"sane-scripts.clone" "sane-scripts.clone"
"sane-scripts.dev-cargo-loop" "sane-scripts.dev-cargo-loop"
"sane-scripts.profile"
]; ];
"sane-scripts.cli" = declPackageSet [ "sane-scripts.cli" = declPackageSet [
"sane-scripts.find-dotfiles" "sane-scripts.find-dotfiles"
@@ -76,7 +77,7 @@ in
"sane-scripts.dev-cargo-loop".sandbox = { "sane-scripts.dev-cargo-loop".sandbox = {
net = "clearnet"; net = "clearnet";
whitelistPwd = true; whitelistPwd = true;
extraPaths = [ extraHomePaths = [
# a build script can do a lot... but a well-written one will be confined # a build script can do a lot... but a well-written one will be confined
# to XDG dirs and the local dir, and maybe the internet for fetching dependencies. # to XDG dirs and the local dir, and maybe the internet for fetching dependencies.
".cache" ".cache"
@@ -85,6 +86,14 @@ in
]; ];
}; };
"sane-scripts.profile".sandbox = {
# should maybe be unconfined instead, since it runs a user program?
autodetectCliPaths = "existing";
extraPaths = [
"/tmp"
];
};
"sane-scripts.find-dotfiles".sandbox = { "sane-scripts.find-dotfiles".sandbox = {
method = "bunpen"; method = "bunpen";
extraHomePaths = [ extraHomePaths = [

View File

@@ -122,6 +122,11 @@ let
srcRoot = ./src; srcRoot = ./src;
pkgs = [ "openssh" "sane-scripts.secrets-dump" ]; pkgs = [ "openssh" "sane-scripts.secrets-dump" ];
}; };
profile = static-nix-shell.mkYsh {
pname = "sane-profile";
srcRoot = ./src;
pkgs = [ "flamegraph" "linuxPackages.perf" ];
};
rcp = static-nix-shell.mkBash { rcp = static-nix-shell.mkBash {
pname = "sane-rcp"; pname = "sane-rcp";
srcRoot = ./src; srcRoot = ./src;

View File

@@ -0,0 +1,13 @@
#!/usr/bin/env nix-shell
#!nix-shell -i ysh -p flamegraph -p linuxPackages.perf -p oils-for-unix
# use like `sane-profile some-command --which-takes-a flag`.
# will render a .html file showing the hot-path functions inside the command.
var cmd = ARGV
var tmpdir = "/tmp"
perf record -F 9000 -e cycles:u -g -o "$tmpdir/perf.data" -- @cmd
perf script --input "$tmpdir/perf.data" > "$tmpdir/perf.script"
stackcollapse-perf.pl "$tmpdir/perf.script" | flamegraph.pl --width 2000 > "$tmpdir/flamegraph.html"
echo "flame graph available at $tmpdir/flamegraph.html"