Skip to content

Commit 5915f2b

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Remove redundant mode param in gen_profile
Summary: Profile mode is specified in `enable_profile` call, and passing it again in `gen_profile` is: * redundant * was not verified that it was passed consistently with param in `enable_profile` Reviewed By: bobyangyf Differential Revision: D38551069 fbshipit-source-id: 876944f88397a3cbc03eeecb6e4c89eb8bb96e9f
1 parent 960c1ac commit 5915f2b

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

starlark/src/eval/runtime/evaluator.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ use crate::values::ValueLike;
7575

7676
#[derive(Error, Debug)]
7777
pub(crate) enum EvaluatorError {
78+
#[error("Profiling was not enabled")]
79+
ProfilingNotEnabled,
80+
#[error("Cannot generate profile because only profiling instrumentation enabled")]
81+
InstrumentationEnabled,
7882
#[error("Can't call `write_heap_profile` unless you first call `enable_heap_profile`.")]
7983
HeapProfilingNotEnabled,
8084
#[error("Can't call `write_stmt_profile` unless you first call `enable_stmt_profile`.")]
@@ -296,20 +300,25 @@ impl<'v, 'a> Evaluator<'v, 'a> {
296300

297301
/// Write a profile to a file.
298302
/// Only valid if corresponding profiler was enabled.
299-
pub fn write_profile<P: AsRef<Path>>(
300-
&self,
301-
mode: &ProfileMode,
302-
filename: P,
303-
) -> anyhow::Result<()> {
304-
let profile = self.gen_profile(mode)?;
303+
pub fn write_profile<P: AsRef<Path>>(&self, filename: P) -> anyhow::Result<()> {
304+
let profile = self.gen_profile()?;
305305
fs::write(filename.as_ref(), profile)
306306
.with_context(|| format!("writing profile to `{}`", filename.as_ref().display()))?;
307307
Ok(())
308308
}
309309

310310
/// Generate profile for a given mode.
311311
/// Only valid if corresponding profiler was enabled.
312-
pub fn gen_profile(&self, mode: &ProfileMode) -> anyhow::Result<String> {
312+
pub fn gen_profile(&self) -> anyhow::Result<String> {
313+
let mode = match &self.profile_or_instrumentation_mode {
314+
ProfileOrInstrumentationMode::None => {
315+
return Err(EvaluatorError::ProfilingNotEnabled.into());
316+
}
317+
ProfileOrInstrumentationMode::Instrumentation(..) => {
318+
return Err(EvaluatorError::InstrumentationEnabled.into());
319+
}
320+
ProfileOrInstrumentationMode::Profile(mode) => mode,
321+
};
313322
match mode {
314323
ProfileMode::HeapSummary => self
315324
.heap_profile

0 commit comments

Comments
 (0)