Skip to content

Commit

Permalink
Add cfg(debug_assertions) to CurrentDepGraph debug fields
Browse files Browse the repository at this point in the history
  • Loading branch information
mzacho committed Jan 13, 2025
1 parent 7a202a9 commit a4ef424
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_incremental/src/persist/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub(crate) fn save_dep_graph(tcx: TyCtxt<'_>) {
sess.time("assert_dep_graph", || assert_dep_graph(tcx));
sess.time("check_dirty_clean", || dirty_clean::check_dirty_clean_annotations(tcx));

#[cfg(debug_assertions)]
if sess.opts.unstable_opts.incremental_info {
tcx.dep_graph.print_incremental_info()
}
Expand Down
18 changes: 13 additions & 5 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 @@ -960,6 +962,7 @@ impl<D: Deps> DepGraph<D> {
}
}

#[cfg(debug_assertions)]
pub fn print_incremental_info(&self) {
if let Some(data) = &self.data {
data.current.encoder.print_incremental_info(
Expand Down Expand Up @@ -1082,7 +1085,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 +1141,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
13 changes: 6 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 @@ -643,6 +641,7 @@ impl<D: Deps> GraphEncoder<D> {
}
}

#[cfg(debug_assertions)]
pub(crate) fn print_incremental_info(
&self,
total_read_count: u64,
Expand All @@ -651,8 +650,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 +676,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

0 comments on commit a4ef424

Please sign in to comment.