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.
Following on sdmcclain/FlameGraph#1:
folded
(which exists to process folded profiles), has been enhanced to use the Execution time passed in fromdifffolded.pl
to add some additional context to the profiles:When the time is "REALTIME" it's a regular diff (created without the
-u
option), and so we get a line similar to:my_file.py:38 4 2
Looking at https://github.com/mcclaized/edav_final_project/tree/master/example/data, let's say this file is
baseline_diff.folded
and was created by running:difffolded.pl fibonacci_bad.folded fibonacci_improved.folded
The above output means that line 38 of
my_file.py
was sampled 4 times during the profile offibonacci_bad.py
. The goal of this run ofindex.js -f baseline_diff.folded
is to createbaseline_diff.json
which will be the basis of the "Baseline FlameGraph".So, all we have to do to relate "4" calls of
my_file.py
to it's execution time is sum up the total number of calls at the root level, divide them by the runtime of the program, and then multiple that factor by 4. And that's exactly what this PR does :)We can simply flip the order to generate the data for
improved_diff.json
:difffolded.pl fibonacci_improved.folded fibonacci_bad.folded > improved_diff.folded
which gives us:
my_file.py:38 2 4
and then:
index.js -n -f improved_diff.folded
However! Notice the
-n
(short fornegate
) because we want to reverse the colors: for theimproved_diff.folded
, a smaller first number ("2" in this case) signifies fewer calls in our improved program, and should be marked with blue (meaning 👍 ) instead of red.diff_delta
This one was a little bit more complicated. The third FlameGraph showing the delta should have all of the diffs between the
baseline
andimproved
but since some are positive and some are negative, we can't find the proportion simply by dividing the total number of calls at the root level and dividing by the runtime. We need to iteratively keep track of how much net time is being added/subtracted (calledtimeshare
) for each function call (using thediff
of-1
or+1
to signify this), and divide by this number instead.Take a look at lines 180:183, 17:20, and 186 to see the logic in code.