Skip to content

make default summarize table output a bit more compact #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions summarize/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
.sort_by(|l, r| r.self_time.cmp(&l.self_time));

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

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

table.add_row(Row::new(filter_cells(columns)));
table.set_titles(Row::new(filter_cells(columns)));

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

let mut label_max_width = (results.query_data.iter())
.map(|q| q.label.len())
.max()
.unwrap_or(0);
fn pad(s: &str, max: usize) -> String {
if s.len() >= max {
return s.to_string();
}

let pad = max.saturating_sub(s.len());
format!("{s}{:.<pad$}", " ")
}
for query_data in results.query_data {
let curr_percent = (query_data.self_time.as_nanos() as f64) / total_time * 100.0;
if curr_percent < percent_above {
Expand All @@ -260,7 +273,7 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
// Don't show the cache hits, blocked time or incremental load time columns unless there is
// data to show.
table.add_row(Row::new(filter_cells(&[
(&query_data.label, true),
(&pad(&query_data.label, label_max_width), true),
(&format!("{:.2?}", query_data.self_time), true),
(&format!("{:.3}", curr_percent), true),
(&format!("{:.2?}", query_data.time), true),
Expand Down Expand Up @@ -296,8 +309,9 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
}

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

table.add_row(row!("Item", "Artifact Size",));
table.set_titles(row!("Item", "Artifact Size"));

for artifact_size in results.artifact_sizes {
table.add_row(row![
Expand Down