aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-06-26 09:13:09 +0100
committerbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-06-26 09:13:09 +0100
commitfc0f4ed6353174eb80229571e3e54993b1605e41 (patch)
tree53bfceb17b0d730490e8f489c0c0611433de46e5 /crates
parent0129790a8f84a0858abcb1448e1052caa01fc41c (diff)
parentd621533f15871ce233e3a1dcc0fb10a631090678 (diff)
Merge #1442
1442: add cpuprofile to ra_prof r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_batch/Cargo.toml4
-rw-r--r--crates/ra_prof/Cargo.toml1
-rw-r--r--crates/ra_prof/src/lib.rs33
3 files changed, 38 insertions, 0 deletions
diff --git a/crates/ra_batch/Cargo.toml b/crates/ra_batch/Cargo.toml
index 7d8837fc3..f521937c5 100644
--- a/crates/ra_batch/Cargo.toml
+++ b/crates/ra_batch/Cargo.toml
@@ -15,5 +15,9 @@ ra_ide_api = { path = "../ra_ide_api" }
15ra_hir = { path = "../ra_hir" } 15ra_hir = { path = "../ra_hir" }
16ra_project_model = { path = "../ra_project_model" } 16ra_project_model = { path = "../ra_project_model" }
17 17
18[dependencies.ra_prof]
19path = "../ra_prof"
20# features = [ "cpuprofiler" ]
21
18[dev-dependencies] 22[dev-dependencies]
19test_utils = { path = "../test_utils" } 23test_utils = { path = "../test_utils" }
diff --git a/crates/ra_prof/Cargo.toml b/crates/ra_prof/Cargo.toml
index d55af18f5..787e18385 100644
--- a/crates/ra_prof/Cargo.toml
+++ b/crates/ra_prof/Cargo.toml
@@ -9,3 +9,4 @@ publish = false
9once_cell = "0.2.0" 9once_cell = "0.2.0"
10itertools = "0.8.0" 10itertools = "0.8.0"
11backtrace = "0.3.28" 11backtrace = "0.3.28"
12cpuprofiler = { version = "0.0.3", optional = true }
diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs
index de67b4031..1e8d780ab 100644
--- a/crates/ra_prof/src/lib.rs
+++ b/crates/ra_prof/src/lib.rs
@@ -255,6 +255,39 @@ impl Drop for Scope {
255 } 255 }
256} 256}
257 257
258/// A wrapper around https://github.com/AtheMathmo/cpuprofiler
259///
260/// It can be used to capture sampling profiles of sections of code.
261/// It is not exactly out-of-the-box, as it relies on gperftools.
262/// See the docs for the crate for more!
263#[derive(Debug)]
264pub struct CpuProfiler {
265 _private: (),
266}
267
268pub fn cpu_profiler() -> CpuProfiler {
269 #[cfg(feature = "cpuprofiler")]
270 {
271 cpuprofiler::PROFILER.lock().unwrap().start("./out.profile").unwrap();
272 }
273
274 #[cfg(not(feature = "cpuprofiler"))]
275 {
276 eprintln!("cpuprofiler feature is disabled")
277 }
278
279 CpuProfiler { _private: () }
280}
281
282impl Drop for CpuProfiler {
283 fn drop(&mut self) {
284 #[cfg(feature = "cpuprofiler")]
285 {
286 cpuprofiler::PROFILER.lock().unwrap().stop().unwrap();
287 }
288 }
289}
290
258#[cfg(test)] 291#[cfg(test)]
259mod tests { 292mod tests {
260 use super::*; 293 use super::*;