@@ -303,7 +303,7 @@ const BUG_REPORT_MSG: &str =
303303 "please report this to https://github.com/rust-lang/measureme/issues/new" ;
304304
305305/// Linux x86_64 implementation based on `perf_event_open` and `rdpmc`.
306- #[ cfg( all( target_arch = "x86_64" , target_os = "linux" ) ) ]
306+ #[ cfg( all( target_arch = "x86_64" , target_os = "linux" , not ( target_env = "ohos" ) ) ) ]
307307mod hw {
308308 use memmap2:: { Mmap , MmapOptions } ;
309309 use perf_event_open_sys:: { bindings:: * , perf_event_open} ;
@@ -349,10 +349,12 @@ mod hw {
349349 type_ : perf_type_id ,
350350 hw_id : u32 ,
351351 ) -> Result < Self , Box < dyn Error + Send + Sync > > {
352- let mut attrs = perf_event_attr:: default ( ) ;
353- attrs. size = mem:: size_of :: < perf_event_attr > ( ) . try_into ( ) . unwrap ( ) ;
354- attrs. type_ = type_;
355- attrs. config = hw_id. into ( ) ;
352+ let mut attrs = perf_event_attr {
353+ size : mem:: size_of :: < perf_event_attr > ( ) . try_into ( ) . unwrap ( ) ,
354+ type_,
355+ config : hw_id. into ( ) ,
356+ ..perf_event_attr:: default ( )
357+ } ;
356358
357359 // Only record same-thread, any CPUs, and only userspace (no kernel/hypervisor).
358360 // NOTE(eddyb) `pid = 0`, despite talking about "process id", means
@@ -933,7 +935,7 @@ mod hw {
933935 }
934936}
935937
936- #[ cfg( not( all( target_arch = "x86_64" , target_os = "linux" ) ) ) ]
938+ #[ cfg( not( all( target_arch = "x86_64" , target_os = "linux" , not ( target_env = "ohos" ) ) ) ) ]
937939mod hw {
938940 use std:: error:: Error ;
939941
@@ -992,6 +994,10 @@ mod hw {
992994 add_error ( "only supported OS is Linux" ) ;
993995 }
994996
997+ if cfg ! ( target_env = "ohos" ) {
998+ add_error ( "unsupported OHOS environment" ) ;
999+ }
1000+
9951001 Err ( msg. into ( ) )
9961002 }
9971003 }
0 commit comments