File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -93,16 +93,27 @@ macro_rules! define_categories {
9393 $(
9494 let ( hits, total) = self . query_counts. $name;
9595
96+ //normalize hits to 0%
97+ let hit_percent =
98+ if total > 0 {
99+ ( ( hits as f32 ) / ( total as f32 ) ) * 100.0
100+ } else {
101+ 0.0
102+ } ;
103+
96104 json. push_str( & format!(
97105 "{{ \" category\" : {}, \" time_ms\" : {},
98- \" query_count\" : {}, \" query_hits\" : {} }}" ,
106+ \" query_count\" : {}, \" query_hits\" : {} }}, " ,
99107 stringify!( $name) ,
100108 self . times. $name / 1_000_000 ,
101109 total,
102- format!( "{:.2}" , ( ( ( hits as f32 ) / ( total as f32 ) ) * 100.0 ) )
110+ format!( "{:.2}" , hit_percent )
103111 ) ) ;
104112 ) *
105113
114+ //remove the trailing ',' character
115+ json. pop( ) ;
116+
106117 json. push( ']' ) ;
107118
108119 json
You can’t perform that action at this time.
0 commit comments