@@ -118,6 +118,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
118118 let mut lock = cache. borrow_mut ( ) ;
119119 if let Some ( value) = lock. results . get ( key) {
120120 profq_msg ! ( tcx, ProfileQueriesMsg :: CacheHit ) ;
121+ tcx. sess . profiler ( |p| {
122+ p. record_query ( Q :: CATEGORY ) ;
123+ p. record_query_hit ( Q :: CATEGORY ) ;
124+ } ) ;
125+
121126 let result = Ok ( ( value. value . clone ( ) , value. index ) ) ;
122127 return TryGetJob :: JobCompleted ( result) ;
123128 }
@@ -358,10 +363,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
358363 )
359364 ) ;
360365
366+ self . sess . profiler ( |p| p. record_query ( Q :: CATEGORY ) ) ;
367+
361368 let job = match JobOwner :: try_get ( self , span, & key) {
362369 TryGetJob :: NotYetStarted ( job) => job,
363370 TryGetJob :: JobCompleted ( result) => {
364371 return result. map ( |( v, index) | {
372+ self . sess . profiler ( |p| p. record_query_hit ( Q :: CATEGORY ) ) ;
365373 self . dep_graph . read_index ( index) ;
366374 v
367375 } )
@@ -379,13 +387,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
379387
380388 if dep_node. kind . is_anon ( ) {
381389 profq_msg ! ( self , ProfileQueriesMsg :: ProviderBegin ) ;
390+ self . sess . profiler ( |p| p. start_activity ( Q :: CATEGORY ) ) ;
382391
383392 let res = job. start ( self , |tcx| {
384393 tcx. dep_graph . with_anon_task ( dep_node. kind , || {
385394 Q :: compute ( tcx. global_tcx ( ) , key)
386395 } )
387396 } ) ;
388397
398+ self . sess . profiler ( |p| p. end_activity ( Q :: CATEGORY ) ) ;
389399 profq_msg ! ( self , ProfileQueriesMsg :: ProviderEnd ) ;
390400 let ( ( result, dep_node_index) , diagnostics) = res;
391401
@@ -402,6 +412,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
402412 if !dep_node. kind . is_input ( ) {
403413 if let Some ( dep_node_index) = self . try_mark_green_and_read ( & dep_node) {
404414 profq_msg ! ( self , ProfileQueriesMsg :: CacheHit ) ;
415+ self . sess . profiler ( |p| p. record_query_hit ( Q :: CATEGORY ) ) ;
416+
405417 return self . load_from_disk_and_cache_in_memory :: < Q > ( key,
406418 job,
407419 dep_node_index,
@@ -523,6 +535,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
523535 key, dep_node) ;
524536
525537 profq_msg ! ( self , ProfileQueriesMsg :: ProviderBegin ) ;
538+ self . sess . profiler ( |p| {
539+ p. start_activity ( Q :: CATEGORY ) ;
540+ p. record_query ( Q :: CATEGORY ) ;
541+ } ) ;
542+
526543 let res = job. start ( self , |tcx| {
527544 if dep_node. kind . is_eval_always ( ) {
528545 tcx. dep_graph . with_eval_always_task ( dep_node,
@@ -536,6 +553,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
536553 Q :: compute)
537554 }
538555 } ) ;
556+
557+ self . sess . profiler ( |p| p. end_activity ( Q :: CATEGORY ) ) ;
539558 profq_msg ! ( self , ProfileQueriesMsg :: ProviderEnd ) ;
540559
541560 let ( ( result, dep_node_index) , diagnostics) = res;
@@ -574,7 +593,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
574593 // DepNodeIndex. We must invoke the query itself. The performance cost
575594 // this introduces should be negligible as we'll immediately hit the
576595 // in-memory cache, or another query down the line will.
596+
597+ self . sess . profiler ( |p| {
598+ p. start_activity ( Q :: CATEGORY ) ;
599+ p. record_query ( Q :: CATEGORY ) ;
600+ } ) ;
601+
577602 let _ = self . get_query :: < Q > ( DUMMY_SP , key) ;
603+
604+ self . sess . profiler ( |p| p. end_activity ( Q :: CATEGORY ) ) ;
578605 }
579606 }
580607
@@ -655,6 +682,7 @@ macro_rules! define_queries_inner {
655682 rustc_data_structures:: stable_hasher:: StableHasher ,
656683 ich:: StableHashingContext
657684 } ;
685+ use util:: profiling:: ProfileCategory ;
658686
659687 define_queries_struct! {
660688 tcx: $tcx,
@@ -768,6 +796,7 @@ macro_rules! define_queries_inner {
768796 type Value = $V;
769797
770798 const NAME : & ' static str = stringify!( $name) ;
799+ const CATEGORY : ProfileCategory = $category;
771800 }
772801
773802 impl <$tcx> QueryAccessors <$tcx> for queries:: $name<$tcx> {
0 commit comments