Skip to content

Commit

Permalink
Fix json output in the self-profiler
Browse files Browse the repository at this point in the history
Fix missing ',' array element separators and convert NaN's to 0.
  • Loading branch information
wesleywiser committed Nov 20, 2018
1 parent 31fa301 commit c7dc868
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/librustc/util/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,27 @@ macro_rules! define_categories {
$(
let (hits, total) = self.query_counts.$name;

//normalize hits to 0%
let hit_percent =
if total > 0 {
((hits as f32) / (total as f32)) * 100.0
} else {
0.0
};

json.push_str(&format!(
"{{ \"category\": {}, \"time_ms\": {},
\"query_count\": {}, \"query_hits\": {} }}",
\"query_count\": {}, \"query_hits\": {} }},",
stringify!($name),
self.times.$name / 1_000_000,
total,
format!("{:.2}", (((hits as f32) / (total as f32)) * 100.0))
format!("{:.2}", hit_percent)
));
)*

//remove the trailing ',' character
json.pop();

json.push(']');

json
Expand Down

0 comments on commit c7dc868

Please sign in to comment.