From 752535589b8d925033b6c57ef893aaebbae318bc Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Sat, 27 Apr 2019 17:06:28 -0400 Subject: [PATCH 1/5] summarize (feature): adds percent-above cli argument to show table with percent greater than rows above the value --- summarize/src/main.rs | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/summarize/src/main.rs b/summarize/src/main.rs index ab5768a..03cce7a 100644 --- a/summarize/src/main.rs +++ b/summarize/src/main.rs @@ -18,6 +18,10 @@ struct Opt { /// Writes the analysis to a json file next to instead of stdout #[structopt(long = "json")] json: bool, + + /// Filters the output rows where "% of total time" > "percent-above" + #[structopt(short = "pa", long = "percent-above", default_value = "1.0")] + percent_above: f64, } fn main() -> Result<(), Box> { @@ -34,6 +38,15 @@ fn main() -> Result<(), Box> { return Ok(()); } + //cannot be greater than 100% or less than 0% + let percent_above = if opt.percent_above > 100.0 { + 100.0 + } else if opt.percent_above < 0.0 { + 0.0 + } else { + opt.percent_above + }; + //order the results by descending self time results.query_data.sort_by(|l, r| r.self_time.cmp(&l.self_time)); @@ -52,20 +65,26 @@ fn main() -> Result<(), Box> { let total_time = results.total_time.as_nanos() as f64; for query_data in results.query_data { - table.add_row(row![ - query_data.label, - format!("{:.2?}", query_data.self_time), - format!("{:.3}", ((query_data.self_time.as_nanos() as f64) / total_time) * 100.0), - format!("{}", query_data.invocation_count), - format!("{}", query_data.number_of_cache_hits), - format!("{:.2?}", query_data.blocked_time), - format!("{:.2?}", query_data.incremental_load_time), - ]); + + let percent = (query_data.self_time.as_nanos() as f64) / total_time * 100.0; + + if percent > percent_above { + table.add_row(row![ + query_data.label, + format!("{:.2?}", query_data.self_time), + format!("{:.3}", percent), + format!("{}", query_data.invocation_count), + format!("{}", query_data.number_of_cache_hits), + format!("{:.2?}", query_data.blocked_time), + format!("{:.2?}", query_data.incremental_load_time), + ]); + } } table.printstd(); println!("Total cpu time: {:?}", results.total_time); + println!("Showing results for % total time greater than {:?}%", percent_above); Ok(()) } From 5892ee515b8237d3a8054b4cef0093487e98a610 Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Sat, 27 Apr 2019 17:16:47 -0400 Subject: [PATCH 2/5] (docs): adds CHANGELOG --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..4eb2526 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +# Changelog + +## Unreleased +### Added +- New CLI argument `percent-above` for `summarize` crate ([GH-32]) + +## [0.2.1] - 2019-04-12 + +## [0.2.0] - 2019-04-10 + + +[0.2.1]: https://github.com/rust-lang/measureme/releases/tag/0.2.1 +[0.2.0]: https://github.com/rust-lang/measureme/releases/tag/0.2.0 + +[GH-32]: https://github.com/rust-lang/measureme/issues/32 \ No newline at end of file From ce841d9d5c7ead7c0ffd3fc71a8004774a984104 Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Sun, 28 Apr 2019 19:16:04 -0400 Subject: [PATCH 3/5] (docs): updates CHANGELOG --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4eb2526..9633884 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased ### Added -- New CLI argument `percent-above` for `summarize` crate ([GH-32]) +- `summarize`: New CLI argument `percent-above` for `summarize` crate ([GH-32]) ## [0.2.1] - 2019-04-12 @@ -12,4 +12,4 @@ [0.2.1]: https://github.com/rust-lang/measureme/releases/tag/0.2.1 [0.2.0]: https://github.com/rust-lang/measureme/releases/tag/0.2.0 -[GH-32]: https://github.com/rust-lang/measureme/issues/32 \ No newline at end of file +[GH-32]: https://github.com/rust-lang/measureme/issues/32 From a7aecf7c00ef18274081ebf0f35160c8f2017a78 Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Sun, 28 Apr 2019 19:17:19 -0400 Subject: [PATCH 4/5] summarize (feature): updates percent-above per review in https://github.com/rust-lang/measureme/pull/36/files --- summarize/src/main.rs | 50 +++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/summarize/src/main.rs b/summarize/src/main.rs index 03cce7a..03ba2ff 100644 --- a/summarize/src/main.rs +++ b/summarize/src/main.rs @@ -19,8 +19,8 @@ struct Opt { #[structopt(long = "json")] json: bool, - /// Filters the output rows where "% of total time" > "percent-above" - #[structopt(short = "pa", long = "percent-above", default_value = "1.0")] + /// Filter the output to items whose self-time is greater than this value + #[structopt(short = "pa", long = "percent-above", default_value = "0.0")] percent_above: f64, } @@ -38,14 +38,13 @@ fn main() -> Result<(), Box> { return Ok(()); } + let percent_above = opt.percent_above; //cannot be greater than 100% or less than 0% - let percent_above = if opt.percent_above > 100.0 { - 100.0 - } else if opt.percent_above < 0.0 { - 0.0 - } else { - opt.percent_above - }; + if percent_above > 100.0 { + return Err("Percentage of total time cannot be more than 100.0".into()) + } else if percent_above < 0.0 { + return Err("Percentage of total time cannot be less than 0.0".into()) + } //order the results by descending self time results.query_data.sort_by(|l, r| r.self_time.cmp(&l.self_time)); @@ -63,28 +62,33 @@ fn main() -> Result<(), Box> { ]); let total_time = results.total_time.as_nanos() as f64; + let mut percent_total_time: f64 = 0.0; for query_data in results.query_data { - let percent = (query_data.self_time.as_nanos() as f64) / total_time * 100.0; - - if percent > percent_above { - table.add_row(row![ - query_data.label, - format!("{:.2?}", query_data.self_time), - format!("{:.3}", percent), - format!("{}", query_data.invocation_count), - format!("{}", query_data.number_of_cache_hits), - format!("{:.2?}", query_data.blocked_time), - format!("{:.2?}", query_data.incremental_load_time), - ]); - } + let curr_percent = (query_data.self_time.as_nanos() as f64) / total_time * 100.0; + if curr_percent < percent_above { break } //no need to run entire loop if filtering by % time + + percent_total_time = percent_total_time + curr_percent; + + table.add_row(row![ + query_data.label, + format!("{:.2?}", query_data.self_time), + format!("{:.3}", curr_percent), + format!("{}", query_data.invocation_count), + format!("{}", query_data.number_of_cache_hits), + format!("{:.2?}", query_data.blocked_time), + format!("{:.2?}", query_data.incremental_load_time), + ]); } table.printstd(); println!("Total cpu time: {:?}", results.total_time); - println!("Showing results for % total time greater than {:?}%", percent_above); + + if percent_above != 0.0 { + println!("Filtered results account for {:.3}% of total time.", percent_total_time); + } Ok(()) } From ceb18d82e88ad07170df38bf3aa750f854374095 Mon Sep 17 00:00:00 2001 From: Amanjeev Sethi Date: Mon, 29 Apr 2019 19:37:40 -0400 Subject: [PATCH 5/5] summarize (feature): better exit errors - updates percent-above per review in https://github.com/rust-lang/measureme/pull/36/files --- summarize/src/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/summarize/src/main.rs b/summarize/src/main.rs index 03ba2ff..2712939 100644 --- a/summarize/src/main.rs +++ b/summarize/src/main.rs @@ -41,9 +41,11 @@ fn main() -> Result<(), Box> { let percent_above = opt.percent_above; //cannot be greater than 100% or less than 0% if percent_above > 100.0 { - return Err("Percentage of total time cannot be more than 100.0".into()) + eprintln!("Percentage of total time cannot be more than 100.0"); + std::process::exit(1); } else if percent_above < 0.0 { - return Err("Percentage of total time cannot be less than 0.0".into()) + eprintln!("Percentage of total time cannot be less than 0.0"); + std::process::exit(1); } //order the results by descending self time