@@ -18,6 +18,10 @@ struct Opt {
18
18
/// Writes the analysis to a json file next to <file_prefix> instead of stdout
19
19
#[ structopt( long = "json" ) ]
20
20
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 ,
21
25
}
22
26
23
27
fn main ( ) -> Result < ( ) , Box < std:: error:: Error > > {
@@ -34,6 +38,16 @@ fn main() -> Result<(), Box<std::error::Error>> {
34
38
return Ok ( ( ) ) ;
35
39
}
36
40
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
+
37
51
//order the results by descending self time
38
52
results. query_data . sort_by ( |l, r| r. self_time . cmp ( & l. self_time ) ) ;
39
53
@@ -50,12 +64,19 @@ fn main() -> Result<(), Box<std::error::Error>> {
50
64
] ) ;
51
65
52
66
let total_time = results. total_time . as_nanos ( ) as f64 ;
67
+ let mut percent_total_time: f64 = 0.0 ;
53
68
54
69
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
+
55
76
table. add_row ( row ! [
56
77
query_data. label,
57
78
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 ) ,
59
80
format!( "{}" , query_data. invocation_count) ,
60
81
format!( "{}" , query_data. number_of_cache_hits) ,
61
82
format!( "{:.2?}" , query_data. blocked_time) ,
@@ -67,5 +88,9 @@ fn main() -> Result<(), Box<std::error::Error>> {
67
88
68
89
println ! ( "Total cpu time: {:?}" , results. total_time) ;
69
90
91
+ if percent_above != 0.0 {
92
+ println ! ( "Filtered results account for {:.3}% of total time." , percent_total_time) ;
93
+ }
94
+
70
95
Ok ( ( ) )
71
96
}
0 commit comments