Skip to content

Add cfg(debug_assertions) to CurrentDepGraph debug fields #135449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::profiling::{QueryInvocationId, SelfProfilerRef};
use rustc_data_structures::sharded::{self, Sharded};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc};
#[cfg(debug_assertions)]
use rustc_data_structures::sync::AtomicU64;
use rustc_data_structures::sync::{AtomicU32, Lock, Lrc};
use rustc_data_structures::unord::UnordMap;
use rustc_index::IndexVec;
use rustc_macros::{Decodable, Encodable};
Expand Down Expand Up @@ -484,9 +486,8 @@ impl<D: Deps> DepGraph<D> {
};
let task_deps = &mut *task_deps;

if cfg!(debug_assertions) {
data.current.total_read_count.fetch_add(1, Ordering::Relaxed);
}
#[cfg(debug_assertions)]
data.current.total_read_count.fetch_add(1, Ordering::Relaxed);

// As long as we only have a low number of reads we can avoid doing a hash
// insert and potentially allocating/reallocating the hashmap
Expand Down Expand Up @@ -514,7 +515,8 @@ impl<D: Deps> DepGraph<D> {
}
}
}
} else if cfg!(debug_assertions) {
} else {
#[cfg(debug_assertions)]
data.current.total_duplicate_read_count.fetch_add(1, Ordering::Relaxed);
}
})
Expand Down Expand Up @@ -962,10 +964,13 @@ impl<D: Deps> DepGraph<D> {

pub fn print_incremental_info(&self) {
if let Some(data) = &self.data {
#[cfg(debug_assertions)]
data.current.encoder.print_incremental_info(
data.current.total_read_count.load(Ordering::Relaxed),
data.current.total_duplicate_read_count.load(Ordering::Relaxed),
)
);
#[cfg(not(debug_assertions))]
data.current.encoder.print_incremental_info(0, 0)
}
}

Expand Down Expand Up @@ -1082,7 +1087,10 @@ pub(super) struct CurrentDepGraph<D: Deps> {

/// These are simple counters that are for profiling and
/// debugging and only active with `debug_assertions`.
#[cfg(debug_assertions)]
total_read_count: AtomicU64,

#[cfg(debug_assertions)]
total_duplicate_read_count: AtomicU64,
}

Expand Down Expand Up @@ -1135,7 +1143,9 @@ impl<D: Deps> CurrentDepGraph<D> {
forbidden_edge,
#[cfg(debug_assertions)]
fingerprints: Lock::new(IndexVec::from_elem_n(None, new_node_count_estimate)),
#[cfg(debug_assertions)]
total_read_count: AtomicU64::new(0),
#[cfg(debug_assertions)]
total_duplicate_read_count: AtomicU64::new(0),
}
}
Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_query_system/src/dep_graph/serialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@ impl NodeInfo {
}

struct Stat {
kind: DepKind,
node_counter: u64,
edge_counter: u64,
}
Expand Down Expand Up @@ -524,8 +523,7 @@ impl<D: Deps> EncoderState<D> {

// Outline the stats code as it's typically disabled and cold.
outline(move || {
let stat =
stats.entry(kind).or_insert(Stat { kind, node_counter: 0, edge_counter: 0 });
let stat = stats.entry(kind).or_insert(Stat { node_counter: 0, edge_counter: 0 });
stat.node_counter += 1;
stat.edge_counter += edge_count as u64;
});
Expand Down Expand Up @@ -651,8 +649,8 @@ impl<D: Deps> GraphEncoder<D> {
let mut status = self.status.lock();
let status = status.as_mut().unwrap();
if let Some(record_stats) = &status.stats {
let mut stats: Vec<_> = record_stats.values().collect();
stats.sort_by_key(|s| -(s.node_counter as i64));
let mut stats: Vec<_> = record_stats.iter().collect();
stats.sort_by_key(|(_, s)| -(s.node_counter as i64));

const SEPARATOR: &str = "[incremental] --------------------------------\
----------------------------------------------\
Expand All @@ -677,14 +675,14 @@ impl<D: Deps> GraphEncoder<D> {
);
eprintln!("{SEPARATOR}");

for stat in stats {
for (kind, stat) in stats {
let node_kind_ratio =
(100.0 * (stat.node_counter as f64)) / (status.total_node_count as f64);
let node_kind_avg_edges = (stat.edge_counter as f64) / (stat.node_counter as f64);

eprintln!(
"[incremental] {:<36}|{:>16.1}% |{:>12} |{:>17.1} |",
format!("{:?}", stat.kind),
format!("{:?}", kind),
node_kind_ratio,
stat.node_counter,
node_kind_avg_edges,
Expand Down
Loading