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 {
93
93
$(
94
94
let ( hits, total) = self . query_counts. $name;
95
95
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
+
96
104
json. push_str( & format!(
97
105
"{{ \" category\" : {}, \" time_ms\" : {},
98
- \" query_count\" : {}, \" query_hits\" : {} }}" ,
106
+ \" query_count\" : {}, \" query_hits\" : {} }}, " ,
99
107
stringify!( $name) ,
100
108
self . times. $name / 1_000_000 ,
101
109
total,
102
- format!( "{:.2}" , ( ( ( hits as f32 ) / ( total as f32 ) ) * 100.0 ) )
110
+ format!( "{:.2}" , hit_percent )
103
111
) ) ;
104
112
) *
105
113
114
+ //remove the trailing ',' character
115
+ json. pop( ) ;
116
+
106
117
json. push( ']' ) ;
107
118
108
119
json
You can’t perform that action at this time.
0 commit comments