@@ -12,26 +12,73 @@ pub use self::long_counter::{LongCounter, Timer};
1212pub use self :: perf_event:: PerfEventDiffable ;
1313pub use self :: size_counter:: SizeCounter ;
1414
15+ /// An abstraction over how a specific Diffable value is counted
16+ ///
17+ /// For example, we can just collect the values, and store the cummulative sum,
18+ /// or we can derive some kind of histogram, etc.
1519pub trait Counter {
20+ /// Start the counter
1621 fn start ( & mut self ) ;
22+ /// Stop the counter
1723 fn stop ( & mut self ) ;
24+ /// Signal a change in GC phase.
25+ ///
26+ /// The phase number starts from 0 and is strictly increasing.
27+ /// Even numbers mean mutators are running (`other`) while odd numbers mean
28+ /// stop-the-world pauses (`stw`).
29+ /// Take action with respect to the last phase if necessary.
1830 fn phase_change ( & mut self , old_phase : usize ) ;
31+ /// Print the counter value for a particular phase
32+ ///
33+ /// If the counter merges the phases, the printing value will include
34+ /// the specified phase and the next phase
1935 fn print_count ( & self , phase : usize ) ;
20- fn print_total ( & self , mutator : Option < bool > ) ;
21- fn print_min ( & self , mutator : bool ) ;
22- fn print_max ( & self , mutator : bool ) ;
36+ /// Get the total count over past phases
37+ ///
38+ /// If the argument is None, count all phases.
39+ /// Otherwise, count only `other` phases if true, or `stw` phases if false
40+ fn get_total ( & self , other : Option < bool > ) -> u64 ;
41+ /// Print the total count over past phases
42+ ///
43+ /// If the argument is None, count all phases.
44+ /// Otherwise, count only `other` phases if true, or `stw` phases if false
45+ fn print_total ( & self , other : Option < bool > ) ;
46+ /// Print the minimum count of the past phases
47+ ///
48+ /// Consider only `other` phases if true, or `stw` phases if false
49+ fn print_min ( & self , other : bool ) ;
50+ /// Print the maximum count of the past phases
51+ ///
52+ /// Consider only `other` phases if true, or `stw` phases if false
53+ fn print_max ( & self , other : bool ) ;
54+ /// Print the count of the last phases
2355 fn print_last ( & self ) ;
56+ /// Whether the counter merges other and stw phases.
2457 fn merge_phases ( & self ) -> bool ;
58+ /// Whether the counter starts implicitly after creation
59+ ///
60+ /// FIXME currently unused
2561 fn implicitly_start ( & self ) -> bool ;
62+ /// Get the name of the counter
2663 fn name ( & self ) -> & String ;
2764}
2865
66+ /// An abstraction over some changing values that we want to measure.
67+ ///
2968/// A Diffable object could be stateless (e.g. a timer that reads the wall
3069/// clock), or stateful (e.g. holds reference to a perf event fd)
3170pub trait Diffable {
71+ /// The type of each reading
3272 type Val ;
73+ /// Start the Diffable
74+ fn start ( & mut self ) ;
75+ /// Stop the Diffable
76+ fn stop ( & mut self ) ;
77+ /// Read the current value
3378 fn current_value ( & mut self ) -> Self :: Val ;
79+ /// Compute the difference between two readings
3480 fn diff ( current : & Self :: Val , earlier : & Self :: Val ) -> u64 ;
81+ /// Print the difference in a specific format
3582 fn print_diff ( val : u64 ) ;
3683}
3784
@@ -40,6 +87,12 @@ pub struct MonotoneNanoTime;
4087impl Diffable for MonotoneNanoTime {
4188 type Val = Instant ;
4289
90+ /// nop for the wall-clock time
91+ fn start ( & mut self ) { }
92+
93+ /// nop for the wall-clock time
94+ fn stop ( & mut self ) { }
95+
4396 fn current_value ( & mut self ) -> Instant {
4497 Instant :: now ( )
4598 }
0 commit comments