aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_prof/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_prof/src')
-rw-r--r--crates/ra_prof/src/lib.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs
index 89df7f04b..7163a8424 100644
--- a/crates/ra_prof/src/lib.rs
+++ b/crates/ra_prof/src/lib.rs
@@ -43,6 +43,7 @@ pub struct Scope {
43} 43}
44 44
45impl Scope { 45impl Scope {
46 #[must_use]
46 pub fn enter() -> Scope { 47 pub fn enter() -> Scope {
47 let prev = IN_SCOPE.with(|slot| std::mem::replace(&mut *slot.borrow_mut(), true)); 48 let prev = IN_SCOPE.with(|slot| std::mem::replace(&mut *slot.borrow_mut(), true));
48 Scope { prev } 49 Scope { prev }
@@ -65,7 +66,8 @@ impl Drop for Scope {
65/// 2. Build with `cpu_profiler` feature. 66/// 2. Build with `cpu_profiler` feature.
66/// 3. Tun the code, the *raw* output would be in the `./out.profile` file. 67/// 3. Tun the code, the *raw* output would be in the `./out.profile` file.
67/// 4. Install pprof for visualization (https://github.com/google/pprof). 68/// 4. Install pprof for visualization (https://github.com/google/pprof).
68/// 5. Use something like `pprof -svg target/release/rust-analyzer ./out.profile` to see the results. 69/// 5. Bump sampling frequency to once per ms: `export CPUPROFILE_FREQUENCY=1000`
70/// 6. Use something like `pprof -svg target/release/rust-analyzer ./out.profile` to see the results.
69/// 71///
70/// For example, here's how I run profiling on NixOS: 72/// For example, here's how I run profiling on NixOS:
71/// 73///
@@ -73,11 +75,16 @@ impl Drop for Scope {
73/// $ nix-shell -p gperftools --run \ 75/// $ nix-shell -p gperftools --run \
74/// 'cargo run --release -p rust-analyzer -- parse < ~/projects/rustbench/parser.rs > /dev/null' 76/// 'cargo run --release -p rust-analyzer -- parse < ~/projects/rustbench/parser.rs > /dev/null'
75/// ``` 77/// ```
78///
79/// See this diff for how to profile completions:
80///
81/// https://github.com/rust-analyzer/rust-analyzer/pull/5306
76#[derive(Debug)] 82#[derive(Debug)]
77pub struct CpuProfiler { 83pub struct CpuProfiler {
78 _private: (), 84 _private: (),
79} 85}
80 86
87#[must_use]
81pub fn cpu_profiler() -> CpuProfiler { 88pub fn cpu_profiler() -> CpuProfiler {
82 #[cfg(feature = "cpu_profiler")] 89 #[cfg(feature = "cpu_profiler")]
83 { 90 {