Skip to content

Commit e0d7945

Browse files
authored
Merge pull request #36 from amanjeev/amanjeev/optional-greater-than
summarize (feature): adds percent-above cli argument
2 parents 26e6ddb + ceb18d8 commit e0d7945

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Changelog
2+
3+
## Unreleased
4+
### Added
5+
- `summarize`: New CLI argument `percent-above` for `summarize` crate ([GH-32])
6+
7+
## [0.2.1] - 2019-04-12
8+
9+
## [0.2.0] - 2019-04-10
10+
11+
12+
[0.2.1]: https://github.com/rust-lang/measureme/releases/tag/0.2.1
13+
[0.2.0]: https://github.com/rust-lang/measureme/releases/tag/0.2.0
14+
15+
[GH-32]: https://github.com/rust-lang/measureme/issues/32

summarize/src/main.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ struct Opt {
1818
/// Writes the analysis to a json file next to <file_prefix> instead of stdout
1919
#[structopt(long = "json")]
2020
json: bool,
21+
22+
/// Filter the output to items whose self-time is greater than this value
23+
#[structopt(short = "pa", long = "percent-above", default_value = "0.0")]
24+
percent_above: f64,
2125
}
2226

2327
fn main() -> Result<(), Box<std::error::Error>> {
@@ -34,6 +38,16 @@ fn main() -> Result<(), Box<std::error::Error>> {
3438
return Ok(());
3539
}
3640

41+
let percent_above = opt.percent_above;
42+
//cannot be greater than 100% or less than 0%
43+
if percent_above > 100.0 {
44+
eprintln!("Percentage of total time cannot be more than 100.0");
45+
std::process::exit(1);
46+
} else if percent_above < 0.0 {
47+
eprintln!("Percentage of total time cannot be less than 0.0");
48+
std::process::exit(1);
49+
}
50+
3751
//order the results by descending self time
3852
results.query_data.sort_by(|l, r| r.self_time.cmp(&l.self_time));
3953

@@ -50,12 +64,19 @@ fn main() -> Result<(), Box<std::error::Error>> {
5064
]);
5165

5266
let total_time = results.total_time.as_nanos() as f64;
67+
let mut percent_total_time: f64 = 0.0;
5368

5469
for query_data in results.query_data {
70+
71+
let curr_percent = (query_data.self_time.as_nanos() as f64) / total_time * 100.0;
72+
if curr_percent < percent_above { break } //no need to run entire loop if filtering by % time
73+
74+
percent_total_time = percent_total_time + curr_percent;
75+
5576
table.add_row(row![
5677
query_data.label,
5778
format!("{:.2?}", query_data.self_time),
58-
format!("{:.3}", ((query_data.self_time.as_nanos() as f64) / total_time) * 100.0),
79+
format!("{:.3}", curr_percent),
5980
format!("{}", query_data.invocation_count),
6081
format!("{}", query_data.number_of_cache_hits),
6182
format!("{:.2?}", query_data.blocked_time),
@@ -67,5 +88,9 @@ fn main() -> Result<(), Box<std::error::Error>> {
6788

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

91+
if percent_above != 0.0 {
92+
println!("Filtered results account for {:.3}% of total time.", percent_total_time);
93+
}
94+
7095
Ok(())
7196
}

0 commit comments

Comments
 (0)