Render flamegraph diff#1
Open
sdmcclain wants to merge 2 commits into
Open
Conversation
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.
Following on sdmcclain/FlameGraph#1:
folded(which exists to process folded profiles), has been enhanced to use the Execution time passed in fromdifffolded.plto add some additional context to the profiles:When the time is "REALTIME" it's a regular diff (created without the
-uoption), and so we get a line similar to:my_file.py:38 4 2Looking at https://github.com/mcclaized/edav_final_project/tree/master/example/data, let's say this file is
baseline_diff.foldedand was created by running:difffolded.pl fibonacci_bad.folded fibonacci_improved.foldedThe above output means that line 38 of
my_file.pywas sampled 4 times during the profile offibonacci_bad.py. The goal of this run ofindex.js -f baseline_diff.foldedis to createbaseline_diff.jsonwhich will be the basis of the "Baseline FlameGraph".So, all we have to do to relate "4" calls of
my_file.pyto 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.foldedwhich gives us:
my_file.py:38 2 4and then:
index.js -n -f improved_diff.foldedHowever! 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_deltaThis one was a little bit more complicated. The third FlameGraph showing the delta should have all of the diffs between the
baselineandimprovedbut 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 thediffof-1or+1to 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.