Skip to content

Commit 15172a6

Browse files
authored
Merge pull request #241 from shua/compact
make default table output a bit more compact
2 parents b8af7fc + b976712 commit 15172a6

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

summarize/src/main.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ fn diff(opt: DiffOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
106106
}
107107

108108
let mut table = Table::new();
109+
table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
109110

110-
table.add_row(row!(
111+
table.set_titles(row!(
111112
"Item",
112113
"Self Time",
113114
"Self Time Change",
@@ -120,14 +121,25 @@ fn diff(opt: DiffOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
120121
"Incremental hashing time",
121122
));
122123

124+
let label_max_width = (results.query_data.iter())
125+
.map(|q| q.label.len())
126+
.max()
127+
.unwrap_or(0);
128+
fn pad(s: &str, max: usize) -> String {
129+
let Some(pad) = max.checked_sub(s.len()) else {
130+
return s.to_string();
131+
};
132+
133+
format!("{s}{:.<pad$}", " ")
134+
}
123135
for query_data in results.query_data {
124136
let exclude = opt.exclude.iter().any(|e| query_data.label.contains(e));
125137
if exclude {
126138
continue;
127139
}
128140

129141
table.add_row(row![
130-
query_data.label,
142+
pad(&query_data.label, label_max_width),
131143
format!("{:.2?}", query_data.self_time),
132144
format!("{:+.2}%", query_data.self_time_change),
133145
format!("{:.2?}", query_data.time),
@@ -145,8 +157,9 @@ fn diff(opt: DiffOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
145157
println!("Total cpu time: {:?}", results.total_time);
146158

147159
let mut table = Table::new();
160+
table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
148161

149-
table.add_row(row!("Item", "Artifact Size Change",));
162+
table.set_titles(row!("Item", "Artifact Size Change",));
150163

151164
for artifact_size in results.artifact_sizes {
152165
let exclude = opt.exclude.iter().any(|e| artifact_size.label.contains(e));
@@ -192,6 +205,7 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
192205
.sort_by(|l, r| r.self_time.cmp(&l.self_time));
193206

194207
let mut table = Table::new();
208+
table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
195209

196210
let mut has_cache_hits = false;
197211
let mut has_blocked_time = false;
@@ -244,11 +258,22 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
244258
.collect()
245259
}
246260

247-
table.add_row(Row::new(filter_cells(columns)));
261+
table.set_titles(Row::new(filter_cells(columns)));
248262

249263
let total_time = results.total_time.as_nanos() as f64;
250264
let mut percent_total_time: f64 = 0.0;
251265

266+
let label_max_width = (results.query_data.iter())
267+
.map(|q| q.label.len())
268+
.max()
269+
.unwrap_or(0);
270+
fn pad(s: &str, max: usize) -> String {
271+
let Some(pad) = max.checked_sub(s.len()) else {
272+
return s.to_string();
273+
};
274+
275+
format!("{s}{:.<pad$}", " ")
276+
}
252277
for query_data in results.query_data {
253278
let curr_percent = (query_data.self_time.as_nanos() as f64) / total_time * 100.0;
254279
if curr_percent < percent_above {
@@ -260,7 +285,7 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
260285
// Don't show the cache hits, blocked time or incremental load time columns unless there is
261286
// data to show.
262287
table.add_row(Row::new(filter_cells(&[
263-
(&query_data.label, true),
288+
(&pad(&query_data.label, label_max_width), true),
264289
(&format!("{:.2?}", query_data.self_time), true),
265290
(&format!("{:.3}", curr_percent), true),
266291
(&format!("{:.2?}", query_data.time), true),
@@ -296,8 +321,9 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
296321
}
297322

298323
let mut table = Table::new();
324+
table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
299325

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

302328
for artifact_size in results.artifact_sizes {
303329
table.add_row(row![

0 commit comments

Comments
 (0)