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

Add datastructure and tools for building and printing stack traces / ref trees conveniently #56

Merged
merged 3 commits into from
Mar 20, 2023

Conversation

ogxd
Copy link
Collaborator

@ogxd ogxd commented Mar 18, 2023

Context

Building stacks will be a very common thing to do in profiler, either stacks by occurrence, stacks by thread group, reference tree, ... It's worth making something generic and convenient to use.

Example usage

Let's say we want to print stacktraces:
We make a sequences field in out profiler

pub sequences: HashMap<Vec<FunctionID>, usize>

Vec<FunctionID> is the stack, usize is the number of times this stack was encountered. This is convenient to use and very performant while the profiler runs since there is no search to do, everything is O(1).

When we're done profiling, we build a tree using

let mut tree = TreeNode::build_from_sequences(sequences)

Then we can sort our tree let's say by descending inclusive calls (this is usually what we want) with

tree.sort_by(&|a, b| b.inclusive.cmp(&a.inclusive));

Then it should be a lot easier to print our stacks into HTML or whatever

@ogxd ogxd requested a review from Bluezen March 18, 2023 16:55
@ogxd ogxd self-assigned this Mar 18, 2023
@Bluezen
Copy link
Collaborator

Bluezen commented Mar 19, 2023

After reviewing the TreeNode structure in this pull request and providing some feedback, I must say that overall it was very well done. Great work!

* Attempt at making TreeNode more flexible

* Fix some bugs

* Improve performance by removing need for cloning when computing inclusive value
@ogxd ogxd merged commit 3e16067 into master Mar 20, 2023
@ogxd ogxd deleted the stack-utils branch May 6, 2023 10:30
@ogxd ogxd added this to the Version 1 milestone May 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants