diff --git a/docs/src/performance.md b/docs/src/performance.md index e52ea9c684de0e2b9d39efe2741dfe0728bc7641..b8f76179e16fcf1f1b886a5c3ef00bcc85aa9ed4 100644 --- a/docs/src/performance.md +++ b/docs/src/performance.md @@ -55,9 +55,32 @@ Open the profiler (tracy-profiler), you should see zed in the list of `Discovere image -To find functions that take a long time follow this image: +Tracy is an incredibly powerful profiler which can do a lot however it's UI is not that friendly. This is not the place for an in depth guide to Tracy, I do however want to highlight one particular workflow that is helpful when figuring out why a piece of code is _sometimes_ slow. -image +Here are the steps: + +1. Click the flamechart button at the top. +2. Click on a function that takes a lot of time. +3. Expand the list of function calls by clicking on main thread. +4. Filter that list to the slower calls then click on one of the slow calls in the list +5. Click zoom to zone to go to that specific function call in the timeline +6. Scroll to zoom in and see more detail about the callers +7. Click on a caller to to get statistics on _it_. + +While normally the blue bars in the Tracy timeline correspond to function calls they can time any part of a codebase. In the example below we have added an extra span "for block in edits" and added metadata to it: the block_height. You can do that like this: + +```rust +let span = ztracing::debug_span!("for block in edits", block_height = block.height()); +let _enter = span.enter(); // span guard, when this is dropped the span ends (and its duration is recorded) +``` + +Click flamechart +Click snapshot +Click main thread +Select the tail calls in the histogram to filter down the list of calls then click on one call +Click zoom to zone +Scroll to zoom in +Click on any of the zones to get statistics # Task/Async profiling