Add parsing of --json=timings

This commit is contained in:
Jakub Beránek
2025-06-06 16:10:30 +02:00
parent 68ac5abb06
commit 7ad5248c95
2 changed files with 17 additions and 0 deletions

View File

@@ -1366,6 +1366,7 @@ impl Default for Options {
real_rust_source_base_dir: None, real_rust_source_base_dir: None,
edition: DEFAULT_EDITION, edition: DEFAULT_EDITION,
json_artifact_notifications: false, json_artifact_notifications: false,
json_section_timings: false,
json_unused_externs: JsonUnusedExterns::No, json_unused_externs: JsonUnusedExterns::No,
json_future_incompat: false, json_future_incompat: false,
pretty: None, pretty: None,
@@ -1880,6 +1881,9 @@ pub struct JsonConfig {
pub json_rendered: HumanReadableErrorType, pub json_rendered: HumanReadableErrorType,
pub json_color: ColorConfig, pub json_color: ColorConfig,
json_artifact_notifications: bool, json_artifact_notifications: bool,
/// Output start and end timestamps of several high-level compilation sections
/// (frontend, backend, linker).
json_section_timings: bool,
pub json_unused_externs: JsonUnusedExterns, pub json_unused_externs: JsonUnusedExterns,
json_future_incompat: bool, json_future_incompat: bool,
} }
@@ -1921,6 +1925,7 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
let mut json_artifact_notifications = false; let mut json_artifact_notifications = false;
let mut json_unused_externs = JsonUnusedExterns::No; let mut json_unused_externs = JsonUnusedExterns::No;
let mut json_future_incompat = false; let mut json_future_incompat = false;
let mut json_section_timings = false;
for option in matches.opt_strs("json") { for option in matches.opt_strs("json") {
// For now conservatively forbid `--color` with `--json` since `--json` // For now conservatively forbid `--color` with `--json` since `--json`
// won't actually be emitting any colors and anything colorized is // 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
} }
"diagnostic-rendered-ansi" => json_color = ColorConfig::Always, "diagnostic-rendered-ansi" => json_color = ColorConfig::Always,
"artifacts" => json_artifact_notifications = true, "artifacts" => json_artifact_notifications = true,
"timings" => json_section_timings = true,
"unused-externs" => json_unused_externs = JsonUnusedExterns::Loud, "unused-externs" => json_unused_externs = JsonUnusedExterns::Loud,
"unused-externs-silent" => json_unused_externs = JsonUnusedExterns::Silent, "unused-externs-silent" => json_unused_externs = JsonUnusedExterns::Silent,
"future-incompat" => json_future_incompat = true, "future-incompat" => json_future_incompat = true,
@@ -1949,6 +1955,7 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
json_rendered, json_rendered,
json_color, json_color,
json_artifact_notifications, json_artifact_notifications,
json_section_timings,
json_unused_externs, json_unused_externs,
json_future_incompat, json_future_incompat,
} }
@@ -2476,6 +2483,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
json_rendered, json_rendered,
json_color, json_color,
json_artifact_notifications, json_artifact_notifications,
json_section_timings,
json_unused_externs, json_unused_externs,
json_future_incompat, json_future_incompat,
} = parse_json(early_dcx, matches); } = parse_json(early_dcx, matches);
@@ -2497,6 +2505,10 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
let mut unstable_opts = UnstableOptions::build(early_dcx, matches, &mut target_modifiers); let mut unstable_opts = UnstableOptions::build(early_dcx, matches, &mut target_modifiers);
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(early_dcx, matches); let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(early_dcx, matches);
if !unstable_opts.unstable_options && json_section_timings {
early_dcx.early_fatal("--json=timings is unstable and requires using `-Zunstable-options`");
}
check_error_format_stability(early_dcx, &unstable_opts, error_format); check_error_format_stability(early_dcx, &unstable_opts, error_format);
let output_types = parse_output_types(early_dcx, &unstable_opts, matches); 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
real_rust_source_base_dir, real_rust_source_base_dir,
edition, edition,
json_artifact_notifications, json_artifact_notifications,
json_section_timings,
json_unused_externs, json_unused_externs,
json_future_incompat, json_future_incompat,
pretty, pretty,

View File

@@ -410,6 +410,10 @@ top_level_options!(
/// by the compiler. /// by the compiler.
json_artifact_notifications: bool [TRACKED], json_artifact_notifications: bool [TRACKED],
/// `true` if we're emitting JSON timings with the start and end of
/// high-level compilation sections
json_section_timings: bool [UNTRACKED],
/// `true` if we're emitting a JSON blob containing the unused externs /// `true` if we're emitting a JSON blob containing the unused externs
json_unused_externs: JsonUnusedExterns [UNTRACKED], json_unused_externs: JsonUnusedExterns [UNTRACKED],