Skip to content

Commit dd1e76b

Browse files
ndmitchellfacebook-github-bot
authored andcommitted
Expose allocated_bytes on Heap/FrozenHeap
Summary: Useful to cheaply see how big heaps are Reviewed By: krallin Differential Revision: D30933010 fbshipit-source-id: 05c81261c844ce57d113c6b9ad98d3147e0d9606
1 parent 934f78c commit dd1e76b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

starlark/src/values/layout/heap.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ impl PartialEq<FrozenHeapRef> for FrozenHeapRef {
127127
impl Eq for FrozenHeapRef {}
128128

129129
impl FrozenHeapRef {
130+
/// Number of bytes allocated on this heap, not including any memory
131+
/// represented by [`extra_memory`](crate::values::StarlarkValue::extra_memory).
132+
pub fn allocated_bytes(&self) -> usize {
133+
self.0.arena.allocated_bytes()
134+
}
135+
130136
/// Obtain a summary of how much memory is currently allocated by this heap.
131137
/// Doesn't include the heaps it keeps alive by reference.
132138
pub fn allocated_summary(&self) -> HeapSummary {
@@ -192,6 +198,12 @@ impl FrozenHeap {
192198
self.alloc_raw(simple(val))
193199
}
194200

201+
/// Number of bytes allocated on this heap, not including any memory
202+
/// represented by [`extra_memory`](crate::values::StarlarkValue::extra_memory).
203+
pub fn allocated_bytes(&self) -> usize {
204+
self.arena.allocated_bytes()
205+
}
206+
195207
/// Obtain a summary of how much memory is currently allocated by this heap.
196208
pub fn allocated_summary(&self) -> HeapSummary {
197209
self.arena.allocated_summary()
@@ -271,10 +283,13 @@ impl Heap {
271283
Self::default()
272284
}
273285

274-
pub(crate) fn allocated_bytes(&self) -> usize {
286+
/// Number of bytes allocated on this heap, not including any memory
287+
/// represented by [`extra_memory`](crate::values::StarlarkValue::extra_memory).
288+
pub fn allocated_bytes(&self) -> usize {
275289
self.arena.borrow().allocated_bytes()
276290
}
277291

292+
/// Only those allocated on the inline heap (mostly strings)
278293
pub(crate) fn allocated_bytes_inline(&self) -> usize {
279294
self.arena.borrow().allocated_bytes_inline()
280295
}

0 commit comments

Comments
 (0)