Skip to content

Commit 80a1d17

Browse files
committed
Add perfmon initialization
1 parent 64fe10d commit 80a1d17

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ atomic-traits = "0.2.0"
3333
atomic = "0.4.6"
3434
spin = "0.5.2"
3535
env_logger = "0.8.2"
36+
[target.'cfg(target_os = "linux")'.dependencies]
37+
pfm-sys = "0.0.4"
3638

3739
[dev-dependencies]
3840
crossbeam = "0.7.3"

src/util/statistics/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ pub use self::counter::Timer;
33

44
pub mod counter;
55
pub mod stats;
6+
#[cfg(target_os = "linux")]
7+
pub mod perf;

src/util/statistics/perf.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use pfm_sys::{pfm_initialize, pfm_strerror, PFM_SUCCESS};
2+
use std::ffi::CStr;
3+
4+
struct Perf {
5+
initialized: bool,
6+
}
7+
8+
impl Default for Perf {
9+
fn default() -> Perf {
10+
Perf { initialized: false }
11+
}
12+
}
13+
14+
impl Perf {
15+
fn initialize(&mut self) -> Result<(), String> {
16+
let result = unsafe { pfm_initialize() };
17+
if result == PFM_SUCCESS {
18+
self.initialized = true;
19+
Ok(())
20+
} else {
21+
let err_c_char = unsafe { pfm_strerror(result) };
22+
let cstr = unsafe { CStr::from_ptr(err_c_char) };
23+
Err(String::from(cstr.to_str().unwrap()))
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)