@@ -118,6 +118,11 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
118
118
let mut lock = cache. borrow_mut ( ) ;
119
119
if let Some ( value) = lock. results . get ( key) {
120
120
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
+
121
126
let result = Ok ( ( value. value . clone ( ) , value. index ) ) ;
122
127
return TryGetJob :: JobCompleted ( result) ;
123
128
}
@@ -358,10 +363,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
358
363
)
359
364
) ;
360
365
366
+ self . sess . profiler ( |p| p. record_query ( Q :: CATEGORY ) ) ;
367
+
361
368
let job = match JobOwner :: try_get ( self , span, & key) {
362
369
TryGetJob :: NotYetStarted ( job) => job,
363
370
TryGetJob :: JobCompleted ( result) => {
364
371
return result. map ( |( v, index) | {
372
+ self . sess . profiler ( |p| p. record_query_hit ( Q :: CATEGORY ) ) ;
365
373
self . dep_graph . read_index ( index) ;
366
374
v
367
375
} )
@@ -379,13 +387,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
379
387
380
388
if dep_node. kind . is_anon ( ) {
381
389
profq_msg ! ( self , ProfileQueriesMsg :: ProviderBegin ) ;
390
+ self . sess . profiler ( |p| p. start_activity ( Q :: CATEGORY ) ) ;
382
391
383
392
let res = job. start ( self , |tcx| {
384
393
tcx. dep_graph . with_anon_task ( dep_node. kind , || {
385
394
Q :: compute ( tcx. global_tcx ( ) , key)
386
395
} )
387
396
} ) ;
388
397
398
+ self . sess . profiler ( |p| p. end_activity ( Q :: CATEGORY ) ) ;
389
399
profq_msg ! ( self , ProfileQueriesMsg :: ProviderEnd ) ;
390
400
let ( ( result, dep_node_index) , diagnostics) = res;
391
401
@@ -402,6 +412,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
402
412
if !dep_node. kind . is_input ( ) {
403
413
if let Some ( dep_node_index) = self . try_mark_green_and_read ( & dep_node) {
404
414
profq_msg ! ( self , ProfileQueriesMsg :: CacheHit ) ;
415
+ self . sess . profiler ( |p| p. record_query_hit ( Q :: CATEGORY ) ) ;
416
+
405
417
return self . load_from_disk_and_cache_in_memory :: < Q > ( key,
406
418
job,
407
419
dep_node_index,
@@ -523,6 +535,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
523
535
key, dep_node) ;
524
536
525
537
profq_msg ! ( self , ProfileQueriesMsg :: ProviderBegin ) ;
538
+ self . sess . profiler ( |p| {
539
+ p. start_activity ( Q :: CATEGORY ) ;
540
+ p. record_query ( Q :: CATEGORY ) ;
541
+ } ) ;
542
+
526
543
let res = job. start ( self , |tcx| {
527
544
if dep_node. kind . is_eval_always ( ) {
528
545
tcx. dep_graph . with_eval_always_task ( dep_node,
@@ -536,6 +553,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
536
553
Q :: compute)
537
554
}
538
555
} ) ;
556
+
557
+ self . sess . profiler ( |p| p. end_activity ( Q :: CATEGORY ) ) ;
539
558
profq_msg ! ( self , ProfileQueriesMsg :: ProviderEnd ) ;
540
559
541
560
let ( ( result, dep_node_index) , diagnostics) = res;
@@ -574,7 +593,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
574
593
// DepNodeIndex. We must invoke the query itself. The performance cost
575
594
// this introduces should be negligible as we'll immediately hit the
576
595
// 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
+
577
602
let _ = self . get_query :: < Q > ( DUMMY_SP , key) ;
603
+
604
+ self . sess . profiler ( |p| p. end_activity ( Q :: CATEGORY ) ) ;
578
605
}
579
606
}
580
607
@@ -655,6 +682,7 @@ macro_rules! define_queries_inner {
655
682
rustc_data_structures:: stable_hasher:: StableHasher ,
656
683
ich:: StableHashingContext
657
684
} ;
685
+ use util:: profiling:: ProfileCategory ;
658
686
659
687
define_queries_struct! {
660
688
tcx: $tcx,
@@ -768,6 +796,7 @@ macro_rules! define_queries_inner {
768
796
type Value = $V;
769
797
770
798
const NAME : & ' static str = stringify!( $name) ;
799
+ const CATEGORY : ProfileCategory = $category;
771
800
}
772
801
773
802
impl <$tcx> QueryAccessors <$tcx> for queries:: $name<$tcx> {
0 commit comments