Skip to content

Commit fb33fa4

Browse files
authored
Rollup merge of rust-lang#56091 - wesleywiser:fix_self_profiler_json, r=petrochenkov
Fix json output in the self-profiler Fix missing ',' array element separators and convert NaN's to 0. cc @Mark-Simulacrum
2 parents 1b707f7 + c7dc868 commit fb33fa4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/librustc/util/profiling.rs

+13-2
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)