mirror of
https://github.com/vale981/poetry2nix
synced 2025-03-04 16:51:40 -05:00
Add development tools to generate flame graphs for nix-instantiate
This commit is contained in:
parent
6fc16e0dee
commit
8336c5f8c6
2 changed files with 48 additions and 0 deletions
|
@ -6,10 +6,12 @@
|
|||
}:
|
||||
|
||||
let
|
||||
tools = pkgs.callPackage ./tools {};
|
||||
|
||||
in
|
||||
pkgs.mkShell {
|
||||
buildInputs = [
|
||||
tools.flamegraph
|
||||
pkgs.nixpkgs-fmt
|
||||
pkgs.poetry
|
||||
];
|
||||
|
|
46
tools/default.nix
Normal file
46
tools/default.nix
Normal file
|
@ -0,0 +1,46 @@
|
|||
{ pkgs ? import <nixpkgs> {
|
||||
overlays = [
|
||||
(import ../overlay.nix)
|
||||
];
|
||||
}
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (pkgs) lib;
|
||||
|
||||
in
|
||||
{
|
||||
|
||||
flamegraph = let
|
||||
runtimeDeps = lib.makeBinPath [
|
||||
pkgs.flamegraph
|
||||
pkgs.python3
|
||||
pkgs.nix
|
||||
];
|
||||
|
||||
nixSrc = pkgs.runCommandNoCC "${pkgs.nix.name}-sources" {} ''
|
||||
mkdir $out
|
||||
tar -x --strip=1 -f ${pkgs.nix.src} -C $out
|
||||
'';
|
||||
|
||||
srcPath = builtins.toString ../.;
|
||||
|
||||
in
|
||||
pkgs.writeScriptBin "poetry2nix-flamegraph" ''
|
||||
#!${pkgs.runtimeShell}
|
||||
export PATH=${runtimeDeps}:$PATH
|
||||
|
||||
workdir=$(mktemp -d)
|
||||
function cleanup {
|
||||
rm -rf "$workdir"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# Run once to warm up
|
||||
nix-instantiate --expr '(import <nixpkgs> { overlays = [ (import ${srcPath + "/overlay.nix"}) ]; })' -A poetry
|
||||
nix-instantiate --trace-function-calls --expr '(import <nixpkgs> { overlays = [ (import ${srcPath + "/overlay.nix"}) ]; })' -A poetry 2> $workdir/traceFile
|
||||
python3 ${nixSrc}/contrib/stack-collapse.py $workdir/traceFile > $workdir/traceFile.folded
|
||||
flamegraph.pl $workdir/traceFile.folded > poetry2nix-flamegraph.svg
|
||||
'';
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue