@@ -76,23 +76,46 @@ impl<T> Categories<T> {
76
76
77
77
struct CategoryData {
78
78
times : Categories < u64 > ,
79
+ query_counts : Categories < ( u64 , u64 ) > ,
79
80
}
80
81
81
82
impl CategoryData {
82
83
fn new ( ) -> CategoryData {
83
84
CategoryData {
84
85
times : Categories :: new ( ) ,
86
+ query_counts : Categories :: new ( ) ,
85
87
}
86
88
}
87
89
88
90
fn print ( & self , lock : & mut StdoutLock ) {
89
- writeln ! ( lock, "{0: <15} \t \t {1: <15}" , "Parsing" , self . times. parsing / 1_000_000 ) . unwrap ( ) ;
90
- writeln ! ( lock, "{0: <15} \t \t {1: <15}" , "Expansion" , self . times. expansion / 1_000_000 ) . unwrap ( ) ;
91
- writeln ! ( lock, "{0: <15} \t \t {1: <15}" , "TypeChecking" , self . times. type_checking / 1_000_000 ) . unwrap ( ) ;
92
- writeln ! ( lock, "{0: <15} \t \t {1: <15}" , "BorrowChecking" , self . times. borrow_checking / 1_000_000 ) . unwrap ( ) ;
93
- writeln ! ( lock, "{0: <15} \t \t {1: <15}" , "Codegen" , self . times. codegen / 1_000_000 ) . unwrap ( ) ;
94
- writeln ! ( lock, "{0: <15} \t \t {1: <15}" , "Linking" , self . times. linking / 1_000_000 ) . unwrap ( ) ;
95
- writeln ! ( lock, "{0: <15} \t \t {1: <15}" , "Other" , self . times. other / 1_000_000 ) . unwrap ( ) ;
91
+ macro_rules! p {
92
+ ( $name: tt, $rustic_name: ident) => {
93
+ writeln!(
94
+ lock,
95
+ "{0: <15} \t \t {1: <15}" ,
96
+ $name,
97
+ self . times. $rustic_name / 1_000_000
98
+ ) . unwrap( ) ;
99
+
100
+ let ( hits, total) = self . query_counts. $rustic_name;
101
+ if total > 0 {
102
+ writeln!(
103
+ lock,
104
+ "\t {} hits {} queries" ,
105
+ hits,
106
+ total
107
+ ) . unwrap( ) ;
108
+ }
109
+ } ;
110
+ }
111
+
112
+ p ! ( "Parsing" , parsing) ;
113
+ p ! ( "Expansion" , expansion) ;
114
+ p ! ( "TypeChecking" , type_checking) ;
115
+ p ! ( "BorrowChecking" , borrow_checking) ;
116
+ p ! ( "Codegen" , codegen) ;
117
+ p ! ( "Linking" , linking) ;
118
+ p ! ( "Other" , other) ;
96
119
}
97
120
}
98
121
@@ -147,6 +170,16 @@ impl SelfProfiler {
147
170
self . timer_stack . push ( category) ;
148
171
}
149
172
173
+ pub fn record_query ( & mut self , category : ProfileCategory ) {
174
+ let ( hits, total) = * self . data . query_counts . get ( category) ;
175
+ self . data . query_counts . set ( category, ( hits, total + 1 ) ) ;
176
+ }
177
+
178
+ pub fn record_query_hit ( & mut self , category : ProfileCategory ) {
179
+ let ( hits, total) = * self . data . query_counts . get ( category) ;
180
+ self . data . query_counts . set ( category, ( hits + 1 , total) ) ;
181
+ }
182
+
150
183
pub fn end_activity ( & mut self , category : ProfileCategory ) {
151
184
match self . timer_stack . pop ( ) {
152
185
None => bug ! ( "end_activity() was called but there was no running activity" ) ,
0 commit comments