diff --git a/src/cargo/core/compiler/timings/mod.rs b/src/cargo/core/compiler/timings/mod.rs index bae60ee2ccc..109d2f76963 100644 --- a/src/cargo/core/compiler/timings/mod.rs +++ b/src/cargo/core/compiler/timings/mod.rs @@ -125,17 +125,17 @@ struct Concurrency { /// This is used by the HTML report's JavaScript to render the pipeline graph. #[derive(serde::Serialize)] struct UnitData { - i: usize, + i: u64, name: String, version: String, mode: String, target: String, + features: Vec, start: f64, duration: f64, - rmeta_time: Option, - unblocked_units: Vec, - unblocked_rmeta_units: Vec, - sections: Option>, + unblocked_units: Vec, + unblocked_rmeta_units: Vec, + sections: Option>, } impl<'gctx> Timings<'gctx> { @@ -472,6 +472,8 @@ impl<'gctx> Timings<'gctx> { .map(|kind| build_runner.bcx.target_data.short_name(kind)) .collect::>(); + let unit_data = report::to_unit_data(&self.unit_times, &self.unit_to_index); + let ctx = report::RenderContext { start: self.start, start_str: &self.start_str, @@ -479,7 +481,7 @@ impl<'gctx> Timings<'gctx> { profile: &self.profile, total_fresh: self.total_fresh, total_dirty: self.total_dirty, - unit_times: &self.unit_times, + unit_data, concurrency: &self.concurrency, cpu_usage: &self.cpu_usage, rustc_version, @@ -504,10 +506,6 @@ impl<'gctx> Timings<'gctx> { } impl UnitTime { - fn name_ver(&self) -> String { - format!("{} v{}", self.unit.pkg.name(), self.unit.pkg.version()) - } - fn start_section(&mut self, name: &str, now: f64) { if self .sections diff --git a/src/cargo/core/compiler/timings/report.rs b/src/cargo/core/compiler/timings/report.rs index 6faac2a6c43..1a0811e3472 100644 --- a/src/cargo/core/compiler/timings/report.rs +++ b/src/cargo/core/compiler/timings/report.rs @@ -1,5 +1,6 @@ //! Render HTML report from timing tracking data. +use std::borrow::Cow; use std::collections::HashMap; use std::io::Write; use std::time::Instant; @@ -7,29 +8,64 @@ use std::time::Instant; use itertools::Itertools as _; use crate::CargoResult; -use crate::core::compiler::CompilationSection; use crate::core::compiler::Unit; use super::Concurrency; use super::UnitData; use super::UnitTime; -const FRONTEND_SECTION_NAME: &str = "Frontend"; -const CODEGEN_SECTION_NAME: &str = "Codegen"; - /// Contains post-processed data of individual compilation sections. enum AggregatedSections { /// We know the names and durations of individual compilation sections - Sections(Vec<(String, SectionData)>), - /// We only know when .rmeta was generated, so we can distill frontend and codegen time. - OnlyMetadataTime { - frontend: SectionData, - codegen: SectionData, - }, + Sections(Vec<(SectionName, SectionData)>), /// We know only the total duration OnlyTotalDuration, } +/// Name of an individual compilation section. +#[derive(Clone, Hash, Eq, PartialEq)] +pub(super) enum SectionName { + Frontend, + Codegen, + Named(String), + Other, +} + +impl SectionName { + /// Lower case name. + fn name(&self) -> Cow<'static, str> { + match self { + SectionName::Frontend => "frontend".into(), + SectionName::Codegen => "codegen".into(), + SectionName::Named(n) => n.to_lowercase().into(), + SectionName::Other => "other".into(), + } + } + + fn capitalized_name(&self) -> String { + // Make the first "letter" uppercase. We could probably just assume ASCII here, but this + // should be Unicode compatible. + fn capitalize(s: &str) -> String { + let first_char = s + .chars() + .next() + .map(|c| c.to_uppercase().to_string()) + .unwrap_or_default(); + format!("{first_char}{}", s.chars().skip(1).collect::()) + } + capitalize(&self.name()) + } +} + +impl serde::ser::Serialize for SectionName { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + self.name().serialize(serializer) + } +} + /// Postprocessed section data that has both start and an end. #[derive(Copy, Clone, serde::Serialize)] pub(super) struct SectionData { @@ -61,7 +97,7 @@ pub struct RenderContext<'a> { /// Total number of dirty units. pub total_dirty: u32, /// Time tracking for each individual unit. - pub unit_times: &'a [UnitTime], + pub unit_data: Vec, /// Concurrency-tracking information. This is periodically updated while /// compilation progresses. pub concurrency: &'a [Concurrency], @@ -200,12 +236,10 @@ fn write_summary_table( /// Write timing data in JavaScript. Primarily for `timings.js` to put data /// in a `