1
+ use super :: work_counter:: { WorkCounter , WorkCounterBase , WorkDuration } ;
1
2
use std:: any:: TypeId ;
2
3
use std:: collections:: HashMap ;
3
4
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
4
- use std:: time:: SystemTime ;
5
5
6
6
#[ derive( Default ) ]
7
7
pub struct SchedulerStat {
@@ -10,110 +10,6 @@ pub struct SchedulerStat {
10
10
work_counters : HashMap < TypeId , Vec < Vec < Box < dyn WorkCounter > > > > ,
11
11
}
12
12
13
- #[ derive( Copy , Clone ) ]
14
- struct WorkCounterBase {
15
- total : f64 ,
16
- min : f64 ,
17
- max : f64 ,
18
- }
19
-
20
- impl Default for WorkCounterBase {
21
- fn default ( ) -> Self {
22
- WorkCounterBase {
23
- total : 0.0 ,
24
- min : f64:: INFINITY ,
25
- max : f64:: NEG_INFINITY ,
26
- }
27
- }
28
- }
29
-
30
- impl WorkCounterBase {
31
- fn merge ( & self , other : & Self ) -> Self {
32
- let min = self . min . min ( other. min ) ;
33
- let max = self . max . max ( other. max ) ;
34
- let total = self . total + other. total ;
35
- WorkCounterBase { total, min, max }
36
- }
37
-
38
- fn merge_inplace ( & mut self , other : & Self ) {
39
- self . min = self . min . min ( other. min ) ;
40
- self . max = self . max . max ( other. max ) ;
41
- self . total += other. total ;
42
- }
43
-
44
- fn merge_val ( & mut self , val : f64 ) {
45
- self . min = self . min . min ( val) ;
46
- self . max = self . max . max ( val) ;
47
- self . total += val;
48
- }
49
- }
50
-
51
- trait WorkCounter : WorkCounterClone {
52
- // TODO: consolidate with crate::util::statistics::counter::Counter;
53
- fn start ( & mut self ) ;
54
- fn stop ( & mut self ) ;
55
- fn name ( & self ) -> & ' static str ;
56
- fn get_base ( & self ) -> & WorkCounterBase ;
57
- fn get_base_mut ( & mut self ) -> & mut WorkCounterBase ;
58
- }
59
-
60
- trait WorkCounterClone {
61
- fn clone_box ( & self ) -> Box < dyn WorkCounter > ;
62
- }
63
-
64
- impl < T : ' static + WorkCounter + Clone > WorkCounterClone for T {
65
- fn clone_box ( & self ) -> Box < dyn WorkCounter > {
66
- Box :: new ( self . clone ( ) )
67
- }
68
- }
69
-
70
- impl Clone for Box < dyn WorkCounter > {
71
- fn clone ( & self ) -> Box < dyn WorkCounter > {
72
- self . clone_box ( )
73
- }
74
- }
75
-
76
- #[ derive( Copy , Clone ) ]
77
- struct WorkDuration {
78
- base : WorkCounterBase ,
79
- start_value : Option < SystemTime > ,
80
- running : bool ,
81
- }
82
-
83
- impl WorkDuration {
84
- fn new ( ) -> Self {
85
- WorkDuration {
86
- base : Default :: default ( ) ,
87
- start_value : None ,
88
- running : false ,
89
- }
90
- }
91
- }
92
-
93
- impl WorkCounter for WorkDuration {
94
- fn start ( & mut self ) {
95
- self . start_value = Some ( SystemTime :: now ( ) ) ;
96
- self . running = true ;
97
- }
98
-
99
- fn stop ( & mut self ) {
100
- let duration = self . start_value . unwrap ( ) . elapsed ( ) . unwrap ( ) . as_nanos ( ) as f64 ;
101
- self . base . merge_val ( duration) ;
102
- }
103
-
104
- fn name ( & self ) -> & ' static str {
105
- "time"
106
- }
107
-
108
- fn get_base ( & self ) -> & WorkCounterBase {
109
- & self . base
110
- }
111
-
112
- fn get_base_mut ( & mut self ) -> & mut WorkCounterBase {
113
- & mut self . base
114
- }
115
- }
116
-
117
13
impl SchedulerStat {
118
14
/// Extract the work-packet name from the full type name.
119
15
/// i.e. simplifies `crate::scheduler::gc_work::SomeWorkPacket<Semispace>` to `SomeWorkPacket`.
0 commit comments