@@ -11,21 +11,27 @@ macro_rules! really_warn {
1111}
1212
1313pub enum Counter {
14- WallTime ( WallTime ) ,
15- Instructions ( Instructions ) ,
14+ Zero ( InstructionsMinusIrqs ) ,
15+ WallTime ( InstructionsMinusIrqs , WallTime ) ,
16+ Instructions ( InstructionsMinusIrqs , Instructions ) ,
1617 InstructionsMinusIrqs ( InstructionsMinusIrqs ) ,
1718 InstructionsMinusRaw0420 ( InstructionsMinusRaw0420 ) ,
1819}
1920
2021impl Counter {
2122 pub fn by_name ( name : & str ) -> Result < Self , Box < dyn Error + Send + Sync > > {
2223 Ok ( match name {
23- WallTime :: NAME => Counter :: WallTime ( WallTime :: new ( ) ) ,
24- Instructions :: NAME => Counter :: Instructions ( Instructions :: new ( ) ?) ,
25- InstructionsMinusIrqs :: NAME => {
24+ "0" => Counter :: Zero ( InstructionsMinusIrqs :: new ( ) ?) ,
25+ "t" | WallTime :: NAME => {
26+ Counter :: WallTime ( InstructionsMinusIrqs :: new ( ) ?, WallTime :: new ( ) )
27+ }
28+ "i" | Instructions :: NAME => {
29+ Counter :: Instructions ( InstructionsMinusIrqs :: new ( ) ?, Instructions :: new ( ) ?)
30+ }
31+ "I" | InstructionsMinusIrqs :: NAME => {
2632 Counter :: InstructionsMinusIrqs ( InstructionsMinusIrqs :: new ( ) ?)
2733 }
28- InstructionsMinusRaw0420 :: NAME => {
34+ "r" | InstructionsMinusRaw0420 :: NAME => {
2935 Counter :: InstructionsMinusRaw0420 ( InstructionsMinusRaw0420 :: new ( ) ?)
3036 }
3137 _ => return Err ( format ! ( "{:?} is not a valid counter name" , name) . into ( ) ) ,
@@ -34,11 +40,12 @@ impl Counter {
3440
3541 pub ( super ) fn describe_as_json ( & self ) -> String {
3642 let ( name, units) = match self {
37- Counter :: WallTime ( _) => (
43+ Counter :: Zero ( _) => ( "zero" , "[]" ) ,
44+ Counter :: WallTime ( ..) => (
3845 WallTime :: NAME ,
3946 r#"[["ns", 1], ["μs", 1000], ["ms", 1000000], ["s", 1000000000]]"# ,
4047 ) ,
41- Counter :: Instructions ( _ ) => ( Instructions :: NAME , r#"[["instructions", 1]]"# ) ,
48+ Counter :: Instructions ( .. ) => ( Instructions :: NAME , r#"[["instructions", 1]]"# ) ,
4249 Counter :: InstructionsMinusIrqs ( _) => {
4350 ( InstructionsMinusIrqs :: NAME , r#"[["instructions", 1]]"# )
4451 }
@@ -52,8 +59,9 @@ impl Counter {
5259 #[ inline]
5360 pub ( super ) fn since_start ( & self ) -> u64 {
5461 match self {
55- Counter :: WallTime ( counter) => counter. since_start ( ) ,
56- Counter :: Instructions ( counter) => counter. since_start ( ) ,
62+ Counter :: Zero ( _) => 0 ,
63+ Counter :: WallTime ( _, counter) => counter. since_start ( ) ,
64+ Counter :: Instructions ( _, counter) => counter. since_start ( ) ,
5765 Counter :: InstructionsMinusIrqs ( counter) => counter. since_start ( ) ,
5866 Counter :: InstructionsMinusRaw0420 ( counter) => counter. since_start ( ) ,
5967 }
@@ -132,6 +140,17 @@ impl InstructionsMinusIrqs {
132140 }
133141}
134142
143+ // HACK(eddyb) dump total `instructions-minus-irqs:u` for statistics.
144+ impl Drop for InstructionsMinusIrqs {
145+ fn drop ( & mut self ) {
146+ eprintln ! (
147+ "pid={:06} instructions-minus-irqs:u={}" ,
148+ std:: process:: id( ) ,
149+ self . since_start( ) ,
150+ ) ;
151+ }
152+ }
153+
135154// HACK(eddyb) this is a variant of `instructions-minus-irqs:u`, where `r0420`
136155// is subtracted, instead of the usual "hardware interrupts" (aka IRQs).
137156// `r0420` is an undocumented counter on AMD Zen CPUs which appears to count
0 commit comments