Skip to content

Commit 603f0c9

Browse files
Remove the generic SerializationSink parameter from Profiler.
1 parent 77c6869 commit 603f0c9

File tree

5 files changed

+32
-54
lines changed

5 files changed

+32
-54
lines changed

analyzeme/benches/serialization_bench.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,17 @@
33
extern crate test;
44

55
use analyzeme::testing_common;
6-
use measureme::FileSerializationSink;
76

87
#[bench]
98
fn bench_file_serialization_sink(bencher: &mut test::Bencher) {
109
bencher.iter(|| {
11-
testing_common::run_serialization_bench::<FileSerializationSink>(
12-
"file_serialization_sink_test",
13-
500_000,
14-
1,
15-
);
10+
testing_common::run_serialization_bench("file_serialization_sink_test", 500_000, 1);
1611
});
1712
}
1813

1914
#[bench]
2015
fn bench_file_serialization_sink_8_threads(bencher: &mut test::Bencher) {
2116
bencher.iter(|| {
22-
testing_common::run_serialization_bench::<FileSerializationSink>(
23-
"file_serialization_sink_test",
24-
50_000,
25-
8,
26-
);
17+
testing_common::run_serialization_bench("file_serialization_sink_test", 50_000, 8);
2718
});
2819
}

analyzeme/src/testing_common.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::timestamp::Timestamp;
22
use crate::{Event, ProfilingData};
3-
use measureme::{EventId, EventIdBuilder, Profiler, SerializationSink, StringId};
3+
use measureme::{EventId, EventIdBuilder, Profiler, StringId};
44
use rustc_hash::FxHashMap;
55
use std::borrow::Cow;
66
use std::default::Default;
@@ -36,12 +36,12 @@ impl ExpectedEvent {
3636
}
3737

3838
// Generate some profiling data. This is the part that would run in rustc.
39-
fn generate_profiling_data<S: SerializationSink>(
39+
fn generate_profiling_data(
4040
filestem: &Path,
4141
num_stacks: usize,
4242
num_threads: usize,
4343
) -> Vec<Event<'static>> {
44-
let profiler = Arc::new(Profiler::<S>::new(Path::new(filestem)).unwrap());
44+
let profiler = Arc::new(Profiler::new(Path::new(filestem)).unwrap());
4545

4646
let event_id_virtual = EventId::from_label(StringId::new_virtual(42));
4747
let event_id_builder = EventIdBuilder::new(&profiler);
@@ -187,26 +187,19 @@ fn collect_events_per_thread<'a>(
187187
per_thread
188188
}
189189

190-
pub fn run_serialization_bench<S: SerializationSink>(
191-
file_name_stem: &str,
192-
num_events: usize,
193-
num_threads: usize,
194-
) {
190+
pub fn run_serialization_bench(file_name_stem: &str, num_events: usize, num_threads: usize) {
195191
let filestem = mk_filestem(file_name_stem);
196-
generate_profiling_data::<S>(&filestem, num_events, num_threads);
192+
generate_profiling_data(&filestem, num_events, num_threads);
197193
}
198194

199-
pub fn run_end_to_end_serialization_test<S: SerializationSink>(
200-
file_name_stem: &str,
201-
num_threads: usize,
202-
) {
195+
pub fn run_end_to_end_serialization_test(file_name_stem: &str, num_threads: usize) {
203196
let filestem = mk_filestem(file_name_stem);
204-
let expected_events = generate_profiling_data::<S>(&filestem, 10_000, num_threads);
197+
let expected_events = generate_profiling_data(&filestem, 10_000, num_threads);
205198
process_profiling_data(&filestem, &expected_events);
206199
}
207200

208-
fn pseudo_invocation<S: SerializationSink>(
209-
profiler: &Profiler<S>,
201+
fn pseudo_invocation(
202+
profiler: &Profiler,
210203
random: usize,
211204
thread_id: u32,
212205
recursions_left: usize,

analyzeme/tests/serialization.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
use analyzeme::testing_common::run_end_to_end_serialization_test;
2-
use measureme::FileSerializationSink;
32

43
#[test]
54
fn test_file_serialization_sink_1_thread() {
6-
run_end_to_end_serialization_test::<FileSerializationSink>(
7-
"file_serialization_sink_test_1_thread",
8-
1,
9-
);
5+
run_end_to_end_serialization_test("file_serialization_sink_test_1_thread", 1);
106
}
117

128
#[test]
139
fn test_file_serialization_sink_8_threads() {
14-
run_end_to_end_serialization_test::<FileSerializationSink>(
15-
"file_serialization_sink_test_8_threads",
16-
8,
17-
);
10+
run_end_to_end_serialization_test("file_serialization_sink_test_8_threads", 8);
1811
}

measureme/src/event_id.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Profiler, SerializationSink, StringComponent, StringId};
1+
use crate::{Profiler, StringComponent, StringId};
22

33
/// Event IDs are strings conforming to the following grammar:
44
///
@@ -53,12 +53,12 @@ impl EventId {
5353
}
5454
}
5555

56-
pub struct EventIdBuilder<'p, S: SerializationSink> {
57-
profiler: &'p Profiler<S>,
56+
pub struct EventIdBuilder<'p> {
57+
profiler: &'p Profiler,
5858
}
5959

60-
impl<'p, S: SerializationSink> EventIdBuilder<'p, S> {
61-
pub fn new(profiler: &Profiler<S>) -> EventIdBuilder<'_, S> {
60+
impl<'p> EventIdBuilder<'p> {
61+
pub fn new(profiler: &Profiler) -> EventIdBuilder<'_> {
6262
EventIdBuilder { profiler }
6363
}
6464

measureme/src/profiler.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::event_id::EventId;
22
use crate::file_header::{write_file_header, FILE_MAGIC_EVENT_STREAM};
3+
use crate::file_serialization_sink::FileSerializationSink;
34
use crate::raw_event::RawEvent;
45
use crate::serialization::SerializationSink;
56
use crate::stringtable::{SerializableString, StringId, StringTableBuilder};
@@ -24,23 +25,23 @@ impl ProfilerFiles {
2425
}
2526
}
2627

27-
pub struct Profiler<S: SerializationSink> {
28-
event_sink: Arc<S>,
29-
string_table: StringTableBuilder<S>,
28+
pub struct Profiler {
29+
event_sink: Arc<FileSerializationSink>,
30+
string_table: StringTableBuilder<FileSerializationSink>,
3031
start_time: Instant,
3132
}
3233

33-
impl<S: SerializationSink> Profiler<S> {
34-
pub fn new<P: AsRef<Path>>(path_stem: P) -> Result<Profiler<S>, Box<dyn Error + Send + Sync>> {
34+
impl Profiler {
35+
pub fn new<P: AsRef<Path>>(path_stem: P) -> Result<Profiler, Box<dyn Error + Send + Sync>> {
3536
let paths = ProfilerFiles::new(path_stem.as_ref());
36-
let event_sink = Arc::new(S::from_path(&paths.events_file)?);
37+
let event_sink = Arc::new(SerializationSink::from_path(&paths.events_file)?);
3738

3839
// The first thing in every file we generate must be the file header.
3940
write_file_header(&*event_sink, FILE_MAGIC_EVENT_STREAM);
4041

4142
let string_table = StringTableBuilder::new(
42-
Arc::new(S::from_path(&paths.string_data_file)?),
43-
Arc::new(S::from_path(&paths.string_index_file)?),
43+
Arc::new(SerializationSink::from_path(&paths.string_data_file)?),
44+
Arc::new(SerializationSink::from_path(&paths.string_index_file)?),
4445
);
4546

4647
let profiler = Profiler {
@@ -108,7 +109,7 @@ impl<S: SerializationSink> Profiler<S> {
108109
event_kind: StringId,
109110
event_id: EventId,
110111
thread_id: u32,
111-
) -> TimingGuard<'a, S> {
112+
) -> TimingGuard<'a> {
112113
TimingGuard {
113114
profiler: self,
114115
event_id,
@@ -133,15 +134,15 @@ impl<S: SerializationSink> Profiler<S> {
133134
/// When dropped, this `TimingGuard` will record an "end" event in the
134135
/// `Profiler` it was created by.
135136
#[must_use]
136-
pub struct TimingGuard<'a, S: SerializationSink> {
137-
profiler: &'a Profiler<S>,
137+
pub struct TimingGuard<'a> {
138+
profiler: &'a Profiler,
138139
event_id: EventId,
139140
event_kind: StringId,
140141
thread_id: u32,
141142
start_ns: u64,
142143
}
143144

144-
impl<'a, S: SerializationSink> Drop for TimingGuard<'a, S> {
145+
impl<'a> Drop for TimingGuard<'a> {
145146
#[inline]
146147
fn drop(&mut self) {
147148
let raw_event = RawEvent::new_interval(
@@ -156,7 +157,7 @@ impl<'a, S: SerializationSink> Drop for TimingGuard<'a, S> {
156157
}
157158
}
158159

159-
impl<'a, S: SerializationSink> TimingGuard<'a, S> {
160+
impl<'a> TimingGuard<'a> {
160161
/// This method set a new `event_id` right before actually recording the
161162
/// event.
162163
#[inline]

0 commit comments

Comments
 (0)