aclysma / profiling

Provides a very thin abstraction over instrumented profiling crates like puffin, optick, tracy, and superluminal-perf.
Apache License 2.0
320 stars 39 forks source link

Add manual_scope macro #5

Closed Imberflur closed 3 years ago

Imberflur commented 3 years ago

Attempt at #3

Imberflur commented 3 years ago

I'm currently leaning towards leaving this functionality out of this crate but I thought it would be interesting to see what it could look like.

aclysma commented 3 years ago

I agree with you on leaning towards leaving it out for now. Thanks for sharing the the experiment, maybe something will change in the future that makes it an easier sell. Happy to take another look in the future if you come up with something! :)

Imberflur commented 3 years ago

If we had a canonical name for it (like _profiling_guard) then someone could drop it purposefully (undocumented feature - I'd be more comfortable with it not working with one of the profilers if it's not "fully supported" API :) )

I think macro hygiene means the user needs to specify the name to be able to access it. I might not understand what you are proposing here though.

If we did something like this, I'd want the api to be like let my_scope = manual_scope!(...); and then they would drop(my_scope)

That would work as well and feels like a more natural api. I was mainly inspired by the span! macro wgpu uses internally. I think their reason for including the let in the macro was to help keep the usage of the macro on a single line.

Optick behaving inconsistently with the rest of the APIs might be a deal-breaker for this to be a first-class part of the API

yeah :/ theoretically we could just mimic their macro but that involves unsafe and I didn't feel comfortable pulling that in here

aclysma commented 3 years ago

Closing for now but happy to take another look if you have more ideas :)