@@ -54,6 +54,18 @@ mod time {
54
54
. map_err ( |e| vm. new_value_error ( format ! ( "Time error: {:?}" , e) ) )
55
55
}
56
56
57
+ // TODO: implement proper monotonic time for wasm/wasi.
58
+ #[ cfg( not( any( unix, windows) ) ) ]
59
+ fn get_monotonic_time ( vm : & VirtualMachine ) -> PyResult < std:: time:: Duration > {
60
+ duration_since_system_now ( vm)
61
+ }
62
+
63
+ // TODO: implement proper perf time for wasm/wasi.
64
+ #[ cfg( not( any( unix, windows) ) ) ]
65
+ fn get_perf_time ( vm : & VirtualMachine ) -> PyResult < std:: time:: Duration > {
66
+ duration_since_system_now ( vm)
67
+ }
68
+
57
69
#[ cfg( not( unix) ) ]
58
70
#[ pyfunction]
59
71
fn sleep ( dur : std:: time:: Duration ) {
@@ -66,7 +78,6 @@ mod time {
66
78
Ok ( duration_since_system_now ( vm) ?. as_nanos ( ) as u64 )
67
79
}
68
80
69
- #[ pyfunction( name = "perf_counter" ) ] // TODO: fix
70
81
#[ pyfunction]
71
82
pub fn time ( vm : & VirtualMachine ) -> PyResult < f64 > {
72
83
_time ( vm)
@@ -90,32 +101,24 @@ mod time {
90
101
Ok ( Date :: now ( ) / 1000.0 )
91
102
}
92
103
93
- #[ cfg( target_os = "wasi" ) ]
94
104
#[ pyfunction]
95
105
fn monotonic ( vm : & VirtualMachine ) -> PyResult < f64 > {
96
- // TODO: implement proper monotonic time for other platforms.
97
- Ok ( duration_since_system_now ( vm) ?. as_secs_f64 ( ) )
106
+ Ok ( get_monotonic_time ( vm) ?. as_secs_f64 ( ) )
98
107
}
99
108
100
- #[ cfg( target_os = "wasi" ) ]
101
109
#[ pyfunction]
102
110
fn monotonic_ns ( vm : & VirtualMachine ) -> PyResult < u128 > {
103
- // TODO: implement proper monotonic time for other platforms.
104
- Ok ( duration_since_system_now ( vm) ?. as_nanos ( ) )
111
+ Ok ( get_monotonic_time ( vm) ?. as_nanos ( ) )
105
112
}
106
113
107
- #[ cfg( target_os = "wasi" ) ]
108
114
#[ pyfunction]
109
115
fn perf_counter ( vm : & VirtualMachine ) -> PyResult < f64 > {
110
- // TODO: implement proper monotonic time for other platforms.
111
- Ok ( duration_since_system_now ( vm) ?. as_secs_f64 ( ) )
116
+ Ok ( get_perf_time ( vm) ?. as_secs_f64 ( ) )
112
117
}
113
118
114
- #[ cfg( target_os = "wasi" ) ]
115
119
#[ pyfunction]
116
120
fn perf_counter_ns ( vm : & VirtualMachine ) -> PyResult < u128 > {
117
- // TODO: implement proper monotonic time for other platforms.
118
- Ok ( duration_since_system_now ( vm) ?. as_nanos ( ) )
121
+ Ok ( get_perf_time ( vm) ?. as_nanos ( ) )
119
122
}
120
123
121
124
fn pyobj_to_naive_date_time (
@@ -574,24 +577,12 @@ mod unix {
574
577
Err ( vm. new_not_implemented_error ( "get_clock_info unsupported on this system" . to_owned ( ) ) )
575
578
}
576
579
577
- #[ pyfunction]
578
- fn monotonic ( vm : & VirtualMachine ) -> PyResult < f64 > {
579
- clock_gettime ( vm. ctx . new_int ( CLOCK_MONOTONIC ) , vm)
580
+ pub ( super ) fn get_monotonic_time ( vm : & VirtualMachine ) -> PyResult < Duration > {
581
+ get_clock_time ( vm. ctx . new_int ( CLOCK_MONOTONIC ) , vm)
580
582
}
581
583
582
- #[ pyfunction]
583
- fn monotonic_ns ( vm : & VirtualMachine ) -> PyResult < u128 > {
584
- clock_gettime_ns ( vm. ctx . new_int ( CLOCK_MONOTONIC ) , vm)
585
- }
586
-
587
- #[ pyfunction]
588
- fn perf_counter ( vm : & VirtualMachine ) -> PyResult < f64 > {
589
- clock_gettime ( vm. ctx . new_int ( CLOCK_MONOTONIC ) , vm)
590
- }
591
-
592
- #[ pyfunction]
593
- fn perf_counter_ns ( vm : & VirtualMachine ) -> PyResult < u128 > {
594
- clock_gettime_ns ( vm. ctx . new_int ( CLOCK_MONOTONIC ) , vm)
584
+ pub ( super ) fn get_perf_time ( vm : & VirtualMachine ) -> PyResult < Duration > {
585
+ get_clock_time ( vm. ctx . new_int ( CLOCK_MONOTONIC ) , vm)
595
586
}
596
587
597
588
#[ pyfunction]
@@ -740,7 +731,7 @@ mod windows {
740
731
. clone ( )
741
732
}
742
733
743
- fn win_perf_counter ( vm : & VirtualMachine ) -> PyResult < Duration > {
734
+ pub ( super ) fn get_perf_time ( vm : & VirtualMachine ) -> PyResult < Duration > {
744
735
let now = unsafe {
745
736
let mut performance_count = std:: mem:: MaybeUninit :: uninit ( ) ;
746
737
QueryPerformanceCounter ( performance_count. as_mut_ptr ( ) ) ;
@@ -773,7 +764,7 @@ mod windows {
773
764
Ok ( time_increment)
774
765
}
775
766
776
- fn get_monotonic_clock ( vm : & VirtualMachine ) -> PyResult < Duration > {
767
+ pub ( super ) fn get_monotonic_time ( vm : & VirtualMachine ) -> PyResult < Duration > {
777
768
let ticks = unsafe { GetTickCount64 ( ) } ;
778
769
779
770
Ok ( Duration :: from_nanos (
@@ -817,26 +808,6 @@ mod windows {
817
808
} ) )
818
809
}
819
810
820
- #[ pyfunction]
821
- fn monotonic ( vm : & VirtualMachine ) -> PyResult < f64 > {
822
- Ok ( get_monotonic_clock ( vm) ?. as_secs_f64 ( ) )
823
- }
824
-
825
- #[ pyfunction]
826
- fn monotonic_ns ( vm : & VirtualMachine ) -> PyResult < u128 > {
827
- Ok ( get_monotonic_clock ( vm) ?. as_nanos ( ) )
828
- }
829
-
830
- #[ pyfunction]
831
- fn perf_counter ( vm : & VirtualMachine ) -> PyResult < f64 > {
832
- Ok ( win_perf_counter ( vm) ?. as_secs_f64 ( ) )
833
- }
834
-
835
- #[ pyfunction]
836
- fn perf_counter_ns ( vm : & VirtualMachine ) -> PyResult < u128 > {
837
- Ok ( win_perf_counter ( vm) ?. as_nanos ( ) )
838
- }
839
-
840
811
pub ( super ) fn get_thread_time ( vm : & VirtualMachine ) -> PyResult < Duration > {
841
812
let ( kernel_time, user_time) = unsafe {
842
813
let mut _creation_time = std:: mem:: MaybeUninit :: uninit ( ) ;
0 commit comments