Auto merge of #93724 - Mark-Simulacrum:drop-query-stats, r=michaelwoerister

Delete -Zquery-stats infrastructure

These statistics are computable from the self-profile data and/or ad-hoc collectable as needed, and in the meantime contribute to rustc bootstrap times -- locally, this PR shaves ~2.5% from rustc_query_impl builds in instruction counts.

If this does lose some functionality we want to keep, I think we should migrate it to self-profile (or a similar interface) rather than this ad-hoc reporting.
This commit is contained in:
bors 2022-02-09 15:53:10 +00:00
commit 9747ee4755
5 changed files with 0 additions and 122 deletions

View file

@ -400,10 +400,6 @@ impl Compiler {
gcx.enter(rustc_query_impl::alloc_self_profile_query_strings);
}
if self.session().opts.debugging_opts.query_stats {
gcx.enter(rustc_query_impl::print_stats);
}
self.session()
.time("serialize_dep_graph", || gcx.enter(rustc_incremental::save_dep_graph));
}

View file

@ -684,7 +684,6 @@ fn test_debugging_options_tracking_hash() {
untracked!(print_type_sizes, true);
untracked!(proc_macro_backtrace, true);
untracked!(query_dep_graph, true);
untracked!(query_stats, true);
untracked!(save_analysis, true);
untracked!(self_profile, SwitchWithOptPath::Enabled(None));
untracked!(self_profile_events, Some(vec![String::new()]));

View file

@ -28,9 +28,6 @@ mod plumbing;
pub use plumbing::QueryCtxt;
use rustc_query_system::query::*;
mod stats;
pub use self::stats::print_stats;
mod keys;
use keys::Key;

View file

@ -1,112 +0,0 @@
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_middle::ty::query::query_storage;
use rustc_middle::ty::TyCtxt;
use rustc_query_system::query::{QueryCache, QueryCacheStore};
use std::any::type_name;
use std::mem;
trait KeyStats {
fn key_stats(&self, stats: &mut QueryStats);
}
impl<T> KeyStats for T {
default fn key_stats(&self, _: &mut QueryStats) {}
}
impl KeyStats for DefId {
fn key_stats(&self, stats: &mut QueryStats) {
if self.krate == LOCAL_CRATE {
stats.local_def_id_keys = Some(stats.local_def_id_keys.unwrap_or(0) + 1);
}
}
}
#[derive(Clone)]
struct QueryStats {
name: &'static str,
key_size: usize,
key_type: &'static str,
value_size: usize,
value_type: &'static str,
entry_count: usize,
local_def_id_keys: Option<usize>,
}
fn stats<C>(name: &'static str, map: &QueryCacheStore<C>) -> QueryStats
where
C: QueryCache,
{
let mut stats = QueryStats {
name,
key_size: mem::size_of::<C::Key>(),
key_type: type_name::<C::Key>(),
value_size: mem::size_of::<C::Value>(),
value_type: type_name::<C::Value>(),
entry_count: 0,
local_def_id_keys: None,
};
map.iter_results(&mut |key, _, _| {
stats.entry_count += 1;
key.key_stats(&mut stats)
});
stats
}
pub fn print_stats(tcx: TyCtxt<'_>) {
let queries = query_stats(tcx);
let mut query_key_sizes = queries.clone();
query_key_sizes.sort_by_key(|q| q.key_size);
eprintln!("\nLarge query keys:");
for q in query_key_sizes.iter().rev().filter(|q| q.key_size > 8) {
eprintln!(" {} - {} x {} - {}", q.name, q.key_size, q.entry_count, q.key_type);
}
let mut query_value_sizes = queries.clone();
query_value_sizes.sort_by_key(|q| q.value_size);
eprintln!("\nLarge query values:");
for q in query_value_sizes.iter().rev().filter(|q| q.value_size > 8) {
eprintln!(" {} - {} x {} - {}", q.name, q.value_size, q.entry_count, q.value_type);
}
let mut query_value_count = queries.clone();
query_value_count.sort_by_key(|q| q.entry_count);
eprintln!("\nQuery value count:");
for q in query_value_count.iter().rev() {
eprintln!(" {} - {}", q.name, q.entry_count);
}
let mut def_id_density: Vec<_> =
queries.iter().filter(|q| q.local_def_id_keys.is_some()).collect();
def_id_density.sort_by_key(|q| q.local_def_id_keys.unwrap());
eprintln!("\nLocal DefId density:");
let total = tcx.resolutions(()).definitions.def_index_count() as f64;
for q in def_id_density.iter().rev() {
let local = q.local_def_id_keys.unwrap();
eprintln!(" {} - {} = ({}%)", q.name, local, (local as f64 * 100.0) / total);
}
}
macro_rules! print_stats {
(<$tcx:tt>
$($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($K:ty) -> $V:ty,)*
) => {
fn query_stats(tcx: TyCtxt<'_>) -> Vec<QueryStats> {
let mut queries = Vec::new();
$(
queries.push(stats::<
query_storage::$name<'_>,
>(
stringify!($name),
&tcx.query_caches.$name,
));
)*
queries
}
}
}
rustc_query_append! { [print_stats!][<'tcx>] }

View file

@ -1369,8 +1369,6 @@ options! {
"use the given `.prof` file for sampled profile-guided optimization (also known as AutoFDO)"),
query_dep_graph: bool = (false, parse_bool, [UNTRACKED],
"enable queries of the dependency graph for regression testing (default: no)"),
query_stats: bool = (false, parse_bool, [UNTRACKED],
"print some statistics about the query system (default: no)"),
randomize_layout: bool = (false, parse_bool, [TRACKED],
"randomize the layout of types (default: no)"),
layout_seed: Option<u64> = (None, parse_opt_number, [TRACKED],