Skip to content

Commit d2570f3

Browse files
Merge pull request #1077 from Mark-Simulacrum/new-measureme
Update to new measureme
2 parents 3ca4c1e + 3fa81d1 commit d2570f3

File tree

5 files changed

+99
-30
lines changed

5 files changed

+99
-30
lines changed

Cargo.lock

+46-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async-trait = "0.1"
3838
database = { path = "../database" }
3939
bytes = "1.0"
4040
url = "2"
41-
analyzeme = { git = "https://github.com/rust-lang/measureme" }
41+
analyzeme = { git = "https://github.com/rust-lang/measureme", branch = "stable" }
4242
tar = "0.4"
4343
inferno = { version="0.10", default-features = false }
4444
mime = "0.3"

site/src/self_profile/codegen_schedule.rs

+26-10
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ fn is_interesting(name: &str) -> bool {
1919
}
2020

2121
fn by_thread(self_profile_data: Vec<u8>) -> anyhow::Result<(u64, HashMap<u32, Vec<Event>>)> {
22-
let data = ProfilingData::from_paged_buffer(self_profile_data)
22+
let data = ProfilingData::from_paged_buffer(self_profile_data, None)
2323
.map_err(|e| anyhow::format_err!("{:?}", e))?;
2424

2525
let mut start = None;
26-
for event in data.iter().filter(|e| !e.timestamp.is_instant()) {
27-
let full_event = event.to_event();
26+
for event in data
27+
.iter()
28+
.filter(|e| e.timestamp().map_or(false, |t| !t.is_instant()))
29+
{
30+
let full_event = data.to_full_event(&event);
2831
if is_interesting(&full_event.label) {
2932
if start.is_some() {
30-
start = std::cmp::min(start, Some(event.timestamp.start()));
33+
start = std::cmp::min(start, Some(event.timestamp().unwrap().start()));
3134
} else {
32-
start = Some(event.timestamp.start());
35+
start = Some(event.timestamp().unwrap().start());
3336
}
3437
}
3538
}
@@ -39,19 +42,32 @@ fn by_thread(self_profile_data: Vec<u8>) -> anyhow::Result<(u64, HashMap<u32, Ve
3942

4043
let mut end = start;
4144
let mut by_thread = HashMap::new();
42-
for event in data.iter().filter(|e| !e.timestamp.is_instant()) {
43-
let full_event = event.to_event();
45+
for event in data
46+
.iter()
47+
.filter(|e| e.timestamp().map_or(false, |t| !t.is_instant()))
48+
{
49+
let full_event = data.to_full_event(&event);
4450

4551
if is_interesting(&full_event.label) {
4652
by_thread
4753
.entry(event.thread_id)
4854
.or_insert_with(Vec::new)
4955
.push(Event {
5056
name: full_event.label.into(),
51-
start: event.timestamp.start().duration_since(start).unwrap(),
52-
end: event.timestamp.end().duration_since(start).unwrap(),
57+
start: event
58+
.timestamp()
59+
.unwrap()
60+
.start()
61+
.duration_since(start)
62+
.unwrap(),
63+
end: event
64+
.timestamp()
65+
.unwrap()
66+
.end()
67+
.duration_since(start)
68+
.unwrap(),
5369
});
54-
end = std::cmp::max(end, event.timestamp.end());
70+
end = std::cmp::max(end, event.timestamp().unwrap().end());
5571
}
5672
}
5773

site/src/self_profile/crox.rs

+25-12
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,19 @@ fn generate_thread_to_collapsed_thread_mapping(
6262
// collect start and end times for all threads
6363
let mut thread_start_and_end: HashMap<u32, (SystemTime, SystemTime)> = HashMap::default();
6464
for event in data.iter() {
65+
let timestamp = if let Some(t) = event.timestamp() {
66+
t
67+
} else {
68+
continue;
69+
};
6570
thread_start_and_end
6671
.entry(event.thread_id)
6772
.and_modify(|(thread_start, thread_end)| {
68-
let (event_min, event_max) = timestamp_to_min_max(event.timestamp);
73+
let (event_min, event_max) = timestamp_to_min_max(timestamp);
6974
*thread_start = cmp::min(*thread_start, event_min);
7075
*thread_end = cmp::max(*thread_end, event_max);
7176
})
72-
.or_insert_with(|| timestamp_to_min_max(event.timestamp));
77+
.or_insert_with(|| timestamp_to_min_max(timestamp));
7378
}
7479
// collect the the threads in order of the end time
7580
let mut end_and_thread = thread_start_and_end
@@ -130,29 +135,37 @@ pub fn generate(self_profile_data: Vec<u8>, opt: Opt) -> anyhow::Result<Vec<u8>>
130135

131136
let mut seq = serializer.serialize_seq(None)?;
132137

133-
let data = ProfilingData::from_paged_buffer(self_profile_data)
138+
let data = ProfilingData::from_paged_buffer(self_profile_data, None)
134139
.map_err(|e| anyhow::format_err!("{:?}", e))?;
135140

136141
let thread_to_collapsed_thread =
137142
generate_thread_to_collapsed_thread_mapping(opt.collapse_threads, &data);
138143

139144
// Chrome does not seem to like how many QueryCacheHit events we generate
140145
// only handle Interval events for now
141-
for event in data.iter().filter(|e| !e.timestamp.is_instant()) {
146+
for event in data
147+
.iter()
148+
.filter(|e| e.timestamp().map_or(false, |t| !t.is_instant()))
149+
{
142150
let duration = event.duration().unwrap();
143151
if let Some(minimum_duration) = opt.minimum_duration {
144152
if duration.as_micros() < minimum_duration {
145153
continue;
146154
}
147155
}
148-
let full_event = event.to_event();
156+
let full_event = data.to_full_event(&event);
149157
let crox_event = Event {
150158
name: full_event.label.clone().into_owned(),
151159
category: full_event.event_kind.clone().into_owned(),
152160
event_type: EventType::Complete,
153-
timestamp: event.timestamp.start().duration_since(UNIX_EPOCH).unwrap(),
161+
timestamp: event
162+
.timestamp()
163+
.unwrap()
164+
.start()
165+
.duration_since(UNIX_EPOCH)
166+
.unwrap(),
154167
duration,
155-
process_id: data.metadata.process_id,
168+
process_id: data.metadata().process_id,
156169
thread_id: *thread_to_collapsed_thread
157170
.get(&event.thread_id)
158171
.unwrap_or(&event.thread_id),
@@ -162,12 +175,12 @@ pub fn generate(self_profile_data: Vec<u8>, opt: Opt) -> anyhow::Result<Vec<u8>>
162175
}
163176
// add crate name for the process_id
164177
let index_of_crate_name = data
165-
.metadata
178+
.metadata()
166179
.cmd
167180
.find(" --crate-name ")
168181
.map(|index| index + 14);
169182
if let Some(index) = index_of_crate_name {
170-
let (_, last) = data.metadata.cmd.split_at(index);
183+
let (_, last) = data.metadata().cmd.split_at(index);
171184
let (crate_name, _) = last.split_at(last.find(" ").unwrap_or(last.len()));
172185

173186
let process_name = json!({
@@ -176,7 +189,7 @@ pub fn generate(self_profile_data: Vec<u8>, opt: Opt) -> anyhow::Result<Vec<u8>>
176189
"ts" : 0,
177190
"tid" : 0,
178191
"cat" : "",
179-
"pid" : data.metadata.process_id,
192+
"pid" : data.metadata().process_id,
180193
"args": {
181194
"name" : crate_name
182195
}
@@ -190,9 +203,9 @@ pub fn generate(self_profile_data: Vec<u8>, opt: Opt) -> anyhow::Result<Vec<u8>>
190203
"ts" : 0,
191204
"tid" : 0,
192205
"cat" : "",
193-
"pid" : data.metadata.process_id,
206+
"pid" : data.metadata().process_id,
194207
"args": {
195-
"sort_index" : data.metadata.start_time.duration_since(UNIX_EPOCH).unwrap().as_micros() as u64
208+
"sort_index" : data.metadata().start_time.duration_since(UNIX_EPOCH).unwrap().as_micros() as u64
196209
}
197210
});
198211
seq.serialize_element(&process_name)?;

site/src/self_profile/flamegraph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use inferno::flamegraph::{from_lines, Options as FlamegraphOptions};
66
pub struct Opt {}
77

88
pub fn generate(title: &str, self_profile_data: Vec<u8>, _: Opt) -> anyhow::Result<Vec<u8>> {
9-
let profiling_data = ProfilingData::from_paged_buffer(self_profile_data)
9+
let profiling_data = ProfilingData::from_paged_buffer(self_profile_data, None)
1010
.map_err(|e| anyhow::format_err!("{:?}", e))?;
1111

1212
let recorded_stacks = collapse_stacks(&profiling_data)

0 commit comments

Comments
 (0)