mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
Report vfs memory usage in status command
This commit is contained in:
parent
f00dcf9a69
commit
f2295cda42
3 changed files with 14 additions and 2 deletions
|
@ -440,6 +440,10 @@ impl GlobalStateSnapshot {
|
||||||
ProjectWorkspace::DetachedFiles { .. } => None,
|
ProjectWorkspace::DetachedFiles { .. } => None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn vfs_memory_usage(&self) -> usize {
|
||||||
|
self.vfs.read().0.memory_usage()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn file_id_to_url(vfs: &vfs::Vfs, id: FileId) -> Url {
|
pub(crate) fn file_id_to_url(vfs: &vfs::Vfs, id: FileId) -> Url {
|
||||||
|
|
|
@ -103,6 +103,7 @@ pub(crate) fn handle_analyzer_status(
|
||||||
.collect::<Vec<&AbsPath>>()
|
.collect::<Vec<&AbsPath>>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
format_to!(buf, "\nVfs memory usage: {}\n", snap.vfs_memory_usage());
|
||||||
buf.push_str("\nAnalysis:\n");
|
buf.push_str("\nAnalysis:\n");
|
||||||
buf.push_str(
|
buf.push_str(
|
||||||
&snap
|
&snap
|
||||||
|
|
|
@ -139,6 +139,11 @@ impl Vfs {
|
||||||
self.get(file_id).as_deref().unwrap()
|
self.get(file_id).as_deref().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the overall memory usage for the stored files.
|
||||||
|
pub fn memory_usage(&self) -> usize {
|
||||||
|
self.data.iter().flatten().map(|d| d.capacity()).sum()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns an iterator over the stored ids and their corresponding paths.
|
/// Returns an iterator over the stored ids and their corresponding paths.
|
||||||
///
|
///
|
||||||
/// This will skip deleted files.
|
/// This will skip deleted files.
|
||||||
|
@ -158,7 +163,7 @@ impl Vfs {
|
||||||
///
|
///
|
||||||
/// If the path does not currently exists in the `Vfs`, allocates a new
|
/// If the path does not currently exists in the `Vfs`, allocates a new
|
||||||
/// [`FileId`] for it.
|
/// [`FileId`] for it.
|
||||||
pub fn set_file_contents(&mut self, path: VfsPath, contents: Option<Vec<u8>>) -> bool {
|
pub fn set_file_contents(&mut self, path: VfsPath, mut contents: Option<Vec<u8>>) -> bool {
|
||||||
let file_id = self.alloc_file_id(path);
|
let file_id = self.alloc_file_id(path);
|
||||||
let change_kind = match (self.get(file_id), &contents) {
|
let change_kind = match (self.get(file_id), &contents) {
|
||||||
(None, None) => return false,
|
(None, None) => return false,
|
||||||
|
@ -167,7 +172,9 @@ impl Vfs {
|
||||||
(Some(_), None) => ChangeKind::Delete,
|
(Some(_), None) => ChangeKind::Delete,
|
||||||
(Some(_), Some(_)) => ChangeKind::Modify,
|
(Some(_), Some(_)) => ChangeKind::Modify,
|
||||||
};
|
};
|
||||||
|
if let Some(contents) = &mut contents {
|
||||||
|
contents.shrink_to_fit();
|
||||||
|
}
|
||||||
*self.get_mut(file_id) = contents;
|
*self.get_mut(file_id) = contents;
|
||||||
self.changes.push(ChangedFile { file_id, change_kind });
|
self.changes.push(ChangedFile { file_id, change_kind });
|
||||||
true
|
true
|
||||||
|
|
Loading…
Reference in a new issue