|
1 | 1 | //! Applies changes to the IDE state transactionally.
|
2 | 2 |
|
3 | 3 | use base_db::{
|
4 |
| - salsa::{Database, Durability}, |
| 4 | + salsa::{ |
| 5 | + debug::{DebugQueryTable, TableEntry}, |
| 6 | + Database, Durability, Query, QueryTable, |
| 7 | + }, |
5 | 8 | Change, SourceRootId,
|
6 | 9 | };
|
7 | 10 | use profile::{memory_usage, Bytes};
|
@@ -47,16 +50,37 @@ impl RootDatabase {
|
47 | 50 | // | VS Code | **rust-analyzer: Memory Usage (Clears Database)**
|
48 | 51 | // |===
|
49 | 52 | // image::https://user-images.githubusercontent.com/48062697/113065592-08559f00-91b1-11eb-8c96-64b88068ec02.gif[]
|
50 |
| - pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> { |
51 |
| - let mut acc: Vec<(String, Bytes)> = vec![]; |
| 53 | + pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes, usize)> { |
| 54 | + let mut acc: Vec<(String, Bytes, usize)> = vec![]; |
| 55 | + |
| 56 | + fn collect_query_count<'q, Q>(table: &QueryTable<'q, Q>) -> usize |
| 57 | + where |
| 58 | + QueryTable<'q, Q>: DebugQueryTable, |
| 59 | + Q: Query, |
| 60 | + <Q as Query>::Storage: 'q, |
| 61 | + { |
| 62 | + struct EntryCounter(usize); |
| 63 | + impl<K, V> FromIterator<TableEntry<K, V>> for EntryCounter { |
| 64 | + fn from_iter<T>(iter: T) -> EntryCounter |
| 65 | + where |
| 66 | + T: IntoIterator<Item = TableEntry<K, V>>, |
| 67 | + { |
| 68 | + EntryCounter(iter.into_iter().count()) |
| 69 | + } |
| 70 | + } |
| 71 | + table.entries::<EntryCounter>().0 |
| 72 | + } |
| 73 | + |
52 | 74 | macro_rules! purge_each_query {
|
53 | 75 | ($($q:path)*) => {$(
|
54 | 76 | let before = memory_usage().allocated;
|
55 |
| - $q.in_db(self).purge(); |
| 77 | + let table = $q.in_db(self); |
| 78 | + let count = collect_query_count(&table); |
| 79 | + table.purge(); |
56 | 80 | let after = memory_usage().allocated;
|
57 | 81 | let q: $q = Default::default();
|
58 | 82 | let name = format!("{:?}", q);
|
59 |
| - acc.push((name, before - after)); |
| 83 | + acc.push((name, before - after, count)); |
60 | 84 | )*}
|
61 | 85 | }
|
62 | 86 | purge_each_query![
|
|
0 commit comments