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
Track function start and end #2782
Conversation
Isn't this potentially very expensive since it may do a syscall on the hot path? (I think on Linux the current time is obtained from the vDSO, but on other platforms it might require an actual syscall.) |
cf84cf7
to
4910bad
Compare
I updated it to be conditional on debug logs, changed the log.py to accept a parameter, and replaced |
cbaa879
to
58e4606
Compare
With this patch, and this file I called `log.py`: #!/usr/bin/env nix-shell #!nix-shell -i python3 -p python3 --pure import sys from pprint import pprint stack = [] timestack = [] for line in open(sys.argv[1]): components = line.strip().split(" ", 2) if components[0] != "function-trace": continue direction = components[1] components = components[2].rsplit(" ", 2) loc = components[0] _at = components[1] time = int(components[2]) if direction == "entered": stack.append(loc) timestack.append(time) elif direction == "exited": dur = time - timestack.pop() vst = ";".join(stack) print(f"{vst} {dur}") stack.pop() and: nix-instantiate --trace-function-calls -vvvv ../nixpkgs/pkgs/top-level/release.nix -A unstable > log.matthewbauer 2>&1 ./log.py ./log.matthewbauer > log.matthewbauer.folded flamegraph.pl --title matthewbauer-post-pr log.matthewbauer.folded > log.matthewbauer.folded.svg I can make flame graphs like: http://gsc.io/log.matthewbauer.folded.svg --- Includes test cases around function call failures and tryEval. Uses RAII so the finish is always called at the end of the function.
I've updated this PR to use the option like you suggested, and also switched to RAII for the trace. I also added the stack collapse script in to |
I'm testing this PR against some particularly complex Nix expressions which the original implementation did not properly trace. |
Yep. It worked great on those test cases. I think this is good to go! |
The option to use is now |
Track function start and ends for flame graphs
With this patch, and this file I called
log.py
:and:
I can make flame graphs like: http://gsc.io/log.matthewbauer.folded.svg