First pass at json output
This commit is contained in:
parent
e50dfe66f3
commit
51cc594e10
4 changed files with 56 additions and 0 deletions
|
@ -1369,6 +1369,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
|
||||||
"inject the given attribute in the crate"),
|
"inject the given attribute in the crate"),
|
||||||
self_profile: bool = (false, parse_bool, [UNTRACKED],
|
self_profile: bool = (false, parse_bool, [UNTRACKED],
|
||||||
"run the self profiler"),
|
"run the self profiler"),
|
||||||
|
profile_json: bool = (false, parse_bool, [UNTRACKED],
|
||||||
|
"output a json file with profiler results"),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_lib_output() -> CrateType {
|
pub fn default_lib_output() -> CrateType {
|
||||||
|
|
|
@ -839,6 +839,11 @@ impl Session {
|
||||||
profiler.print_results(&self.opts);
|
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) {
|
pub fn print_perf_stats(&self) {
|
||||||
println!(
|
println!(
|
||||||
"Total time spent computing symbol hashes: {}",
|
"Total time spent computing symbol hashes: {}",
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
use session::config::Options;
|
use session::config::Options;
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
use std::io::{self, StdoutLock, Write};
|
use std::io::{self, StdoutLock, Write};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
@ -119,6 +120,46 @@ impl CategoryData {
|
||||||
p!("Linking", linking);
|
p!("Linking", linking);
|
||||||
p!("Other", other);
|
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 {
|
pub struct SelfProfiler {
|
||||||
|
@ -235,6 +276,10 @@ impl SelfProfiler {
|
||||||
writeln!(lock, "Incremental: {}", incremental).unwrap();
|
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> {
|
pub fn record_activity<'a>(&'a mut self, category: ProfileCategory) -> ProfilerActivity<'a> {
|
||||||
self.start_activity(category);
|
self.start_activity(category);
|
||||||
|
|
||||||
|
|
|
@ -355,6 +355,10 @@ pub fn compile_input(
|
||||||
|
|
||||||
if sess.opts.debugging_opts.self_profile {
|
if sess.opts.debugging_opts.self_profile {
|
||||||
sess.print_profiler_results();
|
sess.print_profiler_results();
|
||||||
|
|
||||||
|
if sess.opts.debugging_opts.profile_json {
|
||||||
|
sess.save_json_results();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
controller_entry_point!(
|
controller_entry_point!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue