Skip to content

Commit 7ad5248

Browse files
committed
Add parsing of --json=timings
1 parent 68ac5ab commit 7ad5248

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,7 @@ impl Default for Options {
13661366
real_rust_source_base_dir: None,
13671367
edition: DEFAULT_EDITION,
13681368
json_artifact_notifications: false,
1369+
json_section_timings: false,
13691370
json_unused_externs: JsonUnusedExterns::No,
13701371
json_future_incompat: false,
13711372
pretty: None,
@@ -1880,6 +1881,9 @@ pub struct JsonConfig {
18801881
pub json_rendered: HumanReadableErrorType,
18811882
pub json_color: ColorConfig,
18821883
json_artifact_notifications: bool,
1884+
/// Output start and end timestamps of several high-level compilation sections
1885+
/// (frontend, backend, linker).
1886+
json_section_timings: bool,
18831887
pub json_unused_externs: JsonUnusedExterns,
18841888
json_future_incompat: bool,
18851889
}
@@ -1921,6 +1925,7 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
19211925
let mut json_artifact_notifications = false;
19221926
let mut json_unused_externs = JsonUnusedExterns::No;
19231927
let mut json_future_incompat = false;
1928+
let mut json_section_timings = false;
19241929
for option in matches.opt_strs("json") {
19251930
// For now conservatively forbid `--color` with `--json` since `--json`
19261931
// won't actually be emitting any colors and anything colorized is
@@ -1937,6 +1942,7 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
19371942
}
19381943
"diagnostic-rendered-ansi" => json_color = ColorConfig::Always,
19391944
"artifacts" => json_artifact_notifications = true,
1945+
"timings" => json_section_timings = true,
19401946
"unused-externs" => json_unused_externs = JsonUnusedExterns::Loud,
19411947
"unused-externs-silent" => json_unused_externs = JsonUnusedExterns::Silent,
19421948
"future-incompat" => json_future_incompat = true,
@@ -1949,6 +1955,7 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
19491955
json_rendered,
19501956
json_color,
19511957
json_artifact_notifications,
1958+
json_section_timings,
19521959
json_unused_externs,
19531960
json_future_incompat,
19541961
}
@@ -2476,6 +2483,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
24762483
json_rendered,
24772484
json_color,
24782485
json_artifact_notifications,
2486+
json_section_timings,
24792487
json_unused_externs,
24802488
json_future_incompat,
24812489
} = parse_json(early_dcx, matches);
@@ -2497,6 +2505,10 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
24972505
let mut unstable_opts = UnstableOptions::build(early_dcx, matches, &mut target_modifiers);
24982506
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(early_dcx, matches);
24992507

2508+
if !unstable_opts.unstable_options && json_section_timings {
2509+
early_dcx.early_fatal("--json=timings is unstable and requires using `-Zunstable-options`");
2510+
}
2511+
25002512
check_error_format_stability(early_dcx, &unstable_opts, error_format);
25012513

25022514
let output_types = parse_output_types(early_dcx, &unstable_opts, matches);
@@ -2774,6 +2786,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
27742786
real_rust_source_base_dir,
27752787
edition,
27762788
json_artifact_notifications,
2789+
json_section_timings,
27772790
json_unused_externs,
27782791
json_future_incompat,
27792792
pretty,

compiler/rustc_session/src/options.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ top_level_options!(
410410
/// by the compiler.
411411
json_artifact_notifications: bool [TRACKED],
412412

413+
/// `true` if we're emitting JSON timings with the start and end of
414+
/// high-level compilation sections
415+
json_section_timings: bool [UNTRACKED],
416+
413417
/// `true` if we're emitting a JSON blob containing the unused externs
414418
json_unused_externs: JsonUnusedExterns [UNTRACKED],
415419

0 commit comments

Comments
 (0)