nagisa / rust_tracy_client

Tracy client libraries for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I had to use internal for dynamic FrameName

YaLTeR opened this issue · comments

Hi, I'm using tracy-client to profile a Wayland compositor. I'm using non-continuous frames for profiling monitor redrawing. However, with multiple monitors plugged in, every monitor should have its own frame set, as they are disjoint and redraw on their own vsync cycles.

Since monitors can be plugged in and out at runtime, I have to generate FrameNames dynamically, based on the name of the connector. I understand it's not really supported by Tracy at the moment, but it works well enough™ if I leak the name string, so that it's available for the remaining program lifetime. Unfortunately, I can't use the frame_name! macro as it only accepts a literal.

let vblank_frame_name = unsafe {
    tracy_client::internal::create_frame_name(format!("vblank on {output_name}\0").leak())
};

(I do this once when a monitor is connected, not every frame.)

Would it make sense to expose something for this in tracy-client?

wolfpld/tracy#608 I brought this up in Tracy, and the Tracy developer says that leaking the string like this is the intended solution here.

Hum, I can see the use case and the motivation, but I’m not sure how to expose this in the API the right way. In particular, I guess we could add an API to FrameName, something like unsafe fn from_raw, but that wouldn't be really be much of an improvement, except that it wouldn’t be internal? Is that good enough? I don’t know.

Maybe some kind of FrameName::new_leak(String) which appends a \0 then leaks the result?