Skip to content

Commit 2a4dc1b

Browse files
Run cargo fmt.
1 parent ca0f287 commit 2a4dc1b

File tree

8 files changed

+108
-62
lines changed

8 files changed

+108
-62
lines changed

analyzeme/benches/serialization_bench.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use measureme::{FileSerializationSink, MmapSerializationSink};
99
fn bench_file_serialization_sink(bencher: &mut test::Bencher) {
1010
bencher.iter(|| {
1111
testing_common::run_serialization_bench::<FileSerializationSink>(
12-
"file_serialization_sink_test", 500_000, 1
12+
"file_serialization_sink_test",
13+
500_000,
14+
1,
1315
);
1416
});
1517
}
@@ -18,7 +20,9 @@ fn bench_file_serialization_sink(bencher: &mut test::Bencher) {
1820
fn bench_mmap_serialization_sink(bencher: &mut test::Bencher) {
1921
bencher.iter(|| {
2022
testing_common::run_serialization_bench::<MmapSerializationSink>(
21-
"mmap_serialization_sink_test", 500_000, 1
23+
"mmap_serialization_sink_test",
24+
500_000,
25+
1,
2226
);
2327
});
2428
}
@@ -27,7 +31,9 @@ fn bench_mmap_serialization_sink(bencher: &mut test::Bencher) {
2731
fn bench_file_serialization_sink_8_threads(bencher: &mut test::Bencher) {
2832
bencher.iter(|| {
2933
testing_common::run_serialization_bench::<FileSerializationSink>(
30-
"file_serialization_sink_test", 50_000, 8
34+
"file_serialization_sink_test",
35+
50_000,
36+
8,
3137
);
3238
});
3339
}
@@ -36,7 +42,9 @@ fn bench_file_serialization_sink_8_threads(bencher: &mut test::Bencher) {
3642
fn bench_mmap_serialization_sink_8_threads(bencher: &mut test::Bencher) {
3743
bencher.iter(|| {
3844
testing_common::run_serialization_bench::<MmapSerializationSink>(
39-
"mmap_serialization_sink_test", 50_000, 8
45+
"mmap_serialization_sink_test",
46+
50_000,
47+
8,
4048
);
4149
});
4250
}

analyzeme/src/lightweight_event.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ impl<'a> PartialEq for LightweightEvent<'a> {
5959
timestamp: other_timestamp,
6060
} = *other;
6161

62-
std::ptr::eq(data, other_data) &&
63-
event_index == other_event_index &&
64-
thread_id == other_thread_id &&
65-
timestamp == other_timestamp
62+
std::ptr::eq(data, other_data)
63+
&& event_index == other_event_index
64+
&& thread_id == other_thread_id
65+
&& timestamp == other_timestamp
6666
}
6767
}
6868

analyzeme/src/profiling_data.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ fn event_index_to_addr(event_index: usize) -> usize {
309309
FILE_HEADER_SIZE + event_index * mem::size_of::<RawEvent>()
310310
}
311311

312+
#[rustfmt::skip]
312313
#[cfg(test)]
313314
mod tests {
314315
use super::*;

analyzeme/src/stack_collapse.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ pub fn collapse_stacks<'a>(profiling_data: &ProfilingData) -> FxHashMap<String,
6666

6767
// Add this event to the stack_id
6868
thread.stack_id.push(';');
69-
thread.stack_id.push_str(&current_event.to_event().label[..]);
69+
thread
70+
.stack_id
71+
.push_str(&current_event.to_event().label[..]);
7072

7173
// Update current events self time
7274
let self_time = counters.entry(thread.stack_id.clone()).or_default();

analyzeme/src/stringtable.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,13 @@ pub struct StringRef<'st> {
3030
const UNKNOWN_STRING: &str = "<unknown>";
3131

3232
impl<'st> StringRef<'st> {
33-
3433
/// Expands the StringRef into an actual string. This method will
3534
/// avoid allocating a `String` if it can instead return a `&str` pointing
3635
/// into the raw string table data.
3736
pub fn to_string(&self) -> Cow<'st, str> {
38-
3937
let addr = match self.get_addr() {
4038
Ok(addr) => addr,
41-
Err(_) => {
42-
return Cow::from(UNKNOWN_STRING)
43-
}
39+
Err(_) => return Cow::from(UNKNOWN_STRING),
4440
};
4541

4642
// Try to avoid the allocation, which we can do if this is
@@ -60,11 +56,12 @@ impl<'st> StringRef<'st> {
6056
let first_byte = self.table.string_data[pos];
6157
const STRING_ID_SIZE: usize = std::mem::size_of::<StringId>();
6258
if terminator_pos == pos + STRING_ID_SIZE && is_utf8_continuation_byte(first_byte) {
63-
let id = decode_string_id_from_data(&self.table.string_data[pos..pos+STRING_ID_SIZE]);
59+
let id = decode_string_id_from_data(&self.table.string_data[pos..pos + STRING_ID_SIZE]);
6460
return StringRef {
6561
id,
6662
table: self.table,
67-
}.to_string();
63+
}
64+
.to_string();
6865
}
6966

7067
// Decode the bytes until the terminator. If there is a string id in
@@ -84,12 +81,11 @@ impl<'st> StringRef<'st> {
8481
}
8582

8683
pub fn write_to_string(&self, output: &mut String) {
87-
8884
let addr = match self.get_addr() {
8985
Ok(addr) => addr,
9086
Err(_) => {
9187
output.push_str(UNKNOWN_STRING);
92-
return
88+
return;
9389
}
9490
};
9591

analyzeme/src/testing_common.rs

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -68,39 +68,44 @@ fn generate_profiling_data<S: SerializationSink>(
6868
ExpectedEvent::new("QueryWithArg", "AQueryWithArg", &["some_arg"]),
6969
];
7070

71-
let threads: Vec<_> = (0.. num_threads).map(|thread_id| {
72-
let event_ids = event_ids.clone();
73-
let profiler = profiler.clone();
74-
let expected_events_templates = expected_events_templates.clone();
75-
76-
std::thread::spawn(move || {
77-
let mut expected_events = Vec::new();
78-
79-
for i in 0..num_stacks {
80-
// Allocate some invocation stacks
81-
82-
pseudo_invocation(
83-
&profiler,
84-
i,
85-
thread_id as u32,
86-
4,
87-
&event_ids[..],
88-
&expected_events_templates,
89-
&mut expected_events,
90-
);
91-
}
92-
93-
expected_events
71+
let threads: Vec<_> = (0..num_threads)
72+
.map(|thread_id| {
73+
let event_ids = event_ids.clone();
74+
let profiler = profiler.clone();
75+
let expected_events_templates = expected_events_templates.clone();
76+
77+
std::thread::spawn(move || {
78+
let mut expected_events = Vec::new();
79+
80+
for i in 0..num_stacks {
81+
// Allocate some invocation stacks
82+
83+
pseudo_invocation(
84+
&profiler,
85+
i,
86+
thread_id as u32,
87+
4,
88+
&event_ids[..],
89+
&expected_events_templates,
90+
&mut expected_events,
91+
);
92+
}
93+
94+
expected_events
95+
})
9496
})
95-
}).collect();
97+
.collect();
9698

97-
let expected_events: Vec<_> = threads.into_iter().flat_map(|t| t.join().unwrap()).collect();
99+
let expected_events: Vec<_> = threads
100+
.into_iter()
101+
.flat_map(|t| t.join().unwrap())
102+
.collect();
98103

99104
// An example of allocating the string contents of an event id that has
100105
// already been used
101106
profiler.map_virtual_to_concrete_string(
102107
event_id_virtual.to_string_id(),
103-
profiler.alloc_string("SomeQuery")
108+
profiler.alloc_string("SomeQuery"),
104109
);
105110

106111
expected_events
@@ -140,7 +145,10 @@ fn check_profiling_data(
140145
let expected_events_per_thread = collect_events_per_thread(expected_events);
141146

142147
let thread_ids: Vec<_> = actual_events_per_thread.keys().collect();
143-
assert_eq!(thread_ids, expected_events_per_thread.keys().collect::<Vec<_>>());
148+
assert_eq!(
149+
thread_ids,
150+
expected_events_per_thread.keys().collect::<Vec<_>>()
151+
);
144152

145153
for thread_id in thread_ids {
146154
let actual_events = &actual_events_per_thread[thread_id];
@@ -164,22 +172,34 @@ fn check_profiling_data(
164172
assert_eq!(count, num_expected_events);
165173
}
166174

167-
fn collect_events_per_thread<'a>(events: &mut dyn Iterator<Item = Event<'a>>) -> FxHashMap<u32, Vec<Event<'a>>> {
175+
fn collect_events_per_thread<'a>(
176+
events: &mut dyn Iterator<Item = Event<'a>>,
177+
) -> FxHashMap<u32, Vec<Event<'a>>> {
168178
let mut per_thread: FxHashMap<_, _> = Default::default();
169179

170180
for event in events {
171-
per_thread.entry(event.thread_id).or_insert(Vec::new()).push(event);
181+
per_thread
182+
.entry(event.thread_id)
183+
.or_insert(Vec::new())
184+
.push(event);
172185
}
173186

174187
per_thread
175188
}
176189

177-
pub fn run_serialization_bench<S: SerializationSink>(file_name_stem: &str, num_events: usize, num_threads: usize) {
190+
pub fn run_serialization_bench<S: SerializationSink>(
191+
file_name_stem: &str,
192+
num_events: usize,
193+
num_threads: usize,
194+
) {
178195
let filestem = mk_filestem(file_name_stem);
179196
generate_profiling_data::<S>(&filestem, num_events, num_threads);
180197
}
181198

182-
pub fn run_end_to_end_serialization_test<S: SerializationSink>(file_name_stem: &str, num_threads: usize) {
199+
pub fn run_end_to_end_serialization_test<S: SerializationSink>(
200+
file_name_stem: &str,
201+
num_threads: usize,
202+
) {
183203
let filestem = mk_filestem(file_name_stem);
184204
let expected_events = generate_profiling_data::<S>(&filestem, 10_000, num_threads);
185205
process_profiling_data(&filestem, &expected_events);

analyzeme/tests/serialization.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,32 @@ use measureme::{FileSerializationSink, MmapSerializationSink};
33

44
#[test]
55
fn test_file_serialization_sink_1_thread() {
6-
run_end_to_end_serialization_test::<FileSerializationSink>("file_serialization_sink_test_1_thread", 1);
6+
run_end_to_end_serialization_test::<FileSerializationSink>(
7+
"file_serialization_sink_test_1_thread",
8+
1,
9+
);
710
}
811

912
#[test]
1013
fn test_file_serialization_sink_8_threads() {
11-
run_end_to_end_serialization_test::<FileSerializationSink>("file_serialization_sink_test_8_threads", 8);
14+
run_end_to_end_serialization_test::<FileSerializationSink>(
15+
"file_serialization_sink_test_8_threads",
16+
8,
17+
);
1218
}
1319

1420
#[test]
1521
fn test_mmap_serialization_sink_1_thread() {
16-
run_end_to_end_serialization_test::<MmapSerializationSink>("mmap_serialization_sink_test_1_thread", 1);
22+
run_end_to_end_serialization_test::<MmapSerializationSink>(
23+
"mmap_serialization_sink_test_1_thread",
24+
1,
25+
);
1726
}
1827

1928
#[test]
2029
fn test_mmap_serialization_sink_8_threads() {
21-
run_end_to_end_serialization_test::<MmapSerializationSink>("mmap_serialization_sink_test_8_threads", 8);
30+
run_end_to_end_serialization_test::<MmapSerializationSink>(
31+
"mmap_serialization_sink_test_8_threads",
32+
8,
33+
);
2234
}

summarize/src/analysis.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ pub fn perform_analysis(data: ProfilingData) -> Results {
128128
}
129129
};
130130

131-
for current_event in data.iter().rev().map(|lightweight_event| lightweight_event.to_event()) {
131+
for current_event in data
132+
.iter()
133+
.rev()
134+
.map(|lightweight_event| lightweight_event.to_event())
135+
{
132136
match current_event.timestamp {
133137
Timestamp::Instant(_) => {
134138
if &current_event.event_kind[..] == QUERY_CACHE_HIT_EVENT_KIND {
@@ -164,21 +168,24 @@ pub fn perform_analysis(data: ProfilingData) -> Results {
164168
// If there is something on the stack, subtract the current
165169
// interval from it.
166170
if let Some(current_top) = thread.stack.last() {
167-
record_event_data(&current_top.label, &|data| {
168-
match &current_top.event_kind[..] {
171+
record_event_data(
172+
&current_top.label,
173+
&|data| match &current_top.event_kind[..] {
169174
QUERY_EVENT_KIND | GENERIC_ACTIVITY_EVENT_KIND => {
170175
data.self_time -= current_event_duration;
171176
}
172177
INCREMENTAL_LOAD_RESULT_EVENT_KIND => {
173-
data.incremental_load_time -= current_event_duration;
178+
data.incremental_load_time -= current_event_duration;
174179
}
175180
_ => {
176-
eprintln!("Unexpectedly enountered event `{:?}`, \
177-
while top of stack was `{:?}`. Ignoring.",
178-
current_event, current_top);
181+
eprintln!(
182+
"Unexpectedly enountered event `{:?}`, \
183+
while top of stack was `{:?}`. Ignoring.",
184+
current_event, current_top
185+
);
179186
}
180-
}
181-
});
187+
},
188+
);
182189
}
183190

184191
// Update counters for the current event

0 commit comments

Comments
 (0)