Skip to content

Commit

Permalink
Adjust profiling.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Mar 30, 2021
1 parent fe89f32 commit df24315
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
39 changes: 29 additions & 10 deletions compiler/rustc_query_system/src/dep_graph/graph.rs
@@ -1,6 +1,7 @@
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::profiling::QueryInvocationId;
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::sharded::{self, Sharded};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::steal::Steal;
Expand Down Expand Up @@ -241,6 +242,7 @@ impl<K: DepKind> DepGraph<K> {

// Intern the new `DepNode`.
let (dep_node_index, prev_and_color) = data.current.intern_node(
dcx.profiler(),
&data.previous,
key,
edges,
Expand Down Expand Up @@ -271,7 +273,12 @@ impl<K: DepKind> DepGraph<K> {

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

let dep_node_index =
data.current.intern_new_node(target_dep_node, task_deps.reads, Fingerprint::ZERO);
let dep_node_index = data.current.intern_new_node(
cx.profiler(),
target_dep_node,
task_deps.reads,
Fingerprint::ZERO,
);

(result, dep_node_index)
} else {
Expand Down Expand Up @@ -628,8 +639,11 @@ impl<K: DepKind> DepGraph<K> {

// We allocating an entry for the node in the current dependency graph and
// adding all the appropriate edges imported from the previous graph
let dep_node_index =
data.current.promote_node_and_deps_to_current(&data.previous, prev_dep_node_index);
let dep_node_index = data.current.promote_node_and_deps_to_current(
tcx.dep_context().profiler(),
&data.previous,
prev_dep_node_index,
);

// ... emitting any stored diagnostic ...

Expand Down Expand Up @@ -943,14 +957,16 @@ impl<K: DepKind> CurrentDepGraph<K> {
/// Assumes that this is a node that has no equivalent in the previous dep-graph.
fn intern_new_node(
&self,
profiler: &SelfProfilerRef,
key: DepNode<K>,
edges: EdgesVec,
current_fingerprint: Fingerprint,
) -> DepNodeIndex {
match self.new_node_to_index.get_shard_by_value(&key).lock().entry(key) {
Entry::Occupied(entry) => *entry.get(),
Entry::Vacant(entry) => {
let dep_node_index = self.encoder.borrow().send(key, current_fingerprint, edges);
let dep_node_index =
self.encoder.borrow().send(profiler, key, current_fingerprint, edges);
entry.insert(dep_node_index);
#[cfg(debug_assertions)]
self.record_edge(dep_node_index, key);
Expand All @@ -961,6 +977,7 @@ impl<K: DepKind> CurrentDepGraph<K> {

fn intern_node(
&self,
profiler: &SelfProfilerRef,
prev_graph: &PreviousDepGraph<K>,
key: DepNode<K>,
edges: EdgesVec,
Expand All @@ -985,7 +1002,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
Some(dep_node_index) => dep_node_index,
None => {
let dep_node_index =
self.encoder.borrow().send(key, fingerprint, edges);
self.encoder.borrow().send(profiler, key, fingerprint, edges);
prev_index_to_index[prev_index] = Some(dep_node_index);
dep_node_index
}
Expand All @@ -1007,7 +1024,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
Some(dep_node_index) => dep_node_index,
None => {
let dep_node_index =
self.encoder.borrow().send(key, fingerprint, edges);
self.encoder.borrow().send(profiler, key, fingerprint, edges);
prev_index_to_index[prev_index] = Some(dep_node_index);
dep_node_index
}
Expand All @@ -1032,7 +1049,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
Some(dep_node_index) => dep_node_index,
None => {
let dep_node_index =
self.encoder.borrow().send(key, Fingerprint::ZERO, edges);
self.encoder.borrow().send(profiler, key, Fingerprint::ZERO, edges);
prev_index_to_index[prev_index] = Some(dep_node_index);
dep_node_index
}
Expand All @@ -1050,14 +1067,15 @@ impl<K: DepKind> CurrentDepGraph<K> {
let fingerprint = fingerprint.unwrap_or(Fingerprint::ZERO);

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

(dep_node_index, None)
}
}

fn promote_node_and_deps_to_current(
&self,
profiler: &SelfProfilerRef,
prev_graph: &PreviousDepGraph<K>,
prev_index: SerializedDepNodeIndex,
) -> DepNodeIndex {
Expand All @@ -1070,6 +1088,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
None => {
let key = prev_graph.index_to_node(prev_index);
let dep_node_index = self.encoder.borrow().send(
profiler,
key,
prev_graph.fingerprint_by_index(prev_index),
prev_graph
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_query_system/src/dep_graph/serialized.rs
Expand Up @@ -16,6 +16,7 @@ use super::query::DepGraphQuery;
use super::{DepKind, DepNode, DepNodeIndex};
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::sync::Lock;
use rustc_index::vec::{Idx, IndexVec};
use rustc_serialize::opaque::{self, FileEncodeResult, FileEncoder, IntEncodedWithFixedSize};
Expand Down Expand Up @@ -293,10 +294,12 @@ impl<K: DepKind + Encodable<FileEncoder>> GraphEncoder<K> {

pub(crate) fn send(
&self,
profiler: &SelfProfilerRef,
node: DepNode<K>,
fingerprint: Fingerprint,
edges: SmallVec<[DepNodeIndex; 8]>,
) -> DepNodeIndex {
let _prof_timer = profiler.generic_activity("incr_comp_encode_dep_graph");
let node = NodeInfo { node, fingerprint, edges };
self.status.lock().encode_node(&node, &self.record_graph)
}
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_query_system/src/query/plumbing.rs
Expand Up @@ -449,9 +449,11 @@ where

let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
tcx.start_query(job.id, diagnostics, || {
tcx.dep_context()
.dep_graph()
.with_anon_task(query.dep_kind, || query.compute(tcx, key))
tcx.dep_context().dep_graph().with_anon_task(
*tcx.dep_context(),
query.dep_kind,
|| query.compute(tcx, key),
)
})
});

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/select/mod.rs
Expand Up @@ -981,7 +981,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
OP: FnOnce(&mut Self) -> R,
{
let (result, dep_node) =
self.tcx().dep_graph.with_anon_task(DepKind::TraitSelect, || op(self));
self.tcx().dep_graph.with_anon_task(self.tcx(), DepKind::TraitSelect, || op(self));
self.tcx().dep_graph.read_index(dep_node);
(result, dep_node)
}
Expand Down

0 comments on commit df24315

Please sign in to comment.