2019-07-04 15:05:17 -05:00
|
|
|
use std::{fmt, iter::FromIterator, sync::Arc};
|
2019-01-25 07:10:34 -06:00
|
|
|
|
2019-07-04 15:05:17 -05:00
|
|
|
use hir::MacroFile;
|
2019-01-22 15:15:03 -06:00
|
|
|
use ra_db::{
|
2019-07-04 15:05:17 -05:00
|
|
|
salsa::{
|
|
|
|
debug::{DebugQueryTable, TableEntry},
|
|
|
|
Database,
|
|
|
|
},
|
2019-06-01 14:11:38 -05:00
|
|
|
FileTextQuery, SourceRootId,
|
2019-01-22 15:15:03 -06:00
|
|
|
};
|
2019-07-04 15:05:17 -05:00
|
|
|
use ra_prof::{memory_usage, Bytes};
|
2019-07-18 15:19:04 -05:00
|
|
|
use ra_syntax::{ast, AstNode, Parse, SyntaxNode};
|
2019-01-22 15:15:03 -06:00
|
|
|
|
2019-01-25 08:20:52 -06:00
|
|
|
use crate::{
|
2019-07-04 15:05:17 -05:00
|
|
|
db::RootDatabase,
|
|
|
|
symbol_index::{LibrarySymbolsQuery, SymbolIndex},
|
|
|
|
FileId,
|
2019-01-25 08:20:52 -06:00
|
|
|
};
|
2019-01-22 15:15:03 -06:00
|
|
|
|
2019-01-26 11:33:33 -06:00
|
|
|
pub(crate) fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats {
|
2019-06-02 12:15:10 -05:00
|
|
|
db.query(ra_db::ParseQuery).entries::<SyntaxTreeStats>()
|
|
|
|
}
|
|
|
|
pub(crate) fn macro_syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats {
|
|
|
|
db.query(hir::db::ParseMacroQuery).entries::<SyntaxTreeStats>()
|
2019-01-26 11:33:33 -06:00
|
|
|
}
|
|
|
|
|
2019-01-22 15:15:03 -06:00
|
|
|
pub(crate) fn status(db: &RootDatabase) -> String {
|
2019-01-25 08:20:52 -06:00
|
|
|
let files_stats = db.query(FileTextQuery).entries::<FilesStats>();
|
2019-01-26 11:33:33 -06:00
|
|
|
let syntax_tree_stats = syntax_tree_stats(db);
|
2019-06-02 12:15:10 -05:00
|
|
|
let macro_syntax_tree_stats = macro_syntax_tree_stats(db);
|
2019-02-08 05:49:43 -06:00
|
|
|
let symbols_stats = db.query(LibrarySymbolsQuery).entries::<LibrarySymbolsStats>();
|
2019-01-25 08:20:52 -06:00
|
|
|
format!(
|
2019-06-02 12:15:10 -05:00
|
|
|
"{}\n{}\n{}\n{} (macros)\n\n\nmemory:\n{}\ngc {:?} seconds ago",
|
2019-01-26 11:33:33 -06:00
|
|
|
files_stats,
|
|
|
|
symbols_stats,
|
|
|
|
syntax_tree_stats,
|
2019-06-02 12:15:10 -05:00
|
|
|
macro_syntax_tree_stats,
|
2019-06-30 05:30:17 -05:00
|
|
|
memory_usage(),
|
2019-01-26 11:33:33 -06:00
|
|
|
db.last_gc.elapsed().as_secs(),
|
2019-01-25 08:20:52 -06:00
|
|
|
)
|
2019-01-25 07:10:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct FilesStats {
|
|
|
|
total: usize,
|
2019-01-25 08:20:52 -06:00
|
|
|
size: Bytes,
|
2019-01-25 07:10:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for FilesStats {
|
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
2019-01-25 08:20:52 -06:00
|
|
|
write!(fmt, "{} ({}) files", self.total, self.size)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromIterator<TableEntry<FileId, Arc<String>>> for FilesStats {
|
|
|
|
fn from_iter<T>(iter: T) -> FilesStats
|
|
|
|
where
|
|
|
|
T: IntoIterator<Item = TableEntry<FileId, Arc<String>>>,
|
|
|
|
{
|
|
|
|
let mut res = FilesStats::default();
|
|
|
|
for entry in iter {
|
|
|
|
res.total += 1;
|
|
|
|
res.size += entry.value.unwrap().len();
|
|
|
|
}
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
2019-01-26 11:33:33 -06:00
|
|
|
pub(crate) struct SyntaxTreeStats {
|
2019-01-25 08:20:52 -06:00
|
|
|
total: usize,
|
2019-01-26 11:33:33 -06:00
|
|
|
pub(crate) retained: usize,
|
2019-01-25 08:20:52 -06:00
|
|
|
retained_size: Bytes,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for SyntaxTreeStats {
|
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
2019-02-08 05:49:43 -06:00
|
|
|
write!(fmt, "{} trees, {} ({}) retained", self.total, self.retained, self.retained_size,)
|
2019-01-25 07:10:34 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-18 14:29:20 -05:00
|
|
|
impl FromIterator<TableEntry<FileId, Parse<ast::SourceFile>>> for SyntaxTreeStats {
|
2019-06-02 12:15:10 -05:00
|
|
|
fn from_iter<T>(iter: T) -> SyntaxTreeStats
|
|
|
|
where
|
2019-07-18 14:29:20 -05:00
|
|
|
T: IntoIterator<Item = TableEntry<FileId, Parse<ast::SourceFile>>>,
|
2019-06-02 12:15:10 -05:00
|
|
|
{
|
|
|
|
let mut res = SyntaxTreeStats::default();
|
|
|
|
for entry in iter {
|
|
|
|
res.total += 1;
|
2019-07-12 11:41:13 -05:00
|
|
|
if let Some(tree) = entry.value.as_ref().map(|it| it.tree()) {
|
2019-06-02 12:15:10 -05:00
|
|
|
res.retained += 1;
|
|
|
|
res.retained_size += tree.syntax().memory_size_of_subtree();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-18 15:19:04 -05:00
|
|
|
impl FromIterator<TableEntry<MacroFile, Option<Parse<SyntaxNode>>>> for SyntaxTreeStats {
|
2019-01-25 08:20:52 -06:00
|
|
|
fn from_iter<T>(iter: T) -> SyntaxTreeStats
|
|
|
|
where
|
2019-07-18 15:19:04 -05:00
|
|
|
T: IntoIterator<Item = TableEntry<MacroFile, Option<Parse<SyntaxNode>>>>,
|
2019-01-25 08:20:52 -06:00
|
|
|
{
|
|
|
|
let mut res = SyntaxTreeStats::default();
|
|
|
|
for entry in iter {
|
|
|
|
res.total += 1;
|
2019-07-19 04:56:47 -05:00
|
|
|
if let Some(tree) = entry.value.and_then(|it| it).map(|it| it.syntax_node()) {
|
2019-01-25 08:20:52 -06:00
|
|
|
res.retained += 1;
|
2019-06-01 14:11:38 -05:00
|
|
|
res.retained_size += tree.memory_size_of_subtree();
|
2019-01-25 08:20:52 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
res
|
2019-01-25 07:10:34 -06:00
|
|
|
}
|
2019-01-25 08:20:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct LibrarySymbolsStats {
|
|
|
|
total: usize,
|
2019-01-25 12:10:28 -06:00
|
|
|
size: Bytes,
|
2019-01-25 08:20:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for LibrarySymbolsStats {
|
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
2019-01-25 12:10:28 -06:00
|
|
|
write!(fmt, "{} ({}) symbols", self.total, self.size,)
|
2019-01-25 08:20:52 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromIterator<TableEntry<SourceRootId, Arc<SymbolIndex>>> for LibrarySymbolsStats {
|
|
|
|
fn from_iter<T>(iter: T) -> LibrarySymbolsStats
|
|
|
|
where
|
|
|
|
T: IntoIterator<Item = TableEntry<SourceRootId, Arc<SymbolIndex>>>,
|
|
|
|
{
|
|
|
|
let mut res = LibrarySymbolsStats::default();
|
|
|
|
for entry in iter {
|
|
|
|
let value = entry.value.unwrap();
|
|
|
|
res.total += value.len();
|
2019-01-25 12:10:28 -06:00
|
|
|
res.size += value.memory_size();
|
2019-01-25 08:20:52 -06:00
|
|
|
}
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|