Skip to content
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

summarize (feature): adds percent-above cli argument #36

Merged
merged 5 commits into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

## Unreleased
### Added
- `summarize`: 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
25 changes: 24 additions & 1 deletion summarize/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ struct Opt {
/// Writes the analysis to a json file next to <file_prefix> instead of stdout
#[structopt(long = "json")]
json: bool,

/// 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,
}

fn main() -> Result<(), Box<std::error::Error>> {
Expand All @@ -34,6 +38,14 @@ fn main() -> Result<(), Box<std::error::Error>> {
return Ok(());
}

let percent_above = opt.percent_above;
//cannot be greater than 100% or less than 0%
amanjeev marked this conversation as resolved.
Show resolved Hide resolved
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));

Expand All @@ -50,12 +62,19 @@ fn main() -> Result<(), Box<std::error::Error>> {
]);

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 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}", ((query_data.self_time.as_nanos() as f64) / total_time) * 100.0),
format!("{:.3}", curr_percent),
format!("{}", query_data.invocation_count),
format!("{}", query_data.number_of_cache_hits),
format!("{:.2?}", query_data.blocked_time),
Expand All @@ -67,5 +86,9 @@ fn main() -> Result<(), Box<std::error::Error>> {

println!("Total cpu time: {:?}", results.total_time);

if percent_above != 0.0 {
println!("Filtered results account for {:.3}% of total time.", percent_total_time);
}

Ok(())
}