Skip to content

Commit 1f83759

Browse files
stepanchegfacebook-github-bot
authored andcommitted
ProfileData::merge
Summary: API to merge `ProfileData` values. In this diff it returns error unconditionally. Bytecode profile is merged in the following diff D38681490. Reviewed By: bobyangyf Differential Revision: D38681130 fbshipit-source-id: 0c8fc536603f1e62aea9e074f80e34e221385b5f
1 parent 2a62eea commit 1f83759

File tree

1 file changed

+24
-0
lines changed
  • starlark/src/eval/runtime/profile

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::fs;
1919
use std::path::Path;
2020

2121
use anyhow::Context;
22+
use gazebo::prelude::*;
2223

2324
use crate::eval::runtime::profile::bc::BcPairsProfileData;
2425
use crate::eval::runtime::profile::bc::BcProfileData;
@@ -29,6 +30,12 @@ use crate::values::AggregateHeapProfileInfo;
2930
enum ProfileDataError {
3031
#[error("Profile data is not consistent with profile mode (internal error)")]
3132
ProfileDataNotConsistent,
33+
#[error("Empty profile list cannot be merged")]
34+
EmptyProfileList,
35+
#[error("Different profile modes in profile")]
36+
DifferentProfileModes,
37+
#[error("Merge of profile data for profile mode `{0}` is not implemented")]
38+
MergeNotImplemented(ProfileMode),
3239
}
3340

3441
#[derive(Clone, Debug)]
@@ -86,4 +93,21 @@ impl ProfileData {
8693
})?;
8794
Ok(())
8895
}
96+
97+
/// Merge profiles (aggregate).
98+
pub fn merge<'a>(
99+
profiles: impl IntoIterator<Item = &'a ProfileData>,
100+
) -> anyhow::Result<ProfileData> {
101+
let profiles = Vec::from_iter(profiles);
102+
let profile_mode = match profiles.first() {
103+
None => return Err(ProfileDataError::EmptyProfileList.into()),
104+
Some(p) => p.profile_mode.dupe(),
105+
};
106+
for p in &profiles {
107+
if p.profile_mode != profile_mode {
108+
return Err(ProfileDataError::DifferentProfileModes.into());
109+
}
110+
}
111+
Err(ProfileDataError::MergeNotImplemented(profile_mode.dupe()).into())
112+
}
89113
}

0 commit comments

Comments
 (0)