-
Notifications
You must be signed in to change notification settings - Fork 79
Expose a method to return the memory usage of all dynamic atoms. #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use malloc_size_of_derive::MallocSizeOf; | ||
use malloc_size_of::{MallocSizeOf as _, MallocSizeOfOps, MallocShallowSizeOf}; | ||
Comment on lines
+10
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These imports need to be |
||
use parking_lot::Mutex; | ||
use std::borrow::Cow; | ||
use std::mem; | ||
|
@@ -22,6 +24,20 @@ pub(crate) struct Set { | |
buckets: Box<[Mutex<Option<Box<Entry>>>]>, | ||
} | ||
|
||
impl Set { | ||
#[cfg(feature = "malloc_size_of")] | ||
pub(crate) fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { | ||
self.buckets.shallow_size_of(ops) + | ||
self.buckets | ||
.iter() | ||
.map(|bucket| { | ||
bucket.lock().as_ref().map_or(0, |entry| entry.size_of(ops)) | ||
}) | ||
.sum::<usize>() | ||
} | ||
} | ||
|
||
#[cfg_attr(feature = "malloc_size_of", derive(MallocSizeOf))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would personally be tempted to do a manual impl here to avoid the dep on the derive crate (but I suspect my opinion will be a minority one here so this is more of a "noted dissenting opinion" rather than a request for a change). |
||
pub(crate) struct Entry { | ||
pub(crate) string: Box<str>, | ||
pub(crate) hash: u32, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use of
dep:
syntax requires Rust1.71
, so we should bump therust-version
if we're going to do this. I think this should be fine forstring_cache
? But perhaps worth noting I had to revert to the older feature syntax for crates likeeuclid
that have lower MSRVs.