Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
108 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
use crate::ty::query::config::QueryAccessors; | ||
use crate::ty::query::plumbing::QueryState; | ||
use crate::ty::query::queries; | ||
use crate::ty::TyCtxt; | ||
|
||
use std::any::type_name; | ||
use std::mem; | ||
|
||
#[derive(Clone)] | ||
struct QueryStats { | ||
name: &'static str, | ||
cache_hits: usize, | ||
key_size: usize, | ||
key_type: &'static str, | ||
value_size: usize, | ||
value_type: &'static str, | ||
entry_count: usize, | ||
} | ||
|
||
fn stats<'tcx, Q: QueryAccessors<'tcx>>( | ||
name: &'static str, | ||
map: &QueryState<'tcx, Q>, | ||
) -> QueryStats { | ||
QueryStats { | ||
name, | ||
#[cfg(debug_assertions)] | ||
cache_hits: map.cache_hits, | ||
#[cfg(not(debug_assertions))] | ||
cache_hits: 0, | ||
key_size: mem::size_of::<Q::Key>(), | ||
key_type: type_name::<Q::Key>(), | ||
value_size: mem::size_of::<Q::Value>(), | ||
value_type: type_name::<Q::Value>(), | ||
entry_count: map.iter_results(|results| results.count()), | ||
} | ||
} | ||
|
||
pub fn print_stats(tcx: TyCtxt<'_>) { | ||
let queries = query_stats(tcx); | ||
|
||
if cfg!(debug_assertions) { | ||
let hits: usize = queries.iter().map(|s| s.cache_hits).sum(); | ||
let results: usize = queries.iter().map(|s| s.entry_count).sum(); | ||
println!("\nQuery cache hit rate: {}", hits as f64 / (hits + results) as f64); | ||
} | ||
|
||
let mut query_key_sizes = queries.clone(); | ||
query_key_sizes.sort_by_key(|q| q.key_size); | ||
println!("\nLarge query keys:"); | ||
for q in query_key_sizes.iter().rev().filter(|q| q.key_size > 8) { | ||
println!(" {} - {} 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); | ||
println!("\nLarge query values:"); | ||
for q in query_value_sizes.iter().rev().filter(|q| q.value_size > 8) { | ||
println!(" {} - {} x {} - {}", q.name, q.value_size, q.entry_count, q.value_type); | ||
} | ||
|
||
if cfg!(debug_assertions) { | ||
let mut query_cache_hits = queries.clone(); | ||
query_cache_hits.sort_by_key(|q| q.cache_hits); | ||
println!("\nQuery cache hits:"); | ||
for q in query_cache_hits.iter().rev() { | ||
println!( | ||
" {} - {} ({}%)", | ||
q.name, | ||
q.cache_hits, | ||
q.cache_hits as f64 / (q.cache_hits + q.entry_count) as f64 | ||
); | ||
} | ||
} | ||
|
||
let mut query_value_count = queries.clone(); | ||
query_value_count.sort_by_key(|q| q.entry_count); | ||
println!("\nQuery value count:"); | ||
for q in query_value_count.iter().rev() { | ||
println!(" {} - {}", q.name, q.entry_count); | ||
} | ||
} | ||
|
||
macro_rules! print_stats { | ||
(<$tcx:tt> $($category:tt { | ||
$($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident: $node:ident($K:ty) -> $V:ty,)* | ||
},)*) => { | ||
fn query_stats(tcx: TyCtxt<'_>) -> Vec<QueryStats> { | ||
let mut queries = Vec::new(); | ||
|
||
$($( | ||
queries.push(stats::<queries::$name<'_>>( | ||
stringify!($name), | ||
&tcx.queries.$name, | ||
)); | ||
)*)* | ||
|
||
queries | ||
} | ||
} | ||
} | ||
|
||
rustc_query_append! { [print_stats!][<'tcx>] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters