Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub struct BuildConfig {
pub export_dir: Option<PathBuf>,
/// `true` to output a future incompatibility report at the end of the build
pub future_incompat_report: bool,
/// Which kinds of build timings to output (empty if none).
pub timing_outputs: Vec<TimingOutput>,
/// Output timing report at the end of the build
pub timing_report: bool,
/// Output SBOM precursor files.
pub sbom: bool,
/// Build compile time dependencies only, e.g., build scripts and proc macros
Expand Down Expand Up @@ -127,7 +127,7 @@ impl BuildConfig {
rustfix_diagnostic_server: Rc::new(RefCell::new(None)),
export_dir: None,
future_incompat_report: false,
timing_outputs: Vec::new(),
timing_report: false,
sbom,
compile_time_deps_only: false,
})
Expand Down Expand Up @@ -350,12 +350,3 @@ impl UserIntent {
)
}
}

/// Kinds of build timings we can output.
#[derive(Clone, Copy, PartialEq, Debug, Eq, Hash, PartialOrd, Ord)]
pub enum TimingOutput {
/// Human-readable HTML report
Html,
/// Machine-readable JSON (unstable)
Json,
}
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/build_runner/mod.rs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it require an FCP?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to get a vibe check in case there is interest in build analysis having X amount of functionality before it can replace --timings=json

Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
// Generally cargo check does not need to take the artifact-dir lock but there is
// one exception: If check has `--timings` we still need to lock artifact-dir since
// we will output the report files.
!self.bcx.build_config.timing_outputs.is_empty()
self.bcx.build_config.timing_report
}
UserIntent::Build
| UserIntent::Test
Expand Down
6 changes: 2 additions & 4 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ use regex::Regex;
use tracing::{debug, instrument, trace};

pub use self::build_config::UserIntent;
pub use self::build_config::{BuildConfig, CompileMode, MessageFormat, TimingOutput};
pub use self::build_config::{BuildConfig, CompileMode, MessageFormat};
pub use self::build_context::BuildContext;
pub use self::build_context::FileFlavor;
pub use self::build_context::FileType;
Expand Down Expand Up @@ -112,7 +112,6 @@ use cargo_util_schemas::manifest::TomlDebugInfo;
use cargo_util_schemas::manifest::TomlTrimPaths;
use cargo_util_schemas::manifest::TomlTrimPathsValue;
use rustfix::diagnostics::Applicability;
pub(crate) use timings::CompilationSection;

const RUSTDOC_CRATE_VERSION_FLAG: &str = "--crate-version";

Expand Down Expand Up @@ -1131,8 +1130,7 @@ fn add_allow_features(build_runner: &BuildRunner<'_, '_>, cmd: &mut ProcessBuild
/// [`--error-format`]: https://doc.rust-lang.org/nightly/rustc/command-line-arguments.html#--error-format-control-how-errors-are-produced
fn add_error_format_and_color(build_runner: &BuildRunner<'_, '_>, cmd: &mut ProcessBuilder) {
let enable_timings = build_runner.bcx.gctx.cli_unstable().section_timings
&& (!build_runner.bcx.build_config.timing_outputs.is_empty()
|| build_runner.bcx.logger.is_some());
&& (build_runner.bcx.build_config.timing_report || build_runner.bcx.logger.is_some());
if enable_timings {
cmd.arg("-Zunstable-options");
}
Expand Down
27 changes: 5 additions & 22 deletions src/cargo/core/compiler/timings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ pub mod report;

use super::{CompileMode, Unit};
use crate::core::PackageId;
use crate::core::compiler::BuildContext;
use crate::core::compiler::BuildRunner;
use crate::core::compiler::job_queue::JobId;
use crate::core::compiler::{BuildContext, BuildRunner, TimingOutput};
use crate::util::cpu::State;
use crate::util::log_message::LogMessage;
use crate::util::machine_message::{self, Message};
use crate::util::style;
use crate::util::{CargoResult, GlobalContext};

Expand All @@ -35,8 +35,6 @@ pub struct Timings<'gctx> {
enabled: bool,
/// If true, saves an HTML report to disk.
report_html: bool,
/// If true, emits JSON information with timing information.
report_json: bool,
/// When Cargo started.
start: Instant,
/// A rendered string of when compilation started.
Expand Down Expand Up @@ -120,17 +118,14 @@ pub struct UnitData {
impl<'gctx> Timings<'gctx> {
pub fn new(bcx: &BuildContext<'_, 'gctx>, root_units: &[Unit]) -> Timings<'gctx> {
let start = bcx.gctx.creation_time();
let has_report = |what| bcx.build_config.timing_outputs.contains(&what);
let report_html = has_report(TimingOutput::Html);
let report_json = has_report(TimingOutput::Json);
let enabled = report_html | report_json | bcx.logger.is_some();
let report_html = bcx.build_config.timing_report;
let enabled = report_html | bcx.logger.is_some();

if !enabled {
return Timings {
gctx: bcx.gctx,
enabled,
report_html,
report_json,
start,
start_str: String::new(),
root_targets: Vec::new(),
Expand Down Expand Up @@ -175,7 +170,6 @@ impl<'gctx> Timings<'gctx> {
gctx: bcx.gctx,
enabled,
report_html,
report_json,
start,
start_str,
root_targets,
Expand Down Expand Up @@ -286,18 +280,7 @@ impl<'gctx> Timings<'gctx> {
unit_time
.unblocked_units
.extend(unblocked.iter().cloned().cloned());
if self.report_json {
let msg = machine_message::TimingInfo {
package_id: unit_time.unit.pkg.package_id().to_spec(),
target: &unit_time.unit.target,
mode: unit_time.unit.mode,
duration: unit_time.duration,
rmeta_time: unit_time.rmeta_time,
sections: unit_time.sections.clone().into_iter().collect(),
}
.to_json_string();
crate::drop_println!(self.gctx, "{}", msg);
}

if let Some(logger) = build_runner.bcx.logger {
let unblocked = unblocked.iter().map(|u| self.unit_to_index[u]).collect();
logger.log(LogMessage::UnitFinished {
Expand Down
36 changes: 4 additions & 32 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::CargoResult;
use crate::core::Dependency;
use crate::core::compiler::{
BuildConfig, CompileKind, MessageFormat, RustcTargetData, TimingOutput,
};
use crate::core::compiler::{BuildConfig, CompileKind, MessageFormat, RustcTargetData};
use crate::core::resolver::{CliFeatures, ForceAllTargets, HasDevUnits};
use crate::core::{Edition, Package, TargetKind, Workspace, profiles::Profiles, shell};
use crate::ops::lockfile::LOCKFILE_NAME;
Expand Down Expand Up @@ -516,12 +514,10 @@ pub trait CommandExt: Sized {

fn arg_timings(self) -> Self {
self._arg(
optional_opt(
flag(
"timings",
"Timing output formats (unstable) (comma separated): html, json",
"Output a build timing report at the end of the build",
)
.value_name("FMTS")
.require_equals(true)
.help_heading(heading::COMPILATION_OPTIONS),
)
}
Expand Down Expand Up @@ -845,31 +841,7 @@ Run `{cmd}` to see possible targets."
build_config.unit_graph = self.flag("unit-graph");
build_config.future_incompat_report = self.flag("future-incompat-report");
build_config.compile_time_deps_only = self.flag("compile-time-deps");

if self._contains("timings") {
for timing_output in self._values_of("timings") {
for timing_output in timing_output.split(',') {
let timing_output = timing_output.to_ascii_lowercase();
let timing_output = match timing_output.as_str() {
"html" => {
gctx.cli_unstable()
.fail_if_stable_opt("--timings=html", 7405)?;
TimingOutput::Html
}
"json" => {
gctx.cli_unstable()
.fail_if_stable_opt("--timings=json", 7405)?;
TimingOutput::Json
}
s => bail!("invalid timings output specifier: `{}`", s),
};
build_config.timing_outputs.push(timing_output);
}
}
if build_config.timing_outputs.is_empty() {
build_config.timing_outputs.push(TimingOutput::Html);
}
}
build_config.timing_report = self.flag("timings");

if build_config.unit_graph {
gctx.cli_unstable()
Expand Down
19 changes: 0 additions & 19 deletions src/cargo/util/machine_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use serde::ser;
use serde_json::value::RawValue;

use crate::core::Target;
use crate::core::compiler::{CompilationSection, CompileMode};

pub trait Message: ser::Serialize {
fn reason(&self) -> &str;
Expand Down Expand Up @@ -94,24 +93,6 @@ impl<'a> Message for BuildScript<'a> {
}
}

#[derive(Serialize)]
pub struct TimingInfo<'a> {
pub package_id: PackageIdSpec,
pub target: &'a Target,
pub mode: CompileMode,
pub duration: f64,
#[serde(skip_serializing_if = "Option::is_none")]
pub rmeta_time: Option<f64>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub sections: Vec<(String, CompilationSection)>,
}

impl<'a> Message for TimingInfo<'a> {
fn reason(&self) -> &str {
"timing-info"
}
}

#[derive(Serialize)]
pub struct BuildFinished {
pub success: bool,
Expand Down
25 changes: 8 additions & 17 deletions src/doc/man/generated_txt/cargo-bench.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,24 +253,15 @@ OPTIONS
<https://doc.rust-lang.org/cargo/reference/profiles.html> for more
details on profiles.

--timings=fmts
--timings
Output information how long each compilation takes, and track
concurrency information over time. Accepts an optional
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
-Zunstable-options. Valid output formats:

o html (unstable, requires -Zunstable-options): Write a
human-readable file cargo-timing.html to the target/cargo-timings
directory with a report of the compilation. Also write a report
to the same directory with a timestamp in the filename if you
want to look at older runs. HTML output is suitable for human
consumption only, and does not provide machine-readable timing
data.

o json (unstable, requires -Zunstable-options): Emit
machine-readable JSON information about timing information.
concurrency information over time.

A file cargo-timing.html will be written to the target/cargo-timings
directory at the end of the build. An additional report with a
timestamp in its filename is also written if you want to look at a
previous run. These reports are suitable for human consumption only,
and do not provide machine-readable timing data.

Output Options
--target-dir directory
Expand Down
25 changes: 8 additions & 17 deletions src/doc/man/generated_txt/cargo-build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,15 @@ OPTIONS
<https://doc.rust-lang.org/cargo/reference/profiles.html> for more
details on profiles.

--timings=fmts
--timings
Output information how long each compilation takes, and track
concurrency information over time. Accepts an optional
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
-Zunstable-options. Valid output formats:

o html (unstable, requires -Zunstable-options): Write a
human-readable file cargo-timing.html to the target/cargo-timings
directory with a report of the compilation. Also write a report
to the same directory with a timestamp in the filename if you
want to look at older runs. HTML output is suitable for human
consumption only, and does not provide machine-readable timing
data.

o json (unstable, requires -Zunstable-options): Emit
machine-readable JSON information about timing information.
concurrency information over time.

A file cargo-timing.html will be written to the target/cargo-timings
directory at the end of the build. An additional report with a
timestamp in its filename is also written if you want to look at a
previous run. These reports are suitable for human consumption only,
and do not provide machine-readable timing data.

Output Options
--target-dir directory
Expand Down
25 changes: 8 additions & 17 deletions src/doc/man/generated_txt/cargo-check.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,15 @@ OPTIONS
<https://doc.rust-lang.org/cargo/reference/profiles.html> for more
details on profiles.

--timings=fmts
--timings
Output information how long each compilation takes, and track
concurrency information over time. Accepts an optional
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
-Zunstable-options. Valid output formats:

o html (unstable, requires -Zunstable-options): Write a
human-readable file cargo-timing.html to the target/cargo-timings
directory with a report of the compilation. Also write a report
to the same directory with a timestamp in the filename if you
want to look at older runs. HTML output is suitable for human
consumption only, and does not provide machine-readable timing
data.

o json (unstable, requires -Zunstable-options): Emit
machine-readable JSON information about timing information.
concurrency information over time.

A file cargo-timing.html will be written to the target/cargo-timings
directory at the end of the build. An additional report with a
timestamp in its filename is also written if you want to look at a
previous run. These reports are suitable for human consumption only,
and do not provide machine-readable timing data.

Output Options
--target-dir directory
Expand Down
25 changes: 8 additions & 17 deletions src/doc/man/generated_txt/cargo-doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,15 @@ OPTIONS
<https://doc.rust-lang.org/cargo/reference/profiles.html> for more
details on profiles.

--timings=fmts
--timings
Output information how long each compilation takes, and track
concurrency information over time. Accepts an optional
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
-Zunstable-options. Valid output formats:

o html (unstable, requires -Zunstable-options): Write a
human-readable file cargo-timing.html to the target/cargo-timings
directory with a report of the compilation. Also write a report
to the same directory with a timestamp in the filename if you
want to look at older runs. HTML output is suitable for human
consumption only, and does not provide machine-readable timing
data.

o json (unstable, requires -Zunstable-options): Emit
machine-readable JSON information about timing information.
concurrency information over time.

A file cargo-timing.html will be written to the target/cargo-timings
directory at the end of the build. An additional report with a
timestamp in its filename is also written if you want to look at a
previous run. These reports are suitable for human consumption only,
and do not provide machine-readable timing data.

Output Options
--target-dir directory
Expand Down
25 changes: 8 additions & 17 deletions src/doc/man/generated_txt/cargo-fix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -252,24 +252,15 @@ OPTIONS
<https://doc.rust-lang.org/cargo/reference/profiles.html> for more
details on profiles.

--timings=fmts
--timings
Output information how long each compilation takes, and track
concurrency information over time. Accepts an optional
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
-Zunstable-options. Valid output formats:

o html (unstable, requires -Zunstable-options): Write a
human-readable file cargo-timing.html to the target/cargo-timings
directory with a report of the compilation. Also write a report
to the same directory with a timestamp in the filename if you
want to look at older runs. HTML output is suitable for human
consumption only, and does not provide machine-readable timing
data.

o json (unstable, requires -Zunstable-options): Emit
machine-readable JSON information about timing information.
concurrency information over time.

A file cargo-timing.html will be written to the target/cargo-timings
directory at the end of the build. An additional report with a
timestamp in its filename is also written if you want to look at a
previous run. These reports are suitable for human consumption only,
and do not provide machine-readable timing data.

Output Options
--target-dir directory
Expand Down
Loading