Skip to content

Commit d006ecb

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Store ProfileMode in ProfileData
Summary: Used later (D38681490). Also may be helpful when debugging. Reviewed By: milend Differential Revision: D38680885 fbshipit-source-id: 724f8dc4773808583c478414a4dcfd50e343a789
1 parent 01491e2 commit d006ecb

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed

starlark/src/eval/runtime/evaluator.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,10 @@ impl<'v, 'a> Evaluator<'v, 'a> {
337337
.stmt_profile
338338
.gen()
339339
.ok_or_else(|| EvaluatorError::StmtProfilingNotEnabled.into()),
340-
ProfileMode::Bytecode | ProfileMode::BytecodePairs => {
341-
self.bc_profile.gen_csv().map(ProfileData::new)
342-
}
340+
ProfileMode::Bytecode | ProfileMode::BytecodePairs => self
341+
.bc_profile
342+
.gen_csv()
343+
.map(|csv| ProfileData::new(mode, csv)),
343344
ProfileMode::TimeFlame => self
344345
.flame_profile
345346
.gen()

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,22 @@ use std::path::Path;
2020

2121
use anyhow::Context;
2222

23+
use crate::eval::ProfileMode;
24+
2325
/// Collected profiling data.
2426
#[derive(Clone, Debug)]
2527
pub struct ProfileData {
28+
profile_mode: ProfileMode,
2629
/// Serialized to text (e.g. CSV or flamegraph).
2730
profile: String,
2831
}
2932

3033
impl ProfileData {
31-
pub(crate) fn new(profile: String) -> ProfileData {
32-
ProfileData { profile }
34+
pub(crate) fn new(profile_mode: ProfileMode, profile: String) -> ProfileData {
35+
ProfileData {
36+
profile_mode,
37+
profile,
38+
}
3339
}
3440

3541
/// Generate a string with profile data (e.g. CSV or flamegraph, depending on profile type).
@@ -39,8 +45,13 @@ impl ProfileData {
3945

4046
/// Write to a file.
4147
pub fn write(&self, path: &Path) -> anyhow::Result<()> {
42-
fs::write(path, &self.profile)
43-
.with_context(|| format!("write profile data to `{}`", path.display()))?;
48+
fs::write(path, &self.profile).with_context(|| {
49+
format!(
50+
"write profile `{}` data to `{}`",
51+
self.profile_mode,
52+
path.display()
53+
)
54+
})?;
4455
Ok(())
4556
}
4657
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate as starlark;
2626
use crate::eval::runtime::profile::data::ProfileData;
2727
use crate::eval::runtime::profile::flamegraph::FlameGraphWriter;
2828
use crate::eval::runtime::small_duration::SmallDuration;
29+
use crate::eval::ProfileMode;
2930
use crate::values::layout::pointer::RawPointer;
3031
use crate::values::Trace;
3132
use crate::values::Tracer;
@@ -177,6 +178,9 @@ impl<'v> FlameProfile<'v> {
177178
// root;calls1;calls2 1
178179
// All the numbers at the end must be whole numbers (we use milliseconds)
179180
let names = x.values.map(|x| x.to_repr());
180-
ProfileData::new(Stacks::new(&names, &x.frames).render())
181+
ProfileData::new(
182+
ProfileMode::TimeFlame,
183+
Stacks::new(&names, &x.frames).render(),
184+
)
181185
}
182186
}

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

Lines changed: 3 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::ProfileMode;
2324
use crate::values::layout::heap::profile::aggregated::AggregateHeapProfileInfo;
2425
use crate::values::Heap;
2526
use crate::values::Value;
@@ -77,12 +78,12 @@ impl HeapProfile {
7778

7879
fn write_flame_heap_profile(heap: &Heap) -> ProfileData {
7980
let stacks = AggregateHeapProfileInfo::collect(heap, None);
80-
ProfileData::new(stacks.gen_flame_graph())
81+
ProfileData::new(ProfileMode::HeapFlame, stacks.gen_flame_graph())
8182
}
8283

8384
fn write_summarized_heap_profile(heap: &Heap) -> ProfileData {
8485
let stacks = AggregateHeapProfileInfo::collect(heap, None);
85-
ProfileData::new(stacks.gen_summary_csv())
86+
ProfileData::new(ProfileMode::HeapSummary, stacks.gen_summary_csv())
8687
}
8788
}
8889

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::codemap::Span;
3232
use crate::eval::runtime::profile::csv::CsvWriter;
3333
use crate::eval::runtime::profile::data::ProfileData;
3434
use crate::eval::runtime::small_duration::SmallDuration;
35+
use crate::eval::ProfileMode;
3536

3637
#[derive(Debug, thiserror::Error)]
3738
enum StmtProfileError {
@@ -186,7 +187,7 @@ impl StmtProfile {
186187
let now = Instant::now();
187188
self.0
188189
.as_ref()
189-
.map(|data| ProfileData::new(data.write_to_string(now)))
190+
.map(|data| ProfileData::new(ProfileMode::Statement, data.write_to_string(now)))
190191
}
191192

192193
pub(crate) fn coverage(&self) -> anyhow::Result<HashSet<ResolvedFileSpan>> {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::collections::SmallMap;
2323
use crate::eval::runtime::profile::csv::CsvWriter;
2424
use crate::eval::runtime::profile::data::ProfileData;
2525
use crate::eval::runtime::small_duration::SmallDuration;
26+
use crate::eval::ProfileMode;
2627
use crate::values::FrozenStringValue;
2728

2829
#[derive(Default, Debug)]
@@ -65,7 +66,7 @@ impl TypecheckProfile {
6566
if !self.enabled {
6667
return None;
6768
}
68-
Some(ProfileData::new(self.gen_csv()))
69+
Some(ProfileData::new(ProfileMode::Typecheck, self.gen_csv()))
6970
}
7071
}
7172

0 commit comments

Comments
 (0)