@@ -11,21 +11,27 @@ macro_rules! really_warn {
11
11
}
12
12
13
13
pub enum Counter {
14
- WallTime ( WallTime ) ,
15
- Instructions ( Instructions ) ,
14
+ Zero ( InstructionsMinusIrqs ) ,
15
+ WallTime ( InstructionsMinusIrqs , WallTime ) ,
16
+ Instructions ( InstructionsMinusIrqs , Instructions ) ,
16
17
InstructionsMinusIrqs ( InstructionsMinusIrqs ) ,
17
18
InstructionsMinusRaw0420 ( InstructionsMinusRaw0420 ) ,
18
19
}
19
20
20
21
impl Counter {
21
22
pub fn by_name ( name : & str ) -> Result < Self , Box < dyn Error + Send + Sync > > {
22
23
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 => {
26
32
Counter :: InstructionsMinusIrqs ( InstructionsMinusIrqs :: new ( ) ?)
27
33
}
28
- InstructionsMinusRaw0420 :: NAME => {
34
+ "r" | InstructionsMinusRaw0420 :: NAME => {
29
35
Counter :: InstructionsMinusRaw0420 ( InstructionsMinusRaw0420 :: new ( ) ?)
30
36
}
31
37
_ => return Err ( format ! ( "{:?} is not a valid counter name" , name) . into ( ) ) ,
@@ -34,11 +40,12 @@ impl Counter {
34
40
35
41
pub ( super ) fn describe_as_json ( & self ) -> String {
36
42
let ( name, units) = match self {
37
- Counter :: WallTime ( _) => (
43
+ Counter :: Zero ( _) => ( "zero" , "[]" ) ,
44
+ Counter :: WallTime ( ..) => (
38
45
WallTime :: NAME ,
39
46
r#"[["ns", 1], ["μs", 1000], ["ms", 1000000], ["s", 1000000000]]"# ,
40
47
) ,
41
- Counter :: Instructions ( _ ) => ( Instructions :: NAME , r#"[["instructions", 1]]"# ) ,
48
+ Counter :: Instructions ( .. ) => ( Instructions :: NAME , r#"[["instructions", 1]]"# ) ,
42
49
Counter :: InstructionsMinusIrqs ( _) => {
43
50
( InstructionsMinusIrqs :: NAME , r#"[["instructions", 1]]"# )
44
51
}
@@ -52,8 +59,9 @@ impl Counter {
52
59
#[ inline]
53
60
pub ( super ) fn since_start ( & self ) -> u64 {
54
61
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 ( ) ,
57
65
Counter :: InstructionsMinusIrqs ( counter) => counter. since_start ( ) ,
58
66
Counter :: InstructionsMinusRaw0420 ( counter) => counter. since_start ( ) ,
59
67
}
@@ -132,6 +140,17 @@ impl InstructionsMinusIrqs {
132
140
}
133
141
}
134
142
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
+
135
154
// HACK(eddyb) this is a variant of `instructions-minus-irqs:u`, where `r0420`
136
155
// is subtracted, instead of the usual "hardware interrupts" (aka IRQs).
137
156
// `r0420` is an undocumented counter on AMD Zen CPUs which appears to count
0 commit comments