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 collapser for built in Visual Studio profiler #218

Merged
merged 6 commits into from Apr 24, 2022

Conversation

KnapSac
Copy link
Contributor

@KnapSac KnapSac commented Sep 15, 2021

This adds a stack collapser for the built in Visual Studio profiler.

Closes #217

@codecov
Copy link

codecov bot commented Sep 15, 2021

Codecov Report

Merging #218 (58818b6) into master (5ec68ae) will increase coverage by 0.29%.
The diff coverage is 92.85%.

@@            Coverage Diff             @@
##           master     #218      +/-   ##
==========================================
+ Coverage   86.88%   87.17%   +0.29%     
==========================================
  Files          17       18       +1     
  Lines        2401     2526     +125     
==========================================
+ Hits         2086     2202     +116     
- Misses        315      324       +9     
Impacted Files Coverage Δ
src/collapse/mod.rs 52.63% <ø> (ø)
src/collapse/vsprof.rs 92.68% <92.68%> (ø)
src/collapse/guess.rs 70.73% <100.00%> (+1.50%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ec68ae...58818b6. Read the comment docs.

src/collapse/vsprof.rs Outdated Show resolved Hide resolved
@KnapSac
Copy link
Contributor Author

KnapSac commented Sep 18, 2021

@jonhoo I'm not entirely sure what to do about the code coverage test failing, looking at the diff it seems to me as if they're erroneously marking some lines as not covered. Do you have any ideas?

I only tested the output of a C# program, as I don't have any C++ projects to profile. Additionally, I don't know what other languages the built in Visual Studio profiler supports, which there are probably quite a few of. I suspect that the output for all of them is the same, and as such they shouldn't have any issues with this implementation.

In C# the namespace is included in the function name output (so the function name is actually the fully qualified name of the function), this makes some function names incredibly long, especially if the function also has several arguments with long fully qualified names. One idea I had to make the output more readable was to introduce an option to specify the number of namespaces which should be kept and trim any extra namespaces. Another idea could be to add an option to keep the fewest namespaces possible, while still being unique. Both might also not be a bad idea. Is this something you'd like to discuss/incorporate into this PR, or should a discussion about that be moved to a new issue? The latter would have my preference, as this is, although related, not a requirement for a working implementation. What are your thoughts on this?

@KnapSac KnapSac marked this pull request as ready for review September 18, 2021 17:02
@jonhoo
Copy link
Owner

jonhoo commented Sep 19, 2021

I wouldn't worry too much about the code coverage — it tends to be overly sensitive. Usually it's because error paths aren't covered, but I'm okay with that for a first PR :)

I did notice that the output svg in tests/data/collapse-vsprof/results/sample-default.svg doesn't appear to be a valid SVG file though, which doesn't seem right?

I'm also not entirely sure why you chose to not support lines with a depth deeper than 1000? It seems fairly simple to parse the contained numbers? Just find the next ", strip all ,, and then parse as an integer?

For namespaces, I agree with you that such trimming functionality is something we can discuss separately. No need to implement that here, even if it may be a good idea to add later!

I'm a bit short on time, so may take a bit until I have a chance to give this a thorough review, but hopefully the above unblocks you for a little while at least. Thanks for taking the time to implement this!

@KnapSac
Copy link
Contributor Author

KnapSac commented Sep 20, 2021

The svg output indeed does not appear to be correct, when I have some time later this week I'll look into it. As to not supporting lines with a depth over 1000, I don't have any good reason for that. On second thought, whether or not it is actually possible to have a call stack over 1000 deep, we shouldn't introduce an arbitrary restriction on that. I'll also fix that.

For now I'll mark this PR as a draft, when I've resolved these issues I'll mark it as ready. Don't worry about being short on time, as a student I know the feeling ;).

@KnapSac KnapSac marked this pull request as draft September 20, 2021 19:44
@KnapSac KnapSac marked this pull request as ready for review October 1, 2021 22:21
@KnapSac KnapSac requested a review from jonhoo October 1, 2021 22:22
Copy link
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! Left some more comments :)

src/collapse/mod.rs Outdated Show resolved Hide resolved
tests/collapse-vsprof.rs Show resolved Hide resolved
stack: Vec<(String, usize)>,
}

impl Collapse for Folder {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want a slight challenge (definitely not required for the PR to land!), try implementing the CollapsePrivate trait instead:

/// Private trait for internal library authors.
///
/// If you implement this trait, your type will implement the public-facing
/// `Collapse` trait as well. Implementing this trait gives you parallelism
/// for free as long as you adhere to the requirements described in the
/// comments below.
pub trait CollapsePrivate: Send + Sized {

That will give you multi-core file processing, which can speed up collapsing quite a lot.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This point still stands :)

src/collapse/vsprof.rs Show resolved Hide resolved
src/collapse/vsprof.rs Outdated Show resolved Hide resolved
src/collapse/vsprof.rs Outdated Show resolved Hide resolved
src/collapse/vsprof.rs Outdated Show resolved Hide resolved
src/collapse/vsprof.rs Outdated Show resolved Hide resolved
src/collapse/vsprof.rs Outdated Show resolved Hide resolved
src/collapse/vsprof.rs Outdated Show resolved Hide resolved
@KnapSac
Copy link
Contributor Author

KnapSac commented Oct 13, 2021

@jonhoo it seems I made a bit of a mess while preparing #220, and now Github won't let me reopen this PR :(. Do you have any ideas on how to reopen this PR, or do I have to make a new one?

It seems Github is a bit confused, because it says that there are no new commits on my master branch, despite the fact that I added one this morning...

@jonhoo
Copy link
Owner

jonhoo commented Oct 18, 2021

Hmm, that's weird. It seems like it thinks there are no new commits on your master branch, which is what this PR was opened for. So either you'd need to push your commits to your master branch again (and then we should be able to reopen), or just open a new PR from a different branch :)

@KnapSac KnapSac reopened this Oct 23, 2021
@KnapSac
Copy link
Contributor Author

KnapSac commented Oct 23, 2021

@jonhoo I've addressed some of the review comments, I hope to get to the last few some time next week.

@jonhoo
Copy link
Owner

jonhoo commented Jan 11, 2022

Given that we've now bumped the MSRV (in #227), you can use split_once again!

@KnapSac
Copy link
Contributor Author

KnapSac commented Mar 17, 2022

Wow, this has taken me a lot longer to get back to than I would have liked, my apologies.

I believe I have addressed all the review comments you left during your first review, and all my tests pass. The produced flamegraphs also look correct to me visually (I just created a simple program with only a few functions to make it easier to check correctness visually).

Since this branch has fallen behind master quite a bit, it's probably wise to update it. I feel like the PR would benefit from rebasing onto master and then squashing most of the commits, but I just wanted to know whether you're ok with that, or whether you'd rather I merge with master. Especially the commits regarding the MSRV change create a bit of unnecessary noise, which I'd like to get rid of.

Updating will also fix the build I believe.

@KnapSac KnapSac requested a review from jonhoo March 17, 2022 20:35
@jonhoo
Copy link
Owner

jonhoo commented Mar 19, 2022

All good, thanks for coming back to it! Yes, please do squash and rebase onto master and I'll do another review 👍

@KnapSac KnapSac force-pushed the master branch 3 times, most recently from be479d4 to 21c7913 Compare March 19, 2022 15:00
Copy link
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phew, finally found some time to review! Thanks again for coming back to this. I've left some more notes inline, though I think they're all fairly minor 👍

use std::path::PathBuf;

use clap::Parser;
use env_logger::Env;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: we should really move over to tracing.

src/collapse/mod.rs Outdated Show resolved Hide resolved
src/collapse/vsprof.rs Show resolved Hide resolved
stack: Vec<(String, usize)>,
}

impl Collapse for Folder {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This point still stands :)

src/collapse/vsprof.rs Outdated Show resolved Hide resolved
src/collapse/vsprof.rs Show resolved Hide resolved
src/collapse/vsprof.rs Outdated Show resolved Hide resolved
src/collapse/vsprof.rs Outdated Show resolved Hide resolved
src/collapse/vsprof.rs Outdated Show resolved Hide resolved
src/collapse/vsprof.rs Show resolved Hide resolved
@KnapSac KnapSac requested a review from jonhoo April 2, 2022 21:01
Copy link
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something definitely still tugs at me about the A calls B case, but I don't think it's worth blocking this on. It may just be me failing to read in enough detail. And if someone finds an issue later, we'll find out about it then!

I found two more nits, and with those fixed I think we're finally ready to merge!

src/collapse/vsprof.rs Outdated Show resolved Hide resolved
src/collapse/vsprof.rs Outdated Show resolved Hide resolved
src/collapse/vsprof.rs Outdated Show resolved Hide resolved
Copy link
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thank you for sticking with it!

@jonhoo jonhoo merged commit 190570a into jonhoo:master Apr 24, 2022
@jonhoo
Copy link
Owner

jonhoo commented Apr 24, 2022

Published as 0.11.2 🎉

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.

Add collapser for the Visual Studio built in profiler
2 participants