@@ -890,9 +890,12 @@ where
890
890
let span = ctx. span ( id) . expect ( "Span not found, this is a bug" ) ;
891
891
let mut extensions = span. extensions_mut ( ) ;
892
892
if let Some ( timings) = extensions. get_mut :: < Timings > ( ) {
893
- let now = Instant :: now ( ) ;
894
- timings. idle += ( now - timings. last ) . as_nanos ( ) as u64 ;
895
- timings. last = now;
893
+ if timings. entered_count == 0 {
894
+ let now = Instant :: now ( ) ;
895
+ timings. idle += ( now - timings. last ) . as_nanos ( ) as u64 ;
896
+ timings. last = now;
897
+ }
898
+ timings. entered_count += 1 ;
896
899
}
897
900
898
901
if self . fmt_span . trace_enter ( ) {
@@ -910,9 +913,12 @@ where
910
913
let span = ctx. span ( id) . expect ( "Span not found, this is a bug" ) ;
911
914
let mut extensions = span. extensions_mut ( ) ;
912
915
if let Some ( timings) = extensions. get_mut :: < Timings > ( ) {
913
- let now = Instant :: now ( ) ;
914
- timings. busy += ( now - timings. last ) . as_nanos ( ) as u64 ;
915
- timings. last = now;
916
+ timings. entered_count -= 1 ;
917
+ if timings. entered_count == 0 {
918
+ let now = Instant :: now ( ) ;
919
+ timings. busy += ( now - timings. last ) . as_nanos ( ) as u64 ;
920
+ timings. last = now;
921
+ }
916
922
}
917
923
918
924
if self . fmt_span . trace_exit ( ) {
@@ -934,7 +940,9 @@ where
934
940
busy,
935
941
mut idle,
936
942
last,
943
+ entered_count,
937
944
} = * timing;
945
+ debug_assert_eq ! ( entered_count, 0 ) ;
938
946
idle += ( Instant :: now ( ) - last) . as_nanos ( ) as u64 ;
939
947
940
948
let t_idle = field:: display ( TimingDisplay ( idle) ) ;
@@ -1224,6 +1232,7 @@ struct Timings {
1224
1232
idle : u64 ,
1225
1233
busy : u64 ,
1226
1234
last : Instant ,
1235
+ entered_count : u64 ,
1227
1236
}
1228
1237
1229
1238
impl Timings {
@@ -1232,6 +1241,7 @@ impl Timings {
1232
1241
idle : 0 ,
1233
1242
busy : 0 ,
1234
1243
last : Instant :: now ( ) ,
1244
+ entered_count : 0 ,
1235
1245
}
1236
1246
}
1237
1247
}
0 commit comments