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

Scope colors #19

Open kvark opened 3 years ago

kvark commented 3 years ago

Would it be reasonable to expose the colors in this crate? It would enhance the tracy backend experience quite a bit. For example, in https://github.com/gfx-rs/wgpu-rs/discussions/879 we would mark every crate (gfx/wgpu/wgpu-rs) with a separate color.

https://github.com/davidwed/tracy#marking-zones describes the way to pass down colors in Tracy.

aclysma commented 3 years ago

I like the feature idea and I would use it myself. That said, I do have similar feelings about this as another feature request from before: https://github.com/aclysma/profiling/issues/3#issuecomment-742098113

If we did it, what do you think the API should look like? Two approaches come to mind:

The first approach is repetitive, but the second requires using thread locals which aren't free or async-friendly. Also, practically speaking, if multiple upstream crates hardcode their own colors for things, it might make the coloring less useful. Pushing/popping colors might help with this.

kvark commented 3 years ago

I understand the concern here and fully agree on it, in general. In particular though, the API complexity increase appears to be small, and the backends that don't understand colors can just ignore it. So it seems feasible to introduce.

If we did it, what do you think the API should look like?

We need a mini-investigation on how the backends expose this, unless you already know :) If we are talking about Tracy, then your first suggestion makes sense (just an extra optional parameter to the scoping macros).

aclysma commented 3 years ago

It is probably possible to PR improvements to puffin and optick.

We would still need to decide on what the profiling API would look like:

I don't plan to work on this myself at this time, but leaving it here for anyone who wants to pick it up. Happy to review PRs.

kvark commented 3 years ago

Thank you for the investigation!

I don't see how (2) push/pop approach is going to work. I want to have different layers of the stack using different colors, so it would force me to do a push -> marker -> pop at each stage, which is a waste. I.e. I will not be able to keep the pushed color for more than 1 scope anyway.

The approach with categories (3) sounds very interesting. I like the idea, but I imagine that it may not work out. Both (1) and (3) would work for us.