Skip to content

Commit 5c76acf

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Store AggregateHeapProfileInfo in ProfileData
Summary: It is merged in the following diff D38681779. Reviewed By: milend Differential Revision: D38681732 fbshipit-source-id: 2bc675d7820b3dcaf7468263709b4eb4d9be85d2
1 parent fc7f50f commit 5c76acf

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

starlark/src/eval/runtime/profile/data.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,19 @@ use anyhow::Context;
2323
use crate::eval::runtime::profile::bc::BcPairsProfileData;
2424
use crate::eval::runtime::profile::bc::BcProfileData;
2525
use crate::eval::ProfileMode;
26+
use crate::values::AggregateHeapProfileInfo;
27+
28+
#[derive(Debug, thiserror::Error)]
29+
enum ProfileDataError {
30+
#[error("Profile data is not consistent with profile mode (internal error)")]
31+
ProfileDataNotConsistent,
32+
}
2633

2734
#[derive(Clone, Debug)]
2835
pub(crate) enum ProfileDataImpl {
2936
Bc(Box<BcProfileData>),
3037
BcPairs(BcPairsProfileData),
38+
AggregateHeapProfileInfo(Box<AggregateHeapProfileInfo>),
3139
Other(String),
3240
}
3341

@@ -49,10 +57,21 @@ impl ProfileData {
4957

5058
/// Generate a string with profile data (e.g. CSV or flamegraph, depending on profile type).
5159
pub fn gen(&self) -> anyhow::Result<String> {
52-
match &self.profile {
53-
ProfileDataImpl::Other(profile) => Ok(profile.clone()),
54-
ProfileDataImpl::Bc(bc) => Ok(bc.gen_csv()),
55-
ProfileDataImpl::BcPairs(bc_pairs) => Ok(bc_pairs.gen_csv()),
60+
match (&self.profile, &self.profile_mode) {
61+
(ProfileDataImpl::Other(profile), _) => Ok(profile.clone()),
62+
(ProfileDataImpl::Bc(bc), _) => Ok(bc.gen_csv()),
63+
(ProfileDataImpl::BcPairs(bc_pairs), _) => Ok(bc_pairs.gen_csv()),
64+
(
65+
ProfileDataImpl::AggregateHeapProfileInfo(profile),
66+
ProfileMode::HeapFlameRetained | ProfileMode::HeapFlameAllocated,
67+
) => Ok(profile.gen_flame_graph()),
68+
(
69+
ProfileDataImpl::AggregateHeapProfileInfo(profile),
70+
ProfileMode::HeapSummaryRetained | ProfileMode::HeapSummaryAllocated,
71+
) => Ok(profile.gen_summary_csv()),
72+
(ProfileDataImpl::AggregateHeapProfileInfo(_), _) => {
73+
Err(ProfileDataError::ProfileDataNotConsistent.into())
74+
}
5675
}
5776
}
5877

starlark/src/eval/runtime/profile/heap.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::fmt::Debug;
2020
use gazebo::dupe::Dupe;
2121

2222
use crate::eval::runtime::profile::data::ProfileData;
23+
use crate::eval::runtime::profile::data::ProfileDataImpl;
2324
use crate::eval::ProfileMode;
2425
use crate::values::layout::heap::profile::aggregated::AggregateHeapProfileInfo;
2526
use crate::values::Heap;
@@ -87,12 +88,18 @@ impl HeapProfile {
8788

8889
fn write_flame_heap_profile(heap: &Heap) -> ProfileData {
8990
let stacks = AggregateHeapProfileInfo::collect(heap, None);
90-
ProfileData::new(ProfileMode::HeapFlameAllocated, stacks.gen_flame_graph())
91+
ProfileData {
92+
profile_mode: ProfileMode::HeapFlameAllocated,
93+
profile: ProfileDataImpl::AggregateHeapProfileInfo(box stacks),
94+
}
9195
}
9296

9397
fn write_summarized_heap_profile(heap: &Heap) -> ProfileData {
9498
let stacks = AggregateHeapProfileInfo::collect(heap, None);
95-
ProfileData::new(ProfileMode::HeapSummaryAllocated, stacks.gen_summary_csv())
99+
ProfileData {
100+
profile_mode: ProfileMode::HeapSummaryAllocated,
101+
profile: ProfileDataImpl::AggregateHeapProfileInfo(box stacks),
102+
}
96103
}
97104
}
98105

0 commit comments

Comments
 (0)