Skip to content

Commit d019c5c

Browse files
committed
Measure memory usage of the Glean global object
1 parent be9be3d commit d019c5c

File tree

6 files changed

+31
-17
lines changed

6 files changed

+31
-17
lines changed

Cargo.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glean-core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ maintenance = { status = "actively-developed" }
3030
[dependencies]
3131
serde = { version = "1.0.104", features = ["derive"] }
3232
serde_json = "1.0.44"
33-
rkv = { version = "0.20.0", default-features = false }
33+
rkv = { version = "0.20.0", default-features = false, features = ["malloc-size-of"]}
3434
bincode = "1.2.1"
3535
log = "0.4.8"
3636
uuid = { version = "1.0", features = ["v4"] }
@@ -44,7 +44,7 @@ uniffi = { version = "0.29.3", default-features = false }
4444
time = "0.3"
4545
env_logger = { version = "0.10.0", default-features = false, optional = true }
4646
malloc_size_of_derive = "0.1.3"
47-
malloc_size_of = { version = "0.2.1", package = "wr_malloc_size_of", default-features = false, features = ["once_cell"] }
47+
malloc_size_of = { version = "0.2.2", package = "wr_malloc_size_of", default-features = false, features = ["once_cell"] }
4848

4949
[target.'cfg(target_os = "android")'.dependencies]
5050
android_logger = { version = "0.12.0", default-features = false }

glean-core/rlb/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,5 +382,12 @@ pub fn test_get_distribution() -> DistributionMetrics {
382382
glean_core::glean_test_get_distribution()
383383
}
384384

385+
/// Return the heap usage of the `Glean` object and all descendant heap-allocated structures.
386+
///
387+
/// Value is in bytes.
388+
pub fn alloc_size(ops: &mut malloc_size_of::MallocSizeOfOps) -> usize {
389+
glean_core::alloc_size(ops)
390+
}
391+
385392
#[cfg(test)]
386393
mod test;

glean-core/src/database/mod.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,30 +145,27 @@ pub struct Database {
145145
}
146146

147147
impl MallocSizeOf for Database {
148-
fn size_of(&self, _ops: &mut malloc_size_of::MallocSizeOfOps) -> usize {
148+
fn size_of(&self, ops: &mut malloc_size_of::MallocSizeOfOps) -> usize {
149149
// TODO(bug 1960592): Fill in gaps.
150150

151-
/*
152151
let mut n = 0;
153152

154-
n += 0; // self.rkv.size_of(ops) -- not implemented.
155-
n += 0; // self.user_store.size_of(ops) -- not implemented.
153+
n += self.rkv.size_of(ops);
154+
n += self.user_store.size_of(ops);
155+
n += self.ping_store.size_of(ops);
156+
n += self.application_store.size_of(ops);
156157

157158
n += self
158159
.ping_lifetime_data
159160
.as_ref()
160-
.map(|_data| {
161+
.map(|data| {
161162
// TODO(bug 1960592): servo's malloc_size_of implements it for BTreeMap.
162-
//let lock = data.read().unwrap();
163-
//(*lock).size_of(ops)
164-
0
163+
let lock = data.read().unwrap();
164+
(*lock).size_of(ops)
165165
})
166166
.unwrap_or(0);
167167

168168
n
169-
*/
170-
171-
0
172169
}
173170
}
174171

glean-core/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,14 @@ fn initialize_inner(
577577
}
578578
}
579579

580+
/// Return the heap usage of the `Glean` object and all descendant heap-allocated structures.
581+
///
582+
/// Value is in bytes.
583+
pub fn alloc_size(ops: &mut malloc_size_of::MallocSizeOfOps) -> usize {
584+
use malloc_size_of::MallocSizeOf;
585+
core::with_glean(|glean| glean.size_of(ops))
586+
}
587+
580588
/// TEST ONLY FUNCTION
581589
/// Waits on all the glean.init threads' join handles.
582590
pub fn join_init() {

supply-chain/imports.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ user-login = "epage"
257257
user-name = "Ed Page"
258258

259259
[[publisher.wr_malloc_size_of]]
260-
version = "0.2.1"
261-
when = "2025-05-07"
260+
version = "0.2.2"
261+
when = "2025-06-24"
262262
user-id = 48
263263
user-login = "badboy"
264264
user-name = "Jan-Erik Rediger"

0 commit comments

Comments
 (0)