]> git.lizzy.rs Git - rust.git/commitdiff
Refactor json printing
authorWesley Wiser <wwiser@gmail.com>
Tue, 12 Jun 2018 03:41:11 +0000 (23:41 -0400)
committerWesley Wiser <wwiser@gmail.com>
Thu, 2 Aug 2018 22:57:24 +0000 (18:57 -0400)
src/librustc/util/profiling.rs

index 73604d2a4371a89617b7c03247f022f1a842bb47..b32122aad851b3e4eac8d0a819f04f2ef0db39be 100644 (file)
@@ -122,43 +122,29 @@ macro_rules! p {
     }
 
     fn json(&self) -> String {
+        macro_rules! j {
+            ($category:tt, $rustic_name:ident) => {
+                format!("{{ \"category\": {}, \"time_ms\": {} }}", stringify!($category), self.times.$rustic_name / 1_000_000)
+            }
+        }
+
         format!("[
-            {{
-                \"category\": \"Parsing\",
-                \"time_ms\": {}
-            }},
-            {{
-                \"category\": \"Expansion\",
-                \"time_ms\": {}
-            }},
-            {{
-                \"category\": \"TypeChecking\",
-                \"time_ms\": {}
-            }},
-            {{
-                \"category\": \"BorrowChecking\",
-                \"time_ms\": {}
-            }},
-            {{
-                \"category\": \"Codegen\",
-                \"time_ms\": {}
-            }},
-            {{
-                \"category\": \"Linking\",
-                \"time_ms\": {}
-            }},
-            {{
-                \"category\": \"Other\",
-                \"time_ms\": {}
-            }}
+            {},
+            {},
+            {},
+            {},
+            {},
+            {},
+            {}
         ]",
-        self.times.parsing / 1_000_000,
-        self.times.expansion / 1_000_000,
-        self.times.type_checking / 1_000_000,
-        self.times.borrow_checking / 1_000_000,
-        self.times.codegen / 1_000_000,
-        self.times.linking / 1_000_000,
-        self.times.other / 1_000_000)
+            j!("Parsing", parsing),
+            j!("Expansion", expansion),
+            j!("TypeChecking", type_checking),
+            j!("BorrowChecking", borrow_checking),
+            j!("Codegen", codegen),
+            j!("Linking", linking),
+            j!("Other", other)
+        )
     }
 }