Skip to content

Commit 01491e2

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Do not allow calling gen_profile twice
Summary: In the future `gen_profile` may "take" profiling data. So explicitly prohibit calling `gen_profile` twice. Reviewed By: bobyangyf Differential Revision: D38646592 fbshipit-source-id: 45fb2afe0239fd384a51549d981e45f01d37421a
1 parent 0a32bc4 commit 01491e2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

starlark/src/eval/runtime/evaluator.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ pub(crate) enum EvaluatorError {
7878
ProfilingNotEnabled,
7979
#[error("Cannot generate profile because only profiling instrumentation enabled")]
8080
InstrumentationEnabled,
81+
#[error("Profile data already collected")]
82+
ProfileDataAlreadyCollected,
8183
#[error("Can't call `write_heap_profile` unless you first call `enable_heap_profile`.")]
8284
HeapProfilingNotEnabled,
8385
#[error("Can't call `write_stmt_profile` unless you first call `enable_stmt_profile`.")]
@@ -313,8 +315,12 @@ impl<'v, 'a> Evaluator<'v, 'a> {
313315
ProfileOrInstrumentationMode::Instrumentation(..) => {
314316
return Err(EvaluatorError::InstrumentationEnabled.into());
315317
}
316-
ProfileOrInstrumentationMode::Profile(mode) => mode,
318+
ProfileOrInstrumentationMode::Collected => {
319+
return Err(EvaluatorError::ProfileDataAlreadyCollected.into());
320+
}
321+
ProfileOrInstrumentationMode::Profile(mode) => mode.dupe(),
317322
};
323+
self.profile_or_instrumentation_mode = ProfileOrInstrumentationMode::Collected;
318324
match mode {
319325
ProfileMode::HeapSummary => self
320326
.heap_profile

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub(crate) enum ProfileOrInstrumentationMode {
2424
None,
2525
Instrumentation(ProfileMode),
2626
Profile(ProfileMode),
27+
Collected,
2728
}
2829

2930
impl Default for ProfileOrInstrumentationMode {

0 commit comments

Comments
 (0)