@@ -110,12 +110,14 @@ bitflags::bitflags! {
110
110
const FUNCTION_ARGS = 1 << 6 ;
111
111
const LLVM = 1 << 7 ;
112
112
const INCR_RESULT_HASHING = 1 << 8 ;
113
+ const ARTIFACT_SIZES = 1 << 9 ;
113
114
114
115
const DEFAULT = Self :: GENERIC_ACTIVITIES . bits |
115
116
Self :: QUERY_PROVIDERS . bits |
116
117
Self :: QUERY_BLOCKED . bits |
117
118
Self :: INCR_CACHE_LOADS . bits |
118
- Self :: INCR_RESULT_HASHING . bits;
119
+ Self :: INCR_RESULT_HASHING . bits |
120
+ Self :: ARTIFACT_SIZES . bits;
119
121
120
122
const ARGS = Self :: QUERY_KEYS . bits | Self :: FUNCTION_ARGS . bits;
121
123
}
@@ -136,6 +138,7 @@ const EVENT_FILTERS_BY_NAME: &[(&str, EventFilter)] = &[
136
138
( "args" , EventFilter :: ARGS ) ,
137
139
( "llvm" , EventFilter :: LLVM ) ,
138
140
( "incr-result-hashing" , EventFilter :: INCR_RESULT_HASHING ) ,
141
+ ( "artifact-sizes" , EventFilter :: ARTIFACT_SIZES ) ,
139
142
] ;
140
143
141
144
/// Something that uniquely identifies a query invocation.
@@ -285,6 +288,33 @@ impl SelfProfilerRef {
285
288
} )
286
289
}
287
290
291
+ /// Record the size of an artifact that the compiler produces
292
+ ///
293
+ /// `artifact_kind` is the class of artifact (e.g., query_cache, object_file, etc.)
294
+ /// `artifact_name` is an identifier to the specific artifact being stored (usually a filename)
295
+ #[ inline( always) ]
296
+ pub fn artifact_size < A > ( & self , artifact_kind : & str , artifact_name : A , size : u64 )
297
+ where
298
+ A : Borrow < str > + Into < String > ,
299
+ {
300
+ drop ( self . exec ( EventFilter :: ARTIFACT_SIZES , |profiler| {
301
+ let builder = EventIdBuilder :: new ( & profiler. profiler ) ;
302
+ let event_label = profiler. get_or_alloc_cached_string ( artifact_kind) ;
303
+ let event_arg = profiler. get_or_alloc_cached_string ( artifact_name) ;
304
+ let event_id = builder. from_label_and_arg ( event_label, event_arg) ;
305
+ let thread_id = get_thread_id ( ) ;
306
+
307
+ profiler. profiler . record_integer_event (
308
+ profiler. artifact_size_event_kind ,
309
+ event_id,
310
+ thread_id,
311
+ size,
312
+ ) ;
313
+
314
+ TimingGuard :: none ( )
315
+ } ) )
316
+ }
317
+
288
318
#[ inline( always) ]
289
319
pub fn generic_activity_with_args (
290
320
& self ,
@@ -372,7 +402,7 @@ impl SelfProfilerRef {
372
402
) {
373
403
drop ( self . exec ( event_filter, |profiler| {
374
404
let event_id = StringId :: new_virtual ( query_invocation_id. 0 ) ;
375
- let thread_id = std :: thread :: current ( ) . id ( ) . as_u64 ( ) . get ( ) as u32 ;
405
+ let thread_id = get_thread_id ( ) ;
376
406
377
407
profiler. profiler . record_instant_event (
378
408
event_kind ( profiler) ,
@@ -425,6 +455,7 @@ pub struct SelfProfiler {
425
455
incremental_result_hashing_event_kind : StringId ,
426
456
query_blocked_event_kind : StringId ,
427
457
query_cache_hit_event_kind : StringId ,
458
+ artifact_size_event_kind : StringId ,
428
459
}
429
460
430
461
impl SelfProfiler {
@@ -447,6 +478,7 @@ impl SelfProfiler {
447
478
profiler. alloc_string ( "IncrementalResultHashing" ) ;
448
479
let query_blocked_event_kind = profiler. alloc_string ( "QueryBlocked" ) ;
449
480
let query_cache_hit_event_kind = profiler. alloc_string ( "QueryCacheHit" ) ;
481
+ let artifact_size_event_kind = profiler. alloc_string ( "ArtifactSize" ) ;
450
482
451
483
let mut event_filter_mask = EventFilter :: empty ( ) ;
452
484
@@ -491,6 +523,7 @@ impl SelfProfiler {
491
523
incremental_result_hashing_event_kind,
492
524
query_blocked_event_kind,
493
525
query_cache_hit_event_kind,
526
+ artifact_size_event_kind,
494
527
} )
495
528
}
496
529
@@ -561,7 +594,7 @@ impl<'a> TimingGuard<'a> {
561
594
event_kind : StringId ,
562
595
event_id : EventId ,
563
596
) -> TimingGuard < ' a > {
564
- let thread_id = std :: thread :: current ( ) . id ( ) . as_u64 ( ) . get ( ) as u32 ;
597
+ let thread_id = get_thread_id ( ) ;
565
598
let raw_profiler = & profiler. profiler ;
566
599
let timing_guard =
567
600
raw_profiler. start_recording_interval_event ( event_kind, event_id, thread_id) ;
@@ -655,6 +688,10 @@ pub fn duration_to_secs_str(dur: std::time::Duration) -> String {
655
688
format ! ( "{:.3}" , dur. as_secs_f64( ) )
656
689
}
657
690
691
+ fn get_thread_id ( ) -> u32 {
692
+ std:: thread:: current ( ) . id ( ) . as_u64 ( ) . get ( ) as u32
693
+ }
694
+
658
695
// Memory reporting
659
696
cfg_if ! {
660
697
if #[ cfg( windows) ] {
0 commit comments