Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option trace-function-calls doesn't seem to do anything with flakes #7179

Open
nrdxp opened this issue Oct 16, 2022 · 2 comments
Open

option trace-function-calls doesn't seem to do anything with flakes #7179

nrdxp opened this issue Oct 16, 2022 · 2 comments
Labels

Comments

@nrdxp
Copy link
Contributor

nrdxp commented Oct 16, 2022

Describe the bug

The nix.conf option trace-function-calls seems to have no affect in 2.11.2 when using nix-command and flakes.

Steps To Reproduce

  • Set trace-function-calls to true in your nix.conf or on the cli
  • build a package with nix build the --no-eval-cache flag to ensure eval isn't skipped
  • Notice no extra output is printed either to stdout or in the nix daemon logs

Expected behavior

The way the option is described in the manual and in the stack-collapse.py, I would expect extra output on stderr.

nix-env --version output
nix-env (Nix) 2.11.2

Additional context

I want to use this option along with the stack-collapse.py for profiling. For now it looks like I can use flake-compat and nix-instantiate to work around this.

update
Unfortunately trying to generate a flamegraph of a NixOS system evalution resulted in an oom situation on my machine with 64Gb of RAM. x-ref: brendangregg/FlameGraph#58.

We may want to explore a more efficient way to generate these graphs in the future, as this isn't really a practical situation atm.

@nrdxp nrdxp added the bug label Oct 16, 2022
@nrdxp nrdxp changed the title option trace-function-calls doesn't seem to do anything option trace-function-calls doesn't seem to do anything with flakes Oct 16, 2022
@quentinmit
Copy link

I'm not able to reproduce this bug. --trace-function-calls produces output for me when stderr is directed to a pipe. I was able to get a working flamegraph for a NixOS build using this shell line:

nix eval --trace-function-calls --raw .#nixosConfigurations.hostname.config.system.build.toplevel 3>&2 2>&1 1>&3 | (./stack-collapse.py | perl -nle '@_ = split " "; $total{$_[0]} += $_[1]; END { foreach my $x (keys %total) { print "$x $total{$x}"; }; }' | nix shell nixpkgs#flamegraph --command sh -c "flamegraph.pl > flamegraph.svg" )

The main thing I had to do is use the perl one-liner to preaggregate duplicate stacks; for some reason, my one-liner is able to do that much more efficiently than flamegraph.pl is. It took about 9 GB of RAM for flamegraph.pl to generate the SVG for a relatively small nixos configuration.

That said... I found it very hard to get anything meaningful out of the flamegraph, because most NixOS modules don't actually contain any function definitions (or maybe the top-level flake is getting accounted as "«none»" in the trace?), so all I see taking most of the time are a bunch of functions in <nixpkgs>/lib/modules.nix and the utilities they call in lib/attrsets.nix, lib/lists.nix, etc. It would be really nice if there were some way to trace individual thunks instead of just function calls, though that would probably make the trace orders of magnitude larger again.

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-flamegraph-or-profiling-tool/33333/6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants