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

Check if profiler is enabled / HeapStats without panic #37

Open
Dav1dde opened this issue Aug 12, 2024 · 0 comments
Open

Check if profiler is enabled / HeapStats without panic #37

Dav1dde opened this issue Aug 12, 2024 · 0 comments

Comments

@Dav1dde
Copy link

Dav1dde commented Aug 12, 2024

I am profiling a bigger application and switching relatively often between profiled/non-profiled and have a working checkout of the code with dhat profiling inserted into many submodules of a bigger workspace. I created a macro to print the current memory stats across a bunch of different functions and lines of code. In the macro I get the heap stats via HeapStats::get(), but this is problematic and fails if I don't have the profiler enabled. Since this macro is for testing copy pasted in a few crates it's quite annoying to toggle it via feature flag (the feature flag would need to be passed down from the binary crate) and it's also annoying to comment out the code everytime I toggle the profiling.

It would be nice if there was a way to check if profiling is enabled, or if HeapStats::get had a variant which returned Option<HeapStats> or Result<HeapStats, SomeError>.

I am not sure what your preferred API surface for this is, if you have any ideas/recommendations I can draft the PR for it.

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

No branches or pull requests

1 participant