@@ -90,12 +90,58 @@ mod time {
90
90
Ok ( Date :: now ( ) / 1000.0 )
91
91
}
92
92
93
+ #[ cfg( not( any(
94
+ target_os = "macos" ,
95
+ target_os = "android" ,
96
+ target_os = "dragonfly" ,
97
+ target_os = "freebsd" ,
98
+ target_os = "linux" ,
99
+ ) ) ) ]
93
100
#[ pyfunction]
94
101
fn monotonic ( vm : & VirtualMachine ) -> PyResult < f64 > {
95
- // TODO: implement proper monotonic time!
102
+ // TODO: implement proper monotonic time for other platforms.
103
+ Ok ( duration_since_system_now ( vm) ?. as_secs_f64 ( ) )
104
+ }
105
+
106
+ #[ cfg( not( any(
107
+ target_os = "macos" ,
108
+ target_os = "android" ,
109
+ target_os = "dragonfly" ,
110
+ target_os = "freebsd" ,
111
+ target_os = "linux" ,
112
+ ) ) ) ]
113
+ #[ pyfunction]
114
+ fn monotonic_ns ( vm : & VirtualMachine ) -> PyResult < u128 > {
115
+ // TODO: implement proper monotonic time for other platforms.
116
+ Ok ( duration_since_system_now ( vm) ?. as_nanos ( ) )
117
+ }
118
+
119
+ #[ cfg( not( any(
120
+ target_os = "macos" ,
121
+ target_os = "android" ,
122
+ target_os = "dragonfly" ,
123
+ target_os = "freebsd" ,
124
+ target_os = "linux" ,
125
+ ) ) ) ]
126
+ #[ pyfunction]
127
+ fn perf_counter ( vm : & VirtualMachine ) -> PyResult < f64 > {
128
+ // TODO: implement proper monotonic time for other platforms.
96
129
Ok ( duration_since_system_now ( vm) ?. as_secs_f64 ( ) )
97
130
}
98
131
132
+ #[ cfg( not( any(
133
+ target_os = "macos" ,
134
+ target_os = "android" ,
135
+ target_os = "dragonfly" ,
136
+ target_os = "freebsd" ,
137
+ target_os = "linux" ,
138
+ ) ) ) ]
139
+ #[ pyfunction]
140
+ fn perf_counter_ns ( vm : & VirtualMachine ) -> PyResult < u128 > {
141
+ // TODO: implement proper monotonic time for other platforms.
142
+ Ok ( duration_since_system_now ( vm) ?. as_nanos ( ) )
143
+ }
144
+
99
145
fn pyobj_to_naive_date_time (
100
146
value : Either < f64 , i64 > ,
101
147
vm : & VirtualMachine ,
@@ -581,6 +627,54 @@ mod unix {
581
627
Err ( vm. new_not_implemented_error ( "get_clock_info unsupported on this system" . to_owned ( ) ) )
582
628
}
583
629
630
+ #[ cfg( any(
631
+ target_os = "macos" ,
632
+ target_os = "android" ,
633
+ target_os = "dragonfly" ,
634
+ target_os = "freebsd" ,
635
+ target_os = "linux" ,
636
+ ) ) ]
637
+ #[ pyfunction]
638
+ fn monotonic ( vm : & VirtualMachine ) -> PyResult < f64 > {
639
+ clock_gettime ( vm. ctx . new_int ( CLOCK_MONOTONIC ) , vm)
640
+ }
641
+
642
+ #[ cfg( any(
643
+ target_os = "macos" ,
644
+ target_os = "android" ,
645
+ target_os = "dragonfly" ,
646
+ target_os = "freebsd" ,
647
+ target_os = "linux" ,
648
+ ) ) ]
649
+ #[ pyfunction]
650
+ fn monotonic_ns ( vm : & VirtualMachine ) -> PyResult < u128 > {
651
+ clock_gettime_ns ( vm. ctx . new_int ( CLOCK_MONOTONIC ) , vm)
652
+ }
653
+
654
+ #[ cfg( any(
655
+ target_os = "macos" ,
656
+ target_os = "android" ,
657
+ target_os = "dragonfly" ,
658
+ target_os = "freebsd" ,
659
+ target_os = "linux" ,
660
+ ) ) ]
661
+ #[ pyfunction]
662
+ fn perf_counter ( vm : & VirtualMachine ) -> PyResult < f64 > {
663
+ clock_gettime ( vm. ctx . new_int ( CLOCK_MONOTONIC ) , vm)
664
+ }
665
+
666
+ #[ cfg( any(
667
+ target_os = "macos" ,
668
+ target_os = "android" ,
669
+ target_os = "dragonfly" ,
670
+ target_os = "freebsd" ,
671
+ target_os = "linux" ,
672
+ ) ) ]
673
+ #[ pyfunction]
674
+ fn perf_counter_ns ( vm : & VirtualMachine ) -> PyResult < u128 > {
675
+ clock_gettime_ns ( vm. ctx . new_int ( CLOCK_MONOTONIC ) , vm)
676
+ }
677
+
584
678
#[ pyfunction]
585
679
fn sleep ( dur : Duration , vm : & VirtualMachine ) -> PyResult < ( ) > {
586
680
// this is basically std::thread::sleep, but that catches interrupts and we don't want to;
0 commit comments