File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ atomic-traits = "0.2.0"
3333atomic = " 0.4.6"
3434spin = " 0.5.2"
3535env_logger = " 0.8.2"
36+ [target .'cfg(target_os = "linux")' .dependencies ]
37+ pfm-sys = " 0.0.4"
3638
3739[dev-dependencies ]
3840crossbeam = " 0.7.3"
Original file line number Diff line number Diff line change @@ -3,3 +3,5 @@ pub use self::counter::Timer;
33
44pub mod counter;
55pub mod stats;
6+ #[ cfg( target_os = "linux" ) ]
7+ pub mod perf;
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments