@@ -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+
106128pub 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
0 commit comments