Skip to content

Commit 5139985

Browse files
shuaKobzol
authored andcommitted
make default summarize output a bit more compact
1 parent b8af7fc commit 5139985

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

summarize/src/main.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
192192
.sort_by(|l, r| r.self_time.cmp(&l.self_time));
193193

194194
let mut table = Table::new();
195+
table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
195196

196197
let mut has_cache_hits = false;
197198
let mut has_blocked_time = false;
@@ -244,11 +245,23 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
244245
.collect()
245246
}
246247

247-
table.add_row(Row::new(filter_cells(columns)));
248+
table.set_titles(Row::new(filter_cells(columns)));
248249

249250
let total_time = results.total_time.as_nanos() as f64;
250251
let mut percent_total_time: f64 = 0.0;
251252

253+
let mut label_max_width = (results.query_data.iter())
254+
.map(|q| q.label.len())
255+
.max()
256+
.unwrap_or(0);
257+
fn pad(s: &str, max: usize) -> String {
258+
if s.len() >= max {
259+
return s.to_string();
260+
}
261+
262+
let pad = max.saturating_sub(s.len());
263+
format!("{s}{:.<pad$}", " ")
264+
}
252265
for query_data in results.query_data {
253266
let curr_percent = (query_data.self_time.as_nanos() as f64) / total_time * 100.0;
254267
if curr_percent < percent_above {
@@ -260,7 +273,7 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
260273
// Don't show the cache hits, blocked time or incremental load time columns unless there is
261274
// data to show.
262275
table.add_row(Row::new(filter_cells(&[
263-
(&query_data.label, true),
276+
(&pad(&query_data.label, label_max_width), true),
264277
(&format!("{:.2?}", query_data.self_time), true),
265278
(&format!("{:.3}", curr_percent), true),
266279
(&format!("{:.2?}", query_data.time), true),
@@ -296,8 +309,9 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
296309
}
297310

298311
let mut table = Table::new();
312+
table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
299313

300-
table.add_row(row!("Item", "Artifact Size",));
314+
table.set_titles(row!("Item", "Artifact Size"));
301315

302316
for artifact_size in results.artifact_sizes {
303317
table.add_row(row![

0 commit comments

Comments
 (0)