Skip to content

Commit 5bbc2ec

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Make AggregateHeapProfileInfo public
Summary: So a user can collect `AggregateHeapProfileInfo` from different invocations and merge them. Reviewed By: bobyangyf Differential Revision: D38518063 fbshipit-source-id: 4d8e77bafccd1651492c0b9030fd93e3188a07ee
1 parent ebee265 commit 5bbc2ec

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

starlark/src/environment/modules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl FrozenModule {
218218
}
219219

220220
/// Retained memory info, or error if not enabled.
221-
fn aggregated_heap_profile_info(&self) -> anyhow::Result<&AggregateHeapProfileInfo> {
221+
pub fn aggregated_heap_profile_info(&self) -> anyhow::Result<&AggregateHeapProfileInfo> {
222222
self.module
223223
.0
224224
.heap_profile

starlark/src/values/layout/heap/profile/aggregated.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,13 @@ impl<'c> StackFrameWithContext<'c> {
286286
}
287287
}
288288

289+
/// Aggregated heap profiling data when heap profiling is enabled.
290+
///
291+
/// Can be:
292+
/// * written as CSV or flamegraph
293+
/// * merged with another data
289294
#[derive(Clone)]
290-
pub(crate) struct AggregateHeapProfileInfo {
295+
pub struct AggregateHeapProfileInfo {
291296
pub(crate) strings: StringIndex,
292297
pub(crate) root: StackFrame,
293298
/// String `"TOTALS"`. It is needed in heap summary output.
@@ -335,8 +340,8 @@ impl AggregateHeapProfileInfo {
335340
}
336341
}
337342

338-
#[allow(dead_code)] // TODO: used later.
339-
fn merge<'a>(
343+
/// Merge aggregated heap profile from multiple sources (e.g. from several runs).
344+
pub fn merge<'a>(
340345
profiles: impl IntoIterator<Item = &'a AggregateHeapProfileInfo>,
341346
) -> AggregateHeapProfileInfo {
342347
let mut strings = StringIndex::default();
@@ -355,13 +360,14 @@ impl AggregateHeapProfileInfo {
355360
}
356361

357362
/// Write this out recursively to a file.
358-
pub(crate) fn gen_flame_graph(&self) -> String {
363+
pub fn gen_flame_graph(&self) -> String {
359364
let mut writer = FlameGraphWriter::new();
360365
self.root().write_flame_graph(&mut writer, &mut vec![]);
361366
writer.finish()
362367
}
363368

364-
pub(crate) fn gen_summary_csv(&self) -> String {
369+
/// Write per-function summary in CSV format.
370+
pub fn gen_summary_csv(&self) -> String {
365371
HeapSummaryByFunction::init(self).gen_csv(self)
366372
}
367373
}

starlark/src/values/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub use crate::values::layout::heap::heap_type::FrozenHeap;
4949
pub use crate::values::layout::heap::heap_type::FrozenHeapRef;
5050
pub use crate::values::layout::heap::heap_type::Heap;
5151
pub use crate::values::layout::heap::heap_type::Tracer;
52+
pub use crate::values::layout::heap::profile::aggregated::AggregateHeapProfileInfo;
5253
pub use crate::values::layout::identity::ValueIdentity;
5354
pub use crate::values::layout::static_string::constant_string;
5455
pub use crate::values::layout::static_string::StarlarkStrNRepr;

0 commit comments

Comments
 (0)