]> git.lizzy.rs Git - rust.git/commitdiff
First pass at json output
authorWesley Wiser <wwiser@gmail.com>
Wed, 6 Jun 2018 03:05:30 +0000 (23:05 -0400)
committerWesley Wiser <wwiser@gmail.com>
Thu, 2 Aug 2018 22:57:24 +0000 (18:57 -0400)
src/librustc/session/config.rs
src/librustc/session/mod.rs
src/librustc/util/profiling.rs
src/librustc_driver/driver.rs

index cc29bad9cb532be52abb5d1fe339ebd3d5964750..dda4a2d2418d7bc09784b39907b747c08b11f091 100644 (file)
@@ -1369,6 +1369,8 @@ fn parse_cross_lang_lto(slot: &mut CrossLangLto, v: Option<&str>) -> bool {
         "inject the given attribute in the crate"),
     self_profile: bool = (false, parse_bool, [UNTRACKED],
           "run the self profiler"),
+    profile_json: bool = (false, parse_bool, [UNTRACKED],
+          "output a json file with profiler results"),
 }
 
 pub fn default_lib_output() -> CrateType {
index a321728f74989332053d28607a04758166dd5dbe..8bb9f0b92679cb28776d2e2257b633c43f17d7df 100644 (file)
@@ -839,6 +839,11 @@ pub fn print_profiler_results(&self) {
         profiler.print_results(&self.opts);
     }
 
+    pub fn save_json_results(&self) {
+        let profiler = self.self_profiling.borrow();
+        profiler.save_results();
+    }
+
     pub fn print_perf_stats(&self) {
         println!(
             "Total time spent computing symbol hashes:      {}",
index ef4e233260470753646e32f98b610c857d92599e..73604d2a4371a89617b7c03247f022f1a842bb47 100644 (file)
@@ -10,6 +10,7 @@
 
 use session::config::Options;
 
+use std::fs;
 use std::io::{self, StdoutLock, Write};
 use std::time::Instant;
 
@@ -119,6 +120,46 @@ macro_rules! p {
         p!("Linking", linking);
         p!("Other", other);
     }
+
+    fn json(&self) -> String {
+        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)
+    }
 }
 
 pub struct SelfProfiler {
@@ -235,6 +276,10 @@ pub fn print_results(&mut self, opts: &Options) {
         writeln!(lock, "Incremental: {}", incremental).unwrap();
     }
 
+    pub fn save_results(&self) {
+        fs::write("self_profiler_results.json", self.data.json()).unwrap();
+    }
+
     pub fn record_activity<'a>(&'a mut self, category: ProfileCategory) -> ProfilerActivity<'a> {
         self.start_activity(category);
 
index d862741cda54f992ad2a99c63f527ffe1d2830a7..f178f847aa51e21858f17929d60107f4b756405f 100644 (file)
@@ -355,6 +355,10 @@ macro_rules! controller_entry_point {
 
     if sess.opts.debugging_opts.self_profile {
         sess.print_profiler_results();
+
+        if sess.opts.debugging_opts.profile_json {
+            sess.save_json_results();
+        }
     }
 
     controller_entry_point!(