Add -N/--max-depth-outer to keep the outermost frames - #160
Open
rlerdorf wants to merge 1 commit into
Open
Conversation
-n keeps the innermost frames, which is the wrong end for attributing a sample to a phase of the program. With -n 30 on a 100-deep recursion you get the leaf detail and lose the ability to say whether the sample is under parseFile or analyzeFile -- which, on a long multi-stage job, is usually the question worth answering. -N keeps the outermost frames instead, and the two compose: -n 2 -N 2 keeps both ends and elides the middle. Keeping the outermost frames means knowing the depth before emitting anything, so trace_stack gains a counting pre-pass. It copies only the prev_execute_data pointer rather than each frame, and is skipped entirely unless -N is given, so nothing changes for existing invocations. It is kept inline rather than factored into a helper so that phpspy_trace_tpl.c needs no new #define/#undef pair across its twelve instantiations. The emitted sequence always begins at depth 0: when the innermost frames are themselves elided, the marker takes depth 0. stackcollapse-phpspy.pl flushes its accumulated stack on depth 0, so without that every trace in a file would silently merge into one. The marker's function token is whitespace-free (`<elided:19>`) because both that script and top.c split frame lines on spaces, and `#`-prefixed lines were not an option for the same reason. The stack can change between the two passes, which is inherent to sampling a running process. If it shrank, the walk ends early and the outer frames are simply missing; if it grew, the number of outer frames emitted is capped by count rather than by the boundary computed earlier, so -N stays a bound on output size. Both walks are also bounded by PHPSPY_MAX_WALK, since a torn read of prev_execute_data could otherwise loop forever -- a latent issue in the existing single-pass walk too. -N composes usefully with -b: capping the stack is the cheapest way to keep deep traces inside the per-trace output budget.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
-nkeeps the innermost frames, which is the wrong end for attributing a sample to a phase of the program.With
-n 30on a 100-deep recursion you get the leaf detail and lose the ability to say whether the sample is underparseFileoranalyzeFile— which, profiling a long multi-stage job, was the question I actually needed answered.-Nkeeps the outermost frames instead, and the two compose:-n N-N M-n N -N MImplementation notes
Keeping the outermost frames means knowing the depth before emitting anything, so
trace_stackgains a counting pre-pass. It copies only theprev_execute_datapointer rather than each frame, and is skipped entirely unless-Nis given, so nothing changes for existing invocations.It is deliberately kept inline rather than factored into a helper, so
phpspy_trace_tpl.cneeds no new#define/#undefpair across its twelve instantiations.The emitted sequence always begins at depth 0. When the innermost frames are themselves elided, the marker takes depth 0.
stackcollapse-phpspy.plflushes its accumulated stack on$depth == 0, so without this every trace in a file would silently merge into a single stack — I hit exactly that in a first draft. The marker's function token is whitespace-free (<elided:19>) because that script andtop.cboth split frame lines on spaces; a#-prefixed marker was not an option for the same reason.The stack can change between the two passes. That is inherent to sampling a running process. If it shrank, the walk ends early and the outer frames are simply missing. If it grew, the number of outer frames emitted is capped by count rather than by the boundary computed earlier, so
-Nremains a bound on output size.Both walks are now bounded by
PHPSPY_MAX_WALK. That also covers a latent issue in the existing single-pass walk: a torn read ofprev_execute_dataon a running target can currently loop forever.-Ncomposes usefully with-b— capping the stack is the cheapest way to keep deep traces inside the per-trace output budget.Testing
make testpasses (15/15) under bothmakeandUSE_ZEND=1 make.tests/test_max_depth_outer.shcovers each flag combination, that a stack shallower than the cap is not elided at all, and — as a regression guard for the depth-0 trap above — that astackcollapse-phpspy.plround-trip still accounts for every sample.Independent of #156–#159.