-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ pub use self::counter::Timer; | |
|
||
pub mod counter; | ||
pub mod stats; | ||
#[cfg(target_os = "linux")] | ||
pub mod perf; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use pfm_sys::{pfm_initialize, pfm_strerror, PFM_SUCCESS}; | ||
use std::ffi::CStr; | ||
|
||
struct Perf { | ||
initialized: bool, | ||
} | ||
|
||
impl Default for Perf { | ||
fn default() -> Perf { | ||
Perf { initialized: false } | ||
} | ||
} | ||
|
||
impl Perf { | ||
fn initialize(&mut self) -> Result<(), String> { | ||
let result = unsafe { pfm_initialize() }; | ||
if result == PFM_SUCCESS { | ||
self.initialized = true; | ||
Ok(()) | ||
} else { | ||
let err_c_char = unsafe { pfm_strerror(result) }; | ||
let cstr = unsafe { CStr::from_ptr(err_c_char) }; | ||
Err(String::from(cstr.to_str().unwrap())) | ||
} | ||
} | ||
} |