Skip to content

Commit 3a6a0df

Browse files
{wip} better benchmarks
1 parent 8367ec6 commit 3a6a0df

File tree

3 files changed

+61
-20
lines changed

3 files changed

+61
-20
lines changed

analyzeme/benches/serialization_bench.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,35 @@ use measureme::{FileSerializationSink, MmapSerializationSink};
88
#[bench]
99
fn bench_file_serialization_sink(bencher: &mut test::Bencher) {
1010
bencher.iter(|| {
11-
testing_common::run_end_to_end_serialization_test::<FileSerializationSink>(
12-
"file_serialization_sink_test",
11+
testing_common::run_serialization_bench::<FileSerializationSink>(
12+
"file_serialization_sink_test", 500_000, 1
1313
);
1414
});
1515
}
1616

1717
#[bench]
1818
fn bench_mmap_serialization_sink(bencher: &mut test::Bencher) {
1919
bencher.iter(|| {
20-
testing_common::run_end_to_end_serialization_test::<MmapSerializationSink>(
21-
"mmap_serialization_sink_test",
20+
testing_common::run_serialization_bench::<MmapSerializationSink>(
21+
"mmap_serialization_sink_test", 500_000, 1
22+
);
23+
});
24+
}
25+
26+
#[bench]
27+
fn bench_file_serialization_sink_8_threads(bencher: &mut test::Bencher) {
28+
bencher.iter(|| {
29+
testing_common::run_serialization_bench::<FileSerializationSink>(
30+
"file_serialization_sink_test", 50_000, 8
31+
);
32+
});
33+
}
34+
35+
#[bench]
36+
fn bench_mmap_serialization_sink_8_threads(bencher: &mut test::Bencher) {
37+
bencher.iter(|| {
38+
testing_common::run_serialization_bench::<MmapSerializationSink>(
39+
"mmap_serialization_sink_test", 50_000, 8
2240
);
2341
});
2442
}

analyzeme/src/testing_common.rs

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ fn mk_filestem(file_name_stem: &str) -> PathBuf {
1818
}
1919

2020
// Generate some profiling data. This is the part that would run in rustc.
21-
fn generate_profiling_data<S: SerializationSink>(filestem: &Path) -> Vec<Event<'static>> {
21+
fn generate_profiling_data<S: SerializationSink>(
22+
filestem: &Path,
23+
num_stacks: usize,
24+
num_threads: usize,
25+
// sleep: bool,
26+
) -> Vec<Event<'static>> {
2227
let profiler = Arc::new(Profiler::<S>::new(Path::new(filestem)).unwrap());
2328

2429
let event_id_reserved = StringId::reserved(42);
2530

26-
let event_ids = &[
31+
let event_ids = vec![
2732
(
2833
profiler.alloc_string("Generic"),
2934
profiler.alloc_string("SomeGenericActivity"),
@@ -38,20 +43,32 @@ fn generate_profiling_data<S: SerializationSink>(filestem: &Path) -> Vec<Event<'
3843
event_ids_as_str.insert(event_ids[1].0, "Query");
3944
event_ids_as_str.insert(event_ids[1].1, "SomeQuery");
4045

41-
let mut expected_events = Vec::new();
46+
let threads: Vec<_> = (0.. num_threads).map(|_| {
47+
let event_ids = event_ids.clone();
48+
let profiler = profiler.clone();
49+
let event_ids_as_str = event_ids_as_str.clone();
4250

43-
for i in 0..10_000 {
44-
// Allocate some invocation stacks
51+
std::thread::spawn(move || {
52+
let mut expected_events = Vec::new();
4553

46-
pseudo_invocation(
47-
&profiler,
48-
i,
49-
4,
50-
event_ids,
51-
&event_ids_as_str,
52-
&mut expected_events,
53-
);
54-
}
54+
for i in 0..num_stacks {
55+
// Allocate some invocation stacks
56+
57+
pseudo_invocation(
58+
&profiler,
59+
i,
60+
4,
61+
&event_ids[..],
62+
&event_ids_as_str,
63+
&mut expected_events,
64+
);
65+
}
66+
67+
expected_events
68+
})
69+
}).collect();
70+
71+
let expected_events: Vec<_> = threads.into_iter().flat_map(|t| t.join().unwrap()).collect();
5572

5673
// An example of allocating the string contents of an event id that has
5774
// already been used
@@ -103,9 +120,15 @@ fn check_profiling_data(
103120
assert_eq!(count, num_expected_events);
104121
}
105122

123+
pub fn run_serialization_bench<S: SerializationSink>(file_name_stem: &str, num_events: usize, num_threads: usize) {
124+
let filestem = mk_filestem(file_name_stem);
125+
generate_profiling_data::<S>(&filestem, num_events, num_threads);
126+
}
127+
106128
pub fn run_end_to_end_serialization_test<S: SerializationSink>(file_name_stem: &str) {
107129
let filestem = mk_filestem(file_name_stem);
108-
let expected_events = generate_profiling_data::<S>(&filestem);
130+
// FIXME: make processing capable of verifying multi-thread data
131+
let expected_events = generate_profiling_data::<S>(&filestem, 10_000, 1);
109132
process_profiling_data(&filestem, &expected_events);
110133
}
111134

measureme/src/serialization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl Addr {
1111
}
1212
}
1313

14-
pub trait SerializationSink: Sized {
14+
pub trait SerializationSink: Sized + Send + Sync + 'static {
1515
fn from_path(path: &Path) -> Result<Self, Box<dyn Error>>;
1616

1717
fn write_atomic<W>(&self, num_bytes: usize, write: W) -> Addr

0 commit comments

Comments
 (0)