Properly shutdown Tracy in on-demand mode
Browse files at this commitb0eb8ad8c80094de34abd88c109aea421461622bParent: e9b215f1 changed file +15 -0
- src/main.rs +15 -0
src/main.rsmodified+15 -0
| @@ -143,6 +143,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { | |||
| 143 | // slow. | 143 | // slow. |
| 144 | tracy_client::Client::start(); | 144 | tracy_client::Client::start(); |
| 145 | 145 | ||
| 146 | + // In on-demand mode, we must shut down Tracy manually to terminate the connection cleanly. | ||
| 147 | + // Do it from a Drop impl here, so that it runs after the Drop code for all of the state created | ||
| 148 | + // below, because some of those Drop impls themselves create Tracy spans. | ||
| 149 | + let _shutdown_tracy = ShutdownTracy; | ||
| 150 | + | ||
| 146 | info!("starting version {}", &version()); | 151 | info!("starting version {}", &version()); |
| 147 | 152 | ||
| 148 | // Load the config. | 153 | // Load the config. |
| @@ -408,3 +413,13 @@ fn set_default_max_buffer_size(display: &Display<State>, size: usize) { | |||
| 408 | libc::dlclose(lib); | 413 | libc::dlclose(lib); |
| 409 | } | 414 | } |
| 410 | } | 415 | } |
| 416 | + | ||
| 417 | +struct ShutdownTracy; | ||
| 418 | +impl Drop for ShutdownTracy { | ||
| 419 | + fn drop(&mut self) { | ||
| 420 | + #[cfg(feature = "profile-with-tracy-ondemand")] | ||
| 421 | + unsafe { | ||
| 422 | + tracy_client::sys::___tracy_shutdown_profiler(); | ||
| 423 | + } | ||
| 424 | + } | ||
| 425 | +} | ||