Add infrastructure for emitting timing sections

This commit is contained in:
Jakub Beránek
2025-06-06 17:12:55 +02:00
parent 7ad5248c95
commit c9d305952e
9 changed files with 174 additions and 11 deletions

View File

@@ -28,9 +28,10 @@ use termcolor::{ColorSpec, WriteColor};
use crate::diagnostic::IsLint;
use crate::emitter::{
ColorConfig, Destination, Emitter, HumanEmitter, HumanReadableErrorType, OutputTheme,
should_show_source_code,
TimingEvent, should_show_source_code,
};
use crate::registry::Registry;
use crate::timings::{TimingRecord, TimingSection};
use crate::translation::{Translate, to_fluent_args};
use crate::{
CodeSuggestion, FluentBundle, LazyFallbackBundle, MultiSpan, SpanLabel, Subdiag, Suggestions,
@@ -104,6 +105,7 @@ impl JsonEmitter {
enum EmitTyped<'a> {
Diagnostic(Diagnostic),
Artifact(ArtifactNotification<'a>),
SectionTiming(SectionTimestamp<'a>),
FutureIncompat(FutureIncompatReport<'a>),
UnusedExtern(UnusedExterns<'a>),
}
@@ -135,6 +137,21 @@ impl Emitter for JsonEmitter {
}
}
fn emit_timing_section(&mut self, record: TimingRecord, event: TimingEvent) {
let event = match event {
TimingEvent::Start => "start",
TimingEvent::End => "end",
};
let name = match record.section {
TimingSection::Linking => "link",
};
let data = SectionTimestamp { name, event, timestamp: record.timestamp };
let result = self.emit(EmitTyped::SectionTiming(data));
if let Err(e) = result {
panic!("failed to print timing section: {e:?}");
}
}
fn emit_future_breakage_report(&mut self, diags: Vec<crate::DiagInner>, registry: &Registry) {
let data: Vec<FutureBreakageItem<'_>> = diags
.into_iter()
@@ -263,6 +280,16 @@ struct ArtifactNotification<'a> {
emit: &'a str,
}
#[derive(Serialize)]
struct SectionTimestamp<'a> {
/// Name of the section
name: &'a str,
/// Start/end of the section
event: &'a str,
/// Opaque timestamp.
timestamp: u128,
}
#[derive(Serialize)]
struct FutureBreakageItem<'a> {
// Always EmitTyped::Diagnostic, but we want to make sure it gets serialized