@@ -5,9 +5,9 @@ use analyzeme::ProfilingData;
5
5
use std:: error:: Error ;
6
6
use std:: fs:: File ;
7
7
use std:: io:: { BufReader , BufWriter } ;
8
- use std:: path:: PathBuf ;
8
+ use std:: { path:: PathBuf , time :: Duration } ;
9
9
10
- use prettytable:: Table ;
10
+ use prettytable:: { Cell , Row , Table } ;
11
11
use serde:: Serialize ;
12
12
use structopt:: StructOpt ;
13
13
@@ -151,16 +151,49 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error>> {
151
151
152
152
let mut table = Table :: new ( ) ;
153
153
154
- table. add_row ( row ! [
155
- "Item" ,
156
- "Self time" ,
157
- "% of total time" ,
158
- "Time" ,
159
- "Item count" ,
160
- "Cache hits" ,
161
- "Blocked time" ,
162
- "Incremental load time" ,
163
- ] ) ;
154
+ let mut has_cache_hits = false ;
155
+ let mut has_blocked_time = false ;
156
+ let mut has_incremental_load_time = false ;
157
+
158
+ let duration_zero = Duration :: from_secs ( 0 ) ;
159
+ for r in & results. query_data {
160
+ if r. number_of_cache_hits > 0 {
161
+ has_cache_hits = true ;
162
+ }
163
+ if r. blocked_time > duration_zero {
164
+ has_blocked_time = true ;
165
+ }
166
+ if r. incremental_load_time > duration_zero {
167
+ has_incremental_load_time = true ;
168
+ }
169
+
170
+ if has_cache_hits && has_blocked_time && has_incremental_load_time {
171
+ break ;
172
+ }
173
+ }
174
+
175
+ // Don't show the cache hits, blocked time or incremental load time unless there are values
176
+ // to display.
177
+ let columns = & [
178
+ ( "Item" , true ) ,
179
+ ( "Self time" , true ) ,
180
+ ( "% of total time" , true ) ,
181
+ ( "Time" , true ) ,
182
+ ( "Item count" , true ) ,
183
+ ( "Cache hits" , has_cache_hits) ,
184
+ ( "Blocked time" , has_blocked_time) ,
185
+ ( "Incremental load time" , has_incremental_load_time) ,
186
+ ] ;
187
+
188
+ fn filter_cells ( cells : & [ ( & str , bool ) ] ) -> Vec < Cell > {
189
+ cells
190
+ . iter ( )
191
+ . filter ( |( _, show) | * show)
192
+ . map ( |( cell, _) | Cell :: new ( cell) )
193
+ . collect ( )
194
+ }
195
+
196
+ table. add_row ( Row :: new ( filter_cells ( columns) ) ) ;
164
197
165
198
let total_time = results. total_time . as_nanos ( ) as f64 ;
166
199
let mut percent_total_time: f64 = 0.0 ;
@@ -173,16 +206,27 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error>> {
173
206
174
207
percent_total_time = percent_total_time + curr_percent;
175
208
176
- table. add_row ( row ! [
177
- query_data. label,
178
- format!( "{:.2?}" , query_data. self_time) ,
179
- format!( "{:.3}" , curr_percent) ,
180
- format!( "{:.2?}" , query_data. time) ,
181
- format!( "{}" , query_data. invocation_count) ,
182
- format!( "{}" , query_data. number_of_cache_hits) ,
183
- format!( "{:.2?}" , query_data. blocked_time) ,
184
- format!( "{:.2?}" , query_data. incremental_load_time) ,
185
- ] ) ;
209
+ // Don't show the cache hits, blocked time or incremental load time columns unless there is
210
+ // data to show.
211
+ table. add_row ( Row :: new ( filter_cells ( & [
212
+ ( & query_data. label , true ) ,
213
+ ( & format ! ( "{:.2?}" , query_data. self_time) , true ) ,
214
+ ( & format ! ( "{:.3}" , curr_percent) , true ) ,
215
+ ( & format ! ( "{:.2?}" , query_data. time) , true ) ,
216
+ ( & format ! ( "{}" , query_data. invocation_count) , true ) ,
217
+ (
218
+ & format ! ( "{}" , query_data. number_of_cache_hits) ,
219
+ has_cache_hits,
220
+ ) ,
221
+ (
222
+ & format ! ( "{:.2?}" , query_data. blocked_time) ,
223
+ has_blocked_time,
224
+ ) ,
225
+ (
226
+ & format ! ( "{:.2?}" , query_data. incremental_load_time) ,
227
+ has_incremental_load_time,
228
+ ) ,
229
+ ] ) ) ) ;
186
230
}
187
231
188
232
table. printstd ( ) ;
0 commit comments