@@ -97,14 +97,27 @@ use std::time::{Duration, Instant};
97
97
use measureme:: { EventId , EventIdBuilder , SerializableString , StringId } ;
98
98
use parking_lot:: RwLock ;
99
99
100
- /// MmapSerializatioSink is faster on macOS and Linux
101
- /// but FileSerializationSink is faster on Windows
102
- #[ cfg( all( not( windows) , not( target_arch = "wasm32" ) ) ) ]
103
- type SerializationSink = measureme:: MmapSerializationSink ;
104
- #[ cfg( all( windows, not( target_arch = "wasm32" ) ) ) ]
105
- type SerializationSink = measureme:: FileSerializationSink ;
106
- #[ cfg( target_arch = "wasm32" ) ]
107
- type SerializationSink = measureme:: ByteVecSink ;
100
+ cfg_if ! {
101
+ if #[ cfg( target_arch = "wasm32" ) ] {
102
+ cfg_if! {
103
+ if #[ cfg( target_os = "wasi" ) ] {
104
+ type SerializationSink = measureme:: FileSerializationSink ;
105
+ } else {
106
+ type SerializationSink = measureme:: ByteVecSink ;
107
+ }
108
+ }
109
+ } else {
110
+ cfg_if! {
111
+ if #[ cfg( windows) ] {
112
+ /// FileSerializationSink is faster on Windows
113
+ type SerializationSink = measureme:: FileSerializationSink ;
114
+ } else {
115
+ /// MmapSerializatioSink is faster on macOS and Linux
116
+ type SerializationSink = measureme:: MmapSerializationSink ;
117
+ }
118
+ }
119
+ }
120
+ }
108
121
109
122
type Profiler = measureme:: Profiler < SerializationSink > ;
110
123
@@ -604,36 +617,41 @@ pub fn duration_to_secs_str(dur: std::time::Duration) -> String {
604
617
}
605
618
606
619
// Memory reporting
607
- #[ cfg( all( unix, not( target_arch = "wasm32" ) ) ) ]
608
- fn get_resident ( ) -> Option < usize > {
609
- let field = 1 ;
610
- let contents = fs:: read ( "/proc/self/statm" ) . ok ( ) ?;
611
- let contents = String :: from_utf8 ( contents) . ok ( ) ?;
612
- let s = contents. split_whitespace ( ) . nth ( field) ?;
613
- let npages = s. parse :: < usize > ( ) . ok ( ) ?;
614
- Some ( npages * 4096 )
615
- }
616
-
617
- #[ cfg( all( windows, not( target_arch = "wasm32" ) ) ) ]
618
- fn get_resident ( ) -> Option < usize > {
619
- use std:: mem:: { self , MaybeUninit } ;
620
- use winapi:: shared:: minwindef:: DWORD ;
621
- use winapi:: um:: processthreadsapi:: GetCurrentProcess ;
622
- use winapi:: um:: psapi:: { GetProcessMemoryInfo , PROCESS_MEMORY_COUNTERS } ;
623
-
624
- let mut pmc = MaybeUninit :: < PROCESS_MEMORY_COUNTERS > :: uninit ( ) ;
625
- match unsafe {
626
- GetProcessMemoryInfo ( GetCurrentProcess ( ) , pmc. as_mut_ptr ( ) , mem:: size_of_val ( & pmc) as DWORD )
627
- } {
628
- 0 => None ,
629
- _ => {
630
- let pmc = unsafe { pmc. assume_init ( ) } ;
631
- Some ( pmc. WorkingSetSize as usize )
620
+ cfg_if ! {
621
+ if #[ cfg( target_arch = "wasm32" ) ] {
622
+ fn get_resident( ) -> Option <usize > {
623
+ None
624
+ }
625
+ } else {
626
+ cfg_if! {
627
+ if #[ cfg( windows) ] {
628
+ fn get_resident( ) -> Option <usize > {
629
+ use std:: mem:: { self , MaybeUninit } ;
630
+ use winapi:: shared:: minwindef:: DWORD ;
631
+ use winapi:: um:: processthreadsapi:: GetCurrentProcess ;
632
+ use winapi:: um:: psapi:: { GetProcessMemoryInfo , PROCESS_MEMORY_COUNTERS } ;
633
+
634
+ let mut pmc = MaybeUninit :: <PROCESS_MEMORY_COUNTERS >:: uninit( ) ;
635
+ match unsafe {
636
+ GetProcessMemoryInfo ( GetCurrentProcess ( ) , pmc. as_mut_ptr( ) , mem:: size_of_val( & pmc) as DWORD )
637
+ } {
638
+ 0 => None ,
639
+ _ => {
640
+ let pmc = unsafe { pmc. assume_init( ) } ;
641
+ Some ( pmc. WorkingSetSize as usize )
642
+ }
643
+ }
644
+ }
645
+ } else {
646
+ fn get_resident( ) -> Option <usize > {
647
+ let field = 1 ;
648
+ let contents = fs:: read( "/proc/self/statm" ) . ok( ) ?;
649
+ let contents = String :: from_utf8( contents) . ok( ) ?;
650
+ let s = contents. split_whitespace( ) . nth( field) ?;
651
+ let npages = s. parse:: <usize >( ) . ok( ) ?;
652
+ Some ( npages * 4096 )
653
+ }
654
+ }
632
655
}
633
656
}
634
657
}
635
-
636
- #[ cfg( target_arch = "wasm32" ) ]
637
- fn get_resident ( ) -> Option < usize > {
638
- None
639
- }
0 commit comments