1How to use our internal tools to profile and keep Zed fast.
2
3# Flamechart/CPU profiling
4
5See what the CPU spends the most time on. Strongly recommend you use
6[samply](https://github.com/mstange/samply). It opens an interactive profile in
7the browser. See its README on how to install and run.
8
9# Task/Async profiling
10
11Get a profile of the zed foreground executor and background executors. Check if
12anything is blocking the foreground too long or taking too much (clock) time in
13the background.
14
15The profiler always runs in the background. You can save a trace from its UI or
16look at the results live.
17
18## Setup/Building the importer:
19
20- Clone the repo at git@github.com:zed-industries/tracy.git on v0.12.2 branch
21- `cd profiler && mkdir build && cd build`
22- Run cmake to generate build files: `cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..`
23- Build the importer: `ninja`
24- Run the impoter on the trace file: `./tracy-import-miniprofiler /path/to/trace.miniprof /path/to/output.tracy`
25- Open the trace in tracy:
26 - If you're on windows download the v0.12.2 version from the releases on the upstream repo
27 - 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..)
28
29## To Save a Trace:
30
31- Run the action: `zed open performance profiler`
32- Hit the save button. This opens a save dialog or if that fails to open the trace gets saved in your working directory.
33- Convert the profile so it can be imported in tracy using the importer: `./tracy-import-miniprofiler <path to performance_profile.miniprof> output.tracy`
34- Go to <https://tracy.nereid.pl/> hit the 'power button' in the top left and then open saved trace.
35- Now zoom in to see the tasks and how long they took
36
37# Warn if function is slow
38
39```rust
40let _timer = zlog::time!("my_function_name").warn_if_gt(std::time::Duration::from_millis(100));
41```