Skip to content

Commit df24315

Browse files
committed
Adjust profiling.
1 parent fe89f32 commit df24315

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc_data_structures::fingerprint::Fingerprint;
22
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
33
use rustc_data_structures::profiling::QueryInvocationId;
4+
use rustc_data_structures::profiling::SelfProfilerRef;
45
use rustc_data_structures::sharded::{self, Sharded};
56
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
67
use rustc_data_structures::steal::Steal;
@@ -241,6 +242,7 @@ impl<K: DepKind> DepGraph<K> {
241242

242243
// Intern the new `DepNode`.
243244
let (dep_node_index, prev_and_color) = data.current.intern_node(
245+
dcx.profiler(),
244246
&data.previous,
245247
key,
246248
edges,
@@ -271,7 +273,12 @@ impl<K: DepKind> DepGraph<K> {
271273

272274
/// Executes something within an "anonymous" task, that is, a task the
273275
/// `DepNode` of which is determined by the list of inputs it read from.
274-
pub fn with_anon_task<OP, R>(&self, dep_kind: K, op: OP) -> (R, DepNodeIndex)
276+
pub fn with_anon_task<Ctxt: DepContext<DepKind = K>, OP, R>(
277+
&self,
278+
cx: Ctxt,
279+
dep_kind: K,
280+
op: OP,
281+
) -> (R, DepNodeIndex)
275282
where
276283
OP: FnOnce() -> R,
277284
{
@@ -298,8 +305,12 @@ impl<K: DepKind> DepGraph<K> {
298305
hash: data.current.anon_id_seed.combine(hasher.finish()).into(),
299306
};
300307

301-
let dep_node_index =
302-
data.current.intern_new_node(target_dep_node, task_deps.reads, Fingerprint::ZERO);
308+
let dep_node_index = data.current.intern_new_node(
309+
cx.profiler(),
310+
target_dep_node,
311+
task_deps.reads,
312+
Fingerprint::ZERO,
313+
);
303314

304315
(result, dep_node_index)
305316
} else {
@@ -628,8 +639,11 @@ impl<K: DepKind> DepGraph<K> {
628639

629640
// We allocating an entry for the node in the current dependency graph and
630641
// adding all the appropriate edges imported from the previous graph
631-
let dep_node_index =
632-
data.current.promote_node_and_deps_to_current(&data.previous, prev_dep_node_index);
642+
let dep_node_index = data.current.promote_node_and_deps_to_current(
643+
tcx.dep_context().profiler(),
644+
&data.previous,
645+
prev_dep_node_index,
646+
);
633647

634648
// ... emitting any stored diagnostic ...
635649

@@ -943,14 +957,16 @@ impl<K: DepKind> CurrentDepGraph<K> {
943957
/// Assumes that this is a node that has no equivalent in the previous dep-graph.
944958
fn intern_new_node(
945959
&self,
960+
profiler: &SelfProfilerRef,
946961
key: DepNode<K>,
947962
edges: EdgesVec,
948963
current_fingerprint: Fingerprint,
949964
) -> DepNodeIndex {
950965
match self.new_node_to_index.get_shard_by_value(&key).lock().entry(key) {
951966
Entry::Occupied(entry) => *entry.get(),
952967
Entry::Vacant(entry) => {
953-
let dep_node_index = self.encoder.borrow().send(key, current_fingerprint, edges);
968+
let dep_node_index =
969+
self.encoder.borrow().send(profiler, key, current_fingerprint, edges);
954970
entry.insert(dep_node_index);
955971
#[cfg(debug_assertions)]
956972
self.record_edge(dep_node_index, key);
@@ -961,6 +977,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
961977

962978
fn intern_node(
963979
&self,
980+
profiler: &SelfProfilerRef,
964981
prev_graph: &PreviousDepGraph<K>,
965982
key: DepNode<K>,
966983
edges: EdgesVec,
@@ -985,7 +1002,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
9851002
Some(dep_node_index) => dep_node_index,
9861003
None => {
9871004
let dep_node_index =
988-
self.encoder.borrow().send(key, fingerprint, edges);
1005+
self.encoder.borrow().send(profiler, key, fingerprint, edges);
9891006
prev_index_to_index[prev_index] = Some(dep_node_index);
9901007
dep_node_index
9911008
}
@@ -1007,7 +1024,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
10071024
Some(dep_node_index) => dep_node_index,
10081025
None => {
10091026
let dep_node_index =
1010-
self.encoder.borrow().send(key, fingerprint, edges);
1027+
self.encoder.borrow().send(profiler, key, fingerprint, edges);
10111028
prev_index_to_index[prev_index] = Some(dep_node_index);
10121029
dep_node_index
10131030
}
@@ -1032,7 +1049,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
10321049
Some(dep_node_index) => dep_node_index,
10331050
None => {
10341051
let dep_node_index =
1035-
self.encoder.borrow().send(key, Fingerprint::ZERO, edges);
1052+
self.encoder.borrow().send(profiler, key, Fingerprint::ZERO, edges);
10361053
prev_index_to_index[prev_index] = Some(dep_node_index);
10371054
dep_node_index
10381055
}
@@ -1050,14 +1067,15 @@ impl<K: DepKind> CurrentDepGraph<K> {
10501067
let fingerprint = fingerprint.unwrap_or(Fingerprint::ZERO);
10511068

10521069
// This is a new node: it didn't exist in the previous compilation session.
1053-
let dep_node_index = self.intern_new_node(key, edges, fingerprint);
1070+
let dep_node_index = self.intern_new_node(profiler, key, edges, fingerprint);
10541071

10551072
(dep_node_index, None)
10561073
}
10571074
}
10581075

10591076
fn promote_node_and_deps_to_current(
10601077
&self,
1078+
profiler: &SelfProfilerRef,
10611079
prev_graph: &PreviousDepGraph<K>,
10621080
prev_index: SerializedDepNodeIndex,
10631081
) -> DepNodeIndex {
@@ -1070,6 +1088,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
10701088
None => {
10711089
let key = prev_graph.index_to_node(prev_index);
10721090
let dep_node_index = self.encoder.borrow().send(
1091+
profiler,
10731092
key,
10741093
prev_graph.fingerprint_by_index(prev_index),
10751094
prev_graph

compiler/rustc_query_system/src/dep_graph/serialized.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use super::query::DepGraphQuery;
1616
use super::{DepKind, DepNode, DepNodeIndex};
1717
use rustc_data_structures::fingerprint::Fingerprint;
1818
use rustc_data_structures::fx::FxHashMap;
19+
use rustc_data_structures::profiling::SelfProfilerRef;
1920
use rustc_data_structures::sync::Lock;
2021
use rustc_index::vec::{Idx, IndexVec};
2122
use rustc_serialize::opaque::{self, FileEncodeResult, FileEncoder, IntEncodedWithFixedSize};
@@ -293,10 +294,12 @@ impl<K: DepKind + Encodable<FileEncoder>> GraphEncoder<K> {
293294

294295
pub(crate) fn send(
295296
&self,
297+
profiler: &SelfProfilerRef,
296298
node: DepNode<K>,
297299
fingerprint: Fingerprint,
298300
edges: SmallVec<[DepNodeIndex; 8]>,
299301
) -> DepNodeIndex {
302+
let _prof_timer = profiler.generic_activity("incr_comp_encode_dep_graph");
300303
let node = NodeInfo { node, fingerprint, edges };
301304
self.status.lock().encode_node(&node, &self.record_graph)
302305
}

compiler/rustc_query_system/src/query/plumbing.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,11 @@ where
449449

450450
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
451451
tcx.start_query(job.id, diagnostics, || {
452-
tcx.dep_context()
453-
.dep_graph()
454-
.with_anon_task(query.dep_kind, || query.compute(tcx, key))
452+
tcx.dep_context().dep_graph().with_anon_task(
453+
*tcx.dep_context(),
454+
query.dep_kind,
455+
|| query.compute(tcx, key),
456+
)
455457
})
456458
});
457459

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
981981
OP: FnOnce(&mut Self) -> R,
982982
{
983983
let (result, dep_node) =
984-
self.tcx().dep_graph.with_anon_task(DepKind::TraitSelect, || op(self));
984+
self.tcx().dep_graph.with_anon_task(self.tcx(), DepKind::TraitSelect, || op(self));
985985
self.tcx().dep_graph.read_index(dep_node);
986986
(result, dep_node)
987987
}

0 commit comments

Comments
 (0)