File tree 3 files changed +30
-0
lines changed
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"
33
33
atomic = " 0.4.6"
34
34
spin = " 0.5.2"
35
35
env_logger = " 0.8.2"
36
+ [target .'cfg(target_os = "linux")' .dependencies ]
37
+ pfm-sys = " 0.0.4"
36
38
37
39
[dev-dependencies ]
38
40
crossbeam = " 0.7.3"
Original file line number Diff line number Diff line change @@ -3,3 +3,5 @@ pub use self::counter::Timer;
3
3
4
4
pub mod counter;
5
5
pub 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