1
1
use crate :: timestamp:: Timestamp ;
2
2
use crate :: { Event , ProfilingData } ;
3
- use measureme:: { Profiler , SerializationSink , StringId } ;
3
+ use measureme:: { EventIdBuilder , Profiler , SerializationSink , StringId } ;
4
4
use rustc_hash:: FxHashMap ;
5
5
use std:: borrow:: Cow ;
6
6
use std:: default:: Default ;
@@ -18,6 +18,27 @@ fn mk_filestem(file_name_stem: &str) -> PathBuf {
18
18
path
19
19
}
20
20
21
+ #[ derive( Clone ) ]
22
+ struct ExpectedEvent {
23
+ kind : Cow < ' static , str > ,
24
+ label : Cow < ' static , str > ,
25
+ args : Vec < Cow < ' static , str > > ,
26
+ }
27
+
28
+ impl ExpectedEvent {
29
+ fn new (
30
+ kind : & ' static str ,
31
+ label : & ' static str ,
32
+ args : & [ & ' static str ]
33
+ ) -> ExpectedEvent {
34
+ ExpectedEvent {
35
+ kind : Cow :: from ( kind) ,
36
+ label : Cow :: from ( label) ,
37
+ args : args. iter ( ) . map ( |& x| Cow :: from ( x) ) . collect ( ) ,
38
+ }
39
+ }
40
+ }
41
+
21
42
// Generate some profiling data. This is the part that would run in rustc.
22
43
fn generate_profiling_data < S : SerializationSink > (
23
44
filestem : & Path ,
@@ -28,25 +49,34 @@ fn generate_profiling_data<S: SerializationSink>(
28
49
29
50
let event_id_virtual = StringId :: new_virtual ( 42 ) ;
30
51
52
+ let event_id_builder = EventIdBuilder :: new ( & profiler) ;
53
+
31
54
let event_ids = vec ! [
32
55
(
33
56
profiler. alloc_string( "Generic" ) ,
34
57
profiler. alloc_string( "SomeGenericActivity" ) ,
35
58
) ,
36
59
( profiler. alloc_string( "Query" ) , event_id_virtual) ,
60
+ (
61
+ profiler. alloc_string( "QueryWithArg" ) ,
62
+ event_id_builder. from_label_and_arg(
63
+ profiler. alloc_string( "AQueryWithArg" ) ,
64
+ profiler. alloc_string( "some_arg" )
65
+ ) ,
66
+ ) ,
37
67
] ;
38
68
39
69
// This and event_ids have to match!
40
- let mut event_ids_as_str : FxHashMap < _ , _ > = Default :: default ( ) ;
41
- event_ids_as_str . insert ( event_ids [ 0 ] . 0 , "Generic" ) ;
42
- event_ids_as_str . insert ( event_ids [ 0 ] . 1 , "SomeGenericActivity" ) ;
43
- event_ids_as_str . insert ( event_ids [ 1 ] . 0 , "Query" ) ;
44
- event_ids_as_str . insert ( event_ids [ 1 ] . 1 , "SomeQuery" ) ;
70
+ let expected_events_templates = vec ! [
71
+ ExpectedEvent :: new ( "Generic" , "SomeGenericActivity" , & [ ] ) ,
72
+ ExpectedEvent :: new ( "Query" , "SomeQuery" , & [ ] ) ,
73
+ ExpectedEvent :: new ( "QueryWithArg" , "AQueryWithArg" , & [ "some_arg" ] ) ,
74
+ ] ;
45
75
46
76
let threads: Vec < _ > = ( 0 .. num_threads) . map ( |thread_id| {
47
77
let event_ids = event_ids. clone ( ) ;
48
78
let profiler = profiler. clone ( ) ;
49
- let event_ids_as_str = event_ids_as_str . clone ( ) ;
79
+ let expected_events_templates = expected_events_templates . clone ( ) ;
50
80
51
81
std:: thread:: spawn ( move || {
52
82
let mut expected_events = Vec :: new ( ) ;
@@ -60,7 +90,7 @@ fn generate_profiling_data<S: SerializationSink>(
60
90
thread_id as u32 ,
61
91
4 ,
62
92
& event_ids[ ..] ,
63
- & event_ids_as_str ,
93
+ & expected_events_templates ,
64
94
& mut expected_events,
65
95
) ;
66
96
}
@@ -166,14 +196,16 @@ fn pseudo_invocation<S: SerializationSink>(
166
196
thread_id : u32 ,
167
197
recursions_left : usize ,
168
198
event_ids : & [ ( StringId , StringId ) ] ,
169
- event_ids_as_str : & FxHashMap < StringId , & ' static str > ,
199
+ expected_events_templates : & [ ExpectedEvent ] ,
170
200
expected_events : & mut Vec < Event < ' static > > ,
171
201
) {
172
202
if recursions_left == 0 {
173
203
return ;
174
204
}
175
205
176
- let ( event_kind, event_id) = event_ids[ random % event_ids. len ( ) ] ;
206
+ let random_event_index = random % event_ids. len ( ) ;
207
+
208
+ let ( event_kind, event_id) = event_ids[ random_event_index] ;
177
209
178
210
let _prof_guard = profiler. start_recording_interval_event ( event_kind, event_id, thread_id) ;
179
211
@@ -183,19 +215,19 @@ fn pseudo_invocation<S: SerializationSink>(
183
215
thread_id,
184
216
recursions_left - 1 ,
185
217
event_ids,
186
- event_ids_as_str ,
218
+ expected_events_templates ,
187
219
expected_events,
188
220
) ;
189
221
190
222
expected_events. push ( Event {
191
- event_kind : Cow :: from ( event_ids_as_str[ & event_kind] ) ,
192
- label : Cow :: from ( event_ids_as_str[ & event_id] ) ,
193
- additional_data : & [ ] ,
223
+ event_kind : expected_events_templates[ random_event_index] . kind . clone ( ) ,
224
+ label : expected_events_templates[ random_event_index] . label . clone ( ) ,
225
+ additional_data : expected_events_templates[ random_event_index] . args . clone ( ) ,
226
+ thread_id,
194
227
// We can't test this anyway:
195
228
timestamp : Timestamp :: Interval {
196
229
start : SystemTime :: UNIX_EPOCH ,
197
230
end : SystemTime :: UNIX_EPOCH ,
198
231
} ,
199
- thread_id,
200
232
} ) ;
201
233
}
0 commit comments