aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_prof/src/google_cpu_profiler.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-08-12 15:32:36 +0100
committerAleksey Kladov <[email protected]>2020-08-12 15:35:29 +0100
commit208b7bd7ba687fb570feb1b89219f14c63712ce8 (patch)
treec39749d1b71b73b4017c2d0d848ebdc85e570c39 /crates/ra_prof/src/google_cpu_profiler.rs
parent98baa9b569b49162392ed4149dd435854fe941b8 (diff)
Rename ra_prof -> profile
Diffstat (limited to 'crates/ra_prof/src/google_cpu_profiler.rs')
-rw-r--r--crates/ra_prof/src/google_cpu_profiler.rs39
1 files changed, 0 insertions, 39 deletions
diff --git a/crates/ra_prof/src/google_cpu_profiler.rs b/crates/ra_prof/src/google_cpu_profiler.rs
deleted file mode 100644
index db865c65b..000000000
--- a/crates/ra_prof/src/google_cpu_profiler.rs
+++ /dev/null
@@ -1,39 +0,0 @@
1//! https://github.com/gperftools/gperftools
2
3use std::{
4 ffi::CString,
5 os::raw::c_char,
6 path::Path,
7 sync::atomic::{AtomicUsize, Ordering},
8};
9
10#[link(name = "profiler")]
11#[allow(non_snake_case)]
12extern "C" {
13 fn ProfilerStart(fname: *const c_char) -> i32;
14 fn ProfilerStop();
15}
16
17static PROFILER_STATE: AtomicUsize = AtomicUsize::new(OFF);
18const OFF: usize = 0;
19const ON: usize = 1;
20const PENDING: usize = 2;
21
22pub fn start(path: &Path) {
23 if PROFILER_STATE.compare_and_swap(OFF, PENDING, Ordering::SeqCst) != OFF {
24 panic!("profiler already started");
25 }
26 let path = CString::new(path.display().to_string()).unwrap();
27 if unsafe { ProfilerStart(path.as_ptr()) } == 0 {
28 panic!("profiler failed to start")
29 }
30 assert!(PROFILER_STATE.compare_and_swap(PENDING, ON, Ordering::SeqCst) == PENDING);
31}
32
33pub fn stop() {
34 if PROFILER_STATE.compare_and_swap(ON, PENDING, Ordering::SeqCst) != ON {
35 panic!("profiler is not started")
36 }
37 unsafe { ProfilerStop() };
38 assert!(PROFILER_STATE.compare_and_swap(PENDING, OFF, Ordering::SeqCst) == PENDING);
39}