@@ -13,6 +13,7 @@ use std::error::Report;
13
13
use std:: io:: { self , Write } ;
14
14
use std:: path:: Path ;
15
15
use std:: sync:: { Arc , Mutex } ;
16
+ use std:: time:: Instant ;
16
17
use std:: vec;
17
18
18
19
use derive_setters:: Setters ;
@@ -28,9 +29,10 @@ use termcolor::{ColorSpec, WriteColor};
28
29
use crate :: diagnostic:: IsLint ;
29
30
use crate :: emitter:: {
30
31
ColorConfig , Destination , Emitter , HumanEmitter , HumanReadableErrorType , OutputTheme ,
31
- should_show_source_code,
32
+ TimingSectionKind , should_show_source_code,
32
33
} ;
33
34
use crate :: registry:: Registry ;
35
+ use crate :: timings:: TimingSection ;
34
36
use crate :: translation:: { Translate , to_fluent_args} ;
35
37
use crate :: {
36
38
CodeSuggestion , FluentBundle , LazyFallbackBundle , MultiSpan , SpanLabel , Subdiag , Suggestions ,
@@ -60,6 +62,8 @@ pub struct JsonEmitter {
60
62
macro_backtrace : bool ,
61
63
track_diagnostics : bool ,
62
64
terminal_url : TerminalUrl ,
65
+ #[ setters( skip) ]
66
+ start_timestamp : Instant ,
63
67
}
64
68
65
69
impl JsonEmitter {
@@ -85,6 +89,7 @@ impl JsonEmitter {
85
89
macro_backtrace : false ,
86
90
track_diagnostics : false ,
87
91
terminal_url : TerminalUrl :: No ,
92
+ start_timestamp : Instant :: now ( ) ,
88
93
}
89
94
}
90
95
@@ -104,6 +109,7 @@ impl JsonEmitter {
104
109
enum EmitTyped < ' a > {
105
110
Diagnostic ( Diagnostic ) ,
106
111
Artifact ( ArtifactNotification < ' a > ) ,
112
+ SectionTimestamp ( SectionTimestamp < ' a > ) ,
107
113
FutureIncompat ( FutureIncompatReport < ' a > ) ,
108
114
UnusedExtern ( UnusedExterns < ' a > ) ,
109
115
}
@@ -135,6 +141,26 @@ impl Emitter for JsonEmitter {
135
141
}
136
142
}
137
143
144
+ fn emit_timing_section ( & mut self , section : TimingSection , kind : TimingSectionKind ) {
145
+ let kind = match kind {
146
+ TimingSectionKind :: Start => "start" ,
147
+ TimingSectionKind :: End => "end" ,
148
+ } ;
149
+ let name = match section {
150
+ TimingSection :: Linking => "link" ,
151
+ } ;
152
+ let time = Instant :: now ( ) ;
153
+ let data = SectionTimestamp {
154
+ name,
155
+ kind,
156
+ timestamp : time. duration_since ( self . start_timestamp ) . as_micros ( ) ,
157
+ } ;
158
+ let result = self . emit ( EmitTyped :: SectionTimestamp ( data) ) ;
159
+ if let Err ( e) = result {
160
+ panic ! ( "failed to print timing section: {e:?}" ) ;
161
+ }
162
+ }
163
+
138
164
fn emit_future_breakage_report ( & mut self , diags : Vec < crate :: DiagInner > , registry : & Registry ) {
139
165
let data: Vec < FutureBreakageItem < ' _ > > = diags
140
166
. into_iter ( )
@@ -263,6 +289,16 @@ struct ArtifactNotification<'a> {
263
289
emit : & ' a str ,
264
290
}
265
291
292
+ #[ derive( Serialize ) ]
293
+ struct SectionTimestamp < ' a > {
294
+ /// Name of the section
295
+ name : & ' a str ,
296
+ /// Start/end of the section
297
+ kind : & ' a str ,
298
+ /// Microseconds elapsed since some predetermined point in time (~start of the rustc process).
299
+ timestamp : u128 ,
300
+ }
301
+
266
302
#[ derive( Serialize ) ]
267
303
struct FutureBreakageItem < ' a > {
268
304
// Always EmitTyped::Diagnostic, but we want to make sure it gets serialized
0 commit comments