@@ -860,6 +860,7 @@ fn get_thread_id() -> u32 {
860860} 
861861
862862// Memory reporting 
863+ #[ cfg( bootstrap) ]  
863864cfg_match !  { 
864865    cfg( windows)  => { 
865866        pub  fn  get_resident_set_size( )  -> Option <usize > { 
@@ -921,5 +922,67 @@ cfg_match! {
921922    } 
922923} 
923924
925+ #[ cfg( not( bootstrap) ) ]  
926+ cfg_match !  { 
927+     windows => { 
928+         pub  fn  get_resident_set_size( )  -> Option <usize > { 
929+             use  std:: mem; 
930+ 
931+             use  windows:: { 
932+                 Win32 :: System :: ProcessStatus :: { K32GetProcessMemoryInfo ,  PROCESS_MEMORY_COUNTERS } , 
933+                 Win32 :: System :: Threading :: GetCurrentProcess , 
934+             } ; 
935+ 
936+             let  mut  pmc = PROCESS_MEMORY_COUNTERS :: default ( ) ; 
937+             let  pmc_size = mem:: size_of_val( & pmc) ; 
938+             unsafe  { 
939+                 K32GetProcessMemoryInfo ( 
940+                     GetCurrentProcess ( ) , 
941+                     & mut  pmc, 
942+                     pmc_size as  u32 , 
943+                 ) 
944+             } 
945+             . ok( ) 
946+             . ok( ) ?; 
947+ 
948+             Some ( pmc. WorkingSetSize ) 
949+         } 
950+     } 
951+     target_os = "macos"  => { 
952+         pub  fn  get_resident_set_size( )  -> Option <usize > { 
953+             use  libc:: { c_int,  c_void,  getpid,  proc_pidinfo,  proc_taskinfo,  PROC_PIDTASKINFO } ; 
954+             use  std:: mem; 
955+             const  PROC_TASKINFO_SIZE :  c_int = mem:: size_of:: <proc_taskinfo>( )  as  c_int; 
956+ 
957+             unsafe  { 
958+                 let  mut  info:  proc_taskinfo = mem:: zeroed( ) ; 
959+                 let  info_ptr = & mut  info as  * mut  proc_taskinfo as  * mut  c_void; 
960+                 let  pid = getpid( )  as  c_int; 
961+                 let  ret = proc_pidinfo( pid,  PROC_PIDTASKINFO ,  0 ,  info_ptr,  PROC_TASKINFO_SIZE ) ; 
962+                 if  ret == PROC_TASKINFO_SIZE  { 
963+                     Some ( info. pti_resident_size as  usize ) 
964+                 }  else { 
965+                     None 
966+                 } 
967+             } 
968+         } 
969+     } 
970+     unix => { 
971+         pub  fn  get_resident_set_size( )  -> Option <usize > { 
972+             let  field = 1 ; 
973+             let  contents = fs:: read( "/proc/self/statm" ) . ok( ) ?; 
974+             let  contents = String :: from_utf8( contents) . ok( ) ?; 
975+             let  s = contents. split_whitespace( ) . nth( field) ?; 
976+             let  npages = s. parse:: <usize >( ) . ok( ) ?; 
977+             Some ( npages *  4096 ) 
978+         } 
979+     } 
980+     _ => { 
981+         pub  fn  get_resident_set_size( )  -> Option <usize > { 
982+             None 
983+         } 
984+     } 
985+ } 
986+ 
924987#[ cfg( test) ]  
925988mod  tests; 
0 commit comments