adds tracing for instrumenting non-async functions (#44147)

Tracing code is not included in normal release builds
Documents how to use them in our performance docs
Only the maps and cursors are instrumented atm

# Compile times:
current main: fresh release build (cargo clean then build --release)
377.34 secs
current main: fresh debug build (cargo clean then build )
89.31 secs

tracing tracy: fresh release build (cargo clean then build --release)
374.84 secs
tracing tracy: fresh debug build (cargo clean then build )
88.95 secs

tracing tracy: fresh release build with timings (cargo clean then build
--release --features tracing)
375.77 secs
tracing tracy: fresh debug build with timings (cargo clean then build
--features tracing)
90.03 secs


Release Notes:

- N/A

---------

Co-authored-by: localcc <work@localcc.cc>
This commit is contained in:
David Kleingeld
2025-12-05 17:23:06 +00:00
committed by GitHub
co-authored by localcc
parent 07fe8e9bb1
commit b558be7ec6
38 changed files with 898 additions and 451 deletions
+49 -3
View File
@@ -1,6 +1,6 @@
How to use our internal tools to profile and keep Zed fast.
# Flamechart/CPU profiling
# Rough quick CPU profiling (Flamechart)
See what the CPU spends the most time on. Strongly recommend you use
[samply](https://github.com/mstange/samply). It opens an interactive profile in
@@ -12,6 +12,46 @@ The profile.json does not contain any symbols. Firefox profiler can add the loca
<img width="851" height="613" alt="image" src="https://github.com/user-attachments/assets/cbef2b51-0442-4ee9-bc5c-95f6ccf9be2c" />
# In depth CPU profiling (Tracing)
See how long each annotated function call took and its arguments (if
configured).
Annotate any function you need appear in the profile with instrument. For more
details see
[tracing-instrument](https://docs.rs/tracing/latest/tracing/attr.instrument.html):
```rust
#[instrument(skip_all)]
fn should_appear_in_profile(kitty: Cat) {
sleep(QUITE_LONG)
}
```
Then either compile Zed with `ZTRACING=1 cargo r --release`. The release build is optional but highly recommended as like every program Zeds performance characteristics change dramatically with optimizations. You do not want to chase slowdowns that do not exist in release.
## One time Setup/Building the profiler:
Download the profiler:
[linux x86_64](https://zed-tracy-import-miniprofiler.nyc3.digitaloceanspaces.com/tracy-profiler-linux-x86_64)
[macos aarch64](https://zed-tracy-import-miniprofiler.nyc3.digitaloceanspaces.com/tracy-profiler-0.13.0-macos-aarch64)
### Alternative: Building it yourself
- Clone the repo at git@github.com:wolfpld/tracy.git
- `cd profiler && mkdir build && cd build`
- Run cmake to generate build files: `cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..`
- Build the profiler: `ninja`
- [Optional] move the profiler somewhere nice like ~/.local/bin on linux
## Usage
Open the profiler (tracy-profiler), you should see zed in the list of `Discovered clients` click it.
<img width="392" height="287" alt="image" src="https://github.com/user-attachments/assets/b6f06fc3-6b25-41c7-ade9-558cc93d6033" />
To find functions that take a long time follow this image:
<img width="888" height="1159" alt="image" src="https://github.com/user-attachments/assets/77087617-f53a-4331-863d-e59f8a5b6f0b" />
# Task/Async profiling
Get a profile of the zed foreground executor and background executors. Check if
@@ -23,11 +63,17 @@ look at the results live.
## Setup/Building the importer:
Download the importer
[linux x86_64](https://zed-tracy-import-miniprofiler.nyc3.digitaloceanspaces.com/tracy-import-miniprofiler-linux-x86_64)
[mac aarch64](https://zed-tracy-import-miniprofiler.nyc3.digitaloceanspaces.com/tracy-import-miniprofiler-macos-aarch64)
### Alternative: Building it yourself
- Clone the repo at git@github.com:zed-industries/tracy.git on v0.12.2 branch
- `cd profiler && mkdir build && cd build`
- `cd import && mkdir build && cd build`
- Run cmake to generate build files: `cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..`
- Build the importer: `ninja`
- Run the impoter on the trace file: `./tracy-import-miniprofiler /path/to/trace.miniprof /path/to/output.tracy`
- Run the importer on the trace file: `./tracy-import-miniprofiler /path/to/trace.miniprof /path/to/output.tracy`
- Open the trace in tracy:
- If you're on windows download the v0.12.2 version from the releases on the upstream repo
- If you're on other platforms open it on the website: https://tracy.nereid.pl/ (the version might mismatch so your luck might vary, we need to host our own ideally..)