Skip to content

Commit 4552607

Browse files
committed
Refactor json printing
1 parent 51cc594 commit 4552607

File tree

1 file changed

+21
-35
lines changed

1 file changed

+21
-35
lines changed

src/librustc/util/profiling.rs

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -122,43 +122,29 @@ impl CategoryData {
122122
}
123123

124124
fn json(&self) -> String {
125+
macro_rules! j {
126+
($category:tt, $rustic_name:ident) => {
127+
format!("{{ \"category\": {}, \"time_ms\": {} }}", stringify!($category), self.times.$rustic_name / 1_000_000)
128+
}
129+
}
130+
125131
format!("[
126-
{{
127-
\"category\": \"Parsing\",
128-
\"time_ms\": {}
129-
}},
130-
{{
131-
\"category\": \"Expansion\",
132-
\"time_ms\": {}
133-
}},
134-
{{
135-
\"category\": \"TypeChecking\",
136-
\"time_ms\": {}
137-
}},
138-
{{
139-
\"category\": \"BorrowChecking\",
140-
\"time_ms\": {}
141-
}},
142-
{{
143-
\"category\": \"Codegen\",
144-
\"time_ms\": {}
145-
}},
146-
{{
147-
\"category\": \"Linking\",
148-
\"time_ms\": {}
149-
}},
150-
{{
151-
\"category\": \"Other\",
152-
\"time_ms\": {}
153-
}}
132+
{},
133+
{},
134+
{},
135+
{},
136+
{},
137+
{},
138+
{}
154139
]",
155-
self.times.parsing / 1_000_000,
156-
self.times.expansion / 1_000_000,
157-
self.times.type_checking / 1_000_000,
158-
self.times.borrow_checking / 1_000_000,
159-
self.times.codegen / 1_000_000,
160-
self.times.linking / 1_000_000,
161-
self.times.other / 1_000_000)
140+
j!("Parsing", parsing),
141+
j!("Expansion", expansion),
142+
j!("TypeChecking", type_checking),
143+
j!("BorrowChecking", borrow_checking),
144+
j!("Codegen", codegen),
145+
j!("Linking", linking),
146+
j!("Other", other)
147+
)
162148
}
163149
}
164150

0 commit comments

Comments
 (0)