@@ -110,12 +110,14 @@ bitflags::bitflags! {
110110 const FUNCTION_ARGS = 1 << 6 ;
111111 const LLVM = 1 << 7 ;
112112 const INCR_RESULT_HASHING = 1 << 8 ;
113+ const ARTIFACT_SIZES = 1 << 9 ;
113114
114115 const DEFAULT = Self :: GENERIC_ACTIVITIES . bits |
115116 Self :: QUERY_PROVIDERS . bits |
116117 Self :: QUERY_BLOCKED . bits |
117118 Self :: INCR_CACHE_LOADS . bits |
118- Self :: INCR_RESULT_HASHING . bits;
119+ Self :: INCR_RESULT_HASHING . bits |
120+ Self :: ARTIFACT_SIZES . bits;
119121
120122 const ARGS = Self :: QUERY_KEYS . bits | Self :: FUNCTION_ARGS . bits;
121123 }
@@ -136,6 +138,7 @@ const EVENT_FILTERS_BY_NAME: &[(&str, EventFilter)] = &[
136138 ( "args" , EventFilter :: ARGS ) ,
137139 ( "llvm" , EventFilter :: LLVM ) ,
138140 ( "incr-result-hashing" , EventFilter :: INCR_RESULT_HASHING ) ,
141+ ( "artifact-sizes" , EventFilter :: ARTIFACT_SIZES ) ,
139142] ;
140143
141144/// Something that uniquely identifies a query invocation.
@@ -285,6 +288,33 @@ impl SelfProfilerRef {
285288 } )
286289 }
287290
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+
288318 #[ inline( always) ]
289319 pub fn generic_activity_with_args (
290320 & self ,
@@ -372,7 +402,7 @@ impl SelfProfilerRef {
372402 ) {
373403 drop ( self . exec ( event_filter, |profiler| {
374404 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 ( ) ;
376406
377407 profiler. profiler . record_instant_event (
378408 event_kind ( profiler) ,
@@ -425,6 +455,7 @@ pub struct SelfProfiler {
425455 incremental_result_hashing_event_kind : StringId ,
426456 query_blocked_event_kind : StringId ,
427457 query_cache_hit_event_kind : StringId ,
458+ artifact_size_event_kind : StringId ,
428459}
429460
430461impl SelfProfiler {
@@ -447,6 +478,7 @@ impl SelfProfiler {
447478 profiler. alloc_string ( "IncrementalResultHashing" ) ;
448479 let query_blocked_event_kind = profiler. alloc_string ( "QueryBlocked" ) ;
449480 let query_cache_hit_event_kind = profiler. alloc_string ( "QueryCacheHit" ) ;
481+ let artifact_size_event_kind = profiler. alloc_string ( "ArtifactSize" ) ;
450482
451483 let mut event_filter_mask = EventFilter :: empty ( ) ;
452484
@@ -491,6 +523,7 @@ impl SelfProfiler {
491523 incremental_result_hashing_event_kind,
492524 query_blocked_event_kind,
493525 query_cache_hit_event_kind,
526+ artifact_size_event_kind,
494527 } )
495528 }
496529
@@ -561,7 +594,7 @@ impl<'a> TimingGuard<'a> {
561594 event_kind : StringId ,
562595 event_id : EventId ,
563596 ) -> TimingGuard < ' a > {
564- let thread_id = std :: thread :: current ( ) . id ( ) . as_u64 ( ) . get ( ) as u32 ;
597+ let thread_id = get_thread_id ( ) ;
565598 let raw_profiler = & profiler. profiler ;
566599 let timing_guard =
567600 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 {
655688 format ! ( "{:.3}" , dur. as_secs_f64( ) )
656689}
657690
691+ fn get_thread_id ( ) -> u32 {
692+ std:: thread:: current ( ) . id ( ) . as_u64 ( ) . get ( ) as u32
693+ }
694+
658695// Memory reporting
659696cfg_if ! {
660697 if #[ cfg( windows) ] {
0 commit comments