@@ -248,15 +248,15 @@ mod time {
248
248
Ok ( get_thread_time ( vm) ?. as_nanos ( ) as u64 )
249
249
}
250
250
251
- #[ cfg( any( windows, all( target_arch = "wasm32" , not ( target_os = "unknown" ) ) ) ) ]
251
+ #[ cfg( any( windows, all( target_arch = "wasm32" , target_arch = "emscripten" ) ) ) ]
252
252
pub ( super ) fn time_muldiv ( ticks : i64 , mul : i64 , div : i64 ) -> u64 {
253
253
let intpart = ticks / div;
254
254
let ticks = ticks % div;
255
255
let remaining = ( ticks * mul) / div;
256
256
( intpart * mul + remaining) as u64
257
257
}
258
258
259
- #[ cfg( all( target_arch = "wasm32" , not ( target_os = "unknown" ) ) ) ]
259
+ #[ cfg( all( target_arch = "wasm32" , target_os = "emscripten" ) ) ]
260
260
fn get_process_time ( vm : & VirtualMachine ) -> PyResult < Duration > {
261
261
let t: libc:: tms = unsafe {
262
262
let mut t = std:: mem:: MaybeUninit :: uninit ( ) ;
@@ -265,17 +265,26 @@ mod time {
265
265
}
266
266
t. assume_init ( )
267
267
} ;
268
-
269
- #[ cfg( target_os = "wasi" ) ]
270
- let freq = 60 ;
271
- #[ cfg( not( target_os = "wasi" ) ) ]
272
268
let freq = unsafe { libc:: sysconf ( libc:: _SC_CLK_TCK) } ;
273
269
274
270
Ok ( Duration :: from_nanos (
275
271
time_muldiv ( t. tms_utime , SEC_TO_NS , freq) + time_muldiv ( t. tms_stime , SEC_TO_NS , freq) ,
276
272
) )
277
273
}
278
274
275
+ // same as the get_process_time impl for most unixes
276
+ #[ cfg( all( target_arch = "wasm32" , target_os = "wasi" ) ) ]
277
+ pub ( super ) fn get_process_time ( vm : & VirtualMachine ) -> PyResult < Duration > {
278
+ let time: libc:: timespec = unsafe {
279
+ let mut time = std:: mem:: MaybeUninit :: uninit ( ) ;
280
+ if libc:: clock_gettime ( libc:: CLOCK_PROCESS_CPUTIME_ID , time. as_mut_ptr ( ) ) == -1 {
281
+ return Err ( vm. new_os_error ( "Failed to get clock time" . to_owned ( ) ) ) ;
282
+ }
283
+ time. assume_init ( )
284
+ } ;
285
+ Ok ( Duration :: new ( time. tv_sec as u64 , time. tv_nsec as u32 ) )
286
+ }
287
+
279
288
#[ cfg( not( any(
280
289
windows,
281
290
target_os = "macos" ,
0 commit comments