@@ -56,116 +56,170 @@ mod test {
56
56
57
57
#[ test]
58
58
fn basic_test ( ) {
59
+ // <--e1-->
60
+ // <--e1--> <----------e2---------->
61
+ // T2 1 2 3 4 5 6
62
+ // sample interval | | | | | | | | | | |
63
+ // stacks count:
64
+ // rustc 1 2
65
+ // rustc;e1 1 2
66
+ // rustc;e2 1 2 3 4
67
+ // rustc;e2;e1 1 2
68
+
59
69
let events = [
60
70
Event {
61
71
event_kind : "Query" . into ( ) ,
62
- label : "EventA " . into ( ) ,
72
+ label : "e1 " . into ( ) ,
63
73
additional_data : & [ ] ,
64
74
timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 1 ) ,
65
75
timestamp_kind : TimestampKind :: Start ,
66
76
thread_id : 1 ,
67
77
} ,
68
78
Event {
69
79
event_kind : "Query" . into ( ) ,
70
- label : "EventA " . into ( ) ,
80
+ label : "e1 " . into ( ) ,
71
81
additional_data : & [ ] ,
72
82
timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 2 ) ,
73
83
timestamp_kind : TimestampKind :: End ,
74
84
thread_id : 1 ,
75
85
} ,
76
86
Event {
77
87
event_kind : "Query" . into ( ) ,
78
- label : "EventB " . into ( ) ,
88
+ label : "e2 " . into ( ) ,
79
89
additional_data : & [ ] ,
80
90
timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 3 ) ,
81
91
timestamp_kind : TimestampKind :: Start ,
82
92
thread_id : 1 ,
83
93
} ,
84
94
Event {
85
95
event_kind : "Query" . into ( ) ,
86
- label : "EventA " . into ( ) ,
96
+ label : "e1 " . into ( ) ,
87
97
additional_data : & [ ] ,
88
98
timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 4 ) ,
89
99
timestamp_kind : TimestampKind :: Start ,
90
100
thread_id : 1 ,
91
101
} ,
92
102
Event {
93
103
event_kind : "Query" . into ( ) ,
94
- label : "EventA " . into ( ) ,
104
+ label : "e1 " . into ( ) ,
95
105
additional_data : & [ ] ,
96
106
timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 5 ) ,
97
107
timestamp_kind : TimestampKind :: End ,
98
108
thread_id : 1 ,
99
109
} ,
100
110
Event {
101
111
event_kind : "Query" . into ( ) ,
102
- label : "EventB " . into ( ) ,
112
+ label : "e2 " . into ( ) ,
103
113
additional_data : & [ ] ,
104
114
timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 6 ) ,
105
115
timestamp_kind : TimestampKind :: End ,
106
116
thread_id : 1 ,
107
117
} ,
108
118
] ;
109
119
110
- let recorded_stacks = super :: collapse_stacks ( events. iter ( ) . cloned ( ) , 1 ) ;
120
+ let recorded_stacks = super :: collapse_stacks ( events. iter ( ) . cloned ( ) , 500 ) ;
111
121
112
122
let mut expected_stacks = HashMap :: < String , usize > :: new ( ) ;
113
- expected_stacks. insert ( "rustc;EventB;EventA " . into ( ) , 1000 ) ;
114
- expected_stacks. insert ( "rustc;EventB " . into ( ) , 2000 ) ;
115
- expected_stacks. insert ( "rustc;EventA " . into ( ) , 1000 ) ;
116
- expected_stacks. insert ( "rustc" . into ( ) , 1000 ) ;
123
+ expected_stacks. insert ( "rustc;e2;e1 " . into ( ) , 2 ) ;
124
+ expected_stacks. insert ( "rustc;e2 " . into ( ) , 4 ) ;
125
+ expected_stacks. insert ( "rustc;e1 " . into ( ) , 2 ) ;
126
+ expected_stacks. insert ( "rustc" . into ( ) , 2 ) ;
117
127
118
128
assert_eq ! ( expected_stacks, recorded_stacks) ;
119
129
}
120
130
121
131
#[ test]
122
132
fn multi_threaded_test ( ) {
133
+ // <--e1--> <--e1-->
134
+ // T1 1 2 3 4 5
135
+ // <--e3-->
136
+ // <--e1--><----------e2---------->
137
+ // T2 1 2 3 4 5
138
+ // sample interval | | | | |
139
+ // stacks count:
140
+ // rustc 1
141
+ // rustc;e1 2 3
142
+ // rustc;e2 1 2
143
+ // rustc;e2;e3 1
144
+
123
145
let events = [
124
146
Event {
125
147
event_kind : "Query" . into ( ) ,
126
- label : "EventA " . into ( ) ,
148
+ label : "e1 " . into ( ) ,
127
149
additional_data : & [ ] ,
128
150
timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 1 ) ,
129
151
timestamp_kind : TimestampKind :: Start ,
130
152
thread_id : 1 ,
131
153
} ,
132
154
Event {
133
155
event_kind : "Query" . into ( ) ,
134
- label : "EventB " . into ( ) ,
156
+ label : "e1 " . into ( ) ,
135
157
additional_data : & [ ] ,
136
- timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 3 ) ,
158
+ timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 1 ) ,
159
+ timestamp_kind : TimestampKind :: Start ,
160
+ thread_id : 2 ,
161
+ } ,
162
+ Event {
163
+ event_kind : "Query" . into ( ) ,
164
+ label : "e1" . into ( ) ,
165
+ additional_data : & [ ] ,
166
+ timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 2 ) ,
167
+ timestamp_kind : TimestampKind :: End ,
168
+ thread_id : 2 ,
169
+ } ,
170
+ Event {
171
+ event_kind : "Query" . into ( ) ,
172
+ label : "e2" . into ( ) ,
173
+ additional_data : & [ ] ,
174
+ timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 2 ) ,
137
175
timestamp_kind : TimestampKind :: Start ,
138
176
thread_id : 2 ,
139
177
} ,
140
178
Event {
141
179
event_kind : "Query" . into ( ) ,
142
- label : "EventA " . into ( ) ,
180
+ label : "e1 " . into ( ) ,
143
181
additional_data : & [ ] ,
144
182
timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 2 ) ,
145
183
timestamp_kind : TimestampKind :: End ,
146
184
thread_id : 1 ,
147
185
} ,
148
186
Event {
149
187
event_kind : "Query" . into ( ) ,
150
- label : "EventA" . into ( ) ,
188
+ label : "e1" . into ( ) ,
189
+ additional_data : & [ ] ,
190
+ timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 3 ) ,
191
+ timestamp_kind : TimestampKind :: Start ,
192
+ thread_id : 1 ,
193
+ } ,
194
+ Event {
195
+ event_kind : "Query" . into ( ) ,
196
+ label : "e1" . into ( ) ,
151
197
additional_data : & [ ] ,
152
198
timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 4 ) ,
199
+ timestamp_kind : TimestampKind :: End ,
200
+ thread_id : 1 ,
201
+ } ,
202
+ Event {
203
+ event_kind : "Query" . into ( ) ,
204
+ label : "e3" . into ( ) ,
205
+ additional_data : & [ ] ,
206
+ timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 3 ) ,
153
207
timestamp_kind : TimestampKind :: Start ,
154
208
thread_id : 2 ,
155
209
} ,
156
210
Event {
157
211
event_kind : "Query" . into ( ) ,
158
- label : "EventA " . into ( ) ,
212
+ label : "e3 " . into ( ) ,
159
213
additional_data : & [ ] ,
160
- timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 5 ) ,
214
+ timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 4 ) ,
161
215
timestamp_kind : TimestampKind :: End ,
162
216
thread_id : 2 ,
163
217
} ,
164
218
Event {
165
219
event_kind : "Query" . into ( ) ,
166
- label : "EventB " . into ( ) ,
220
+ label : "e2 " . into ( ) ,
167
221
additional_data : & [ ] ,
168
- timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 6 ) ,
222
+ timestamp : SystemTime :: UNIX_EPOCH + Duration :: from_secs ( 5 ) ,
169
223
timestamp_kind : TimestampKind :: End ,
170
224
thread_id : 2 ,
171
225
} ,
@@ -174,9 +228,10 @@ mod test {
174
228
let recorded_stacks = super :: collapse_stacks ( events. iter ( ) . cloned ( ) , 1000 ) ;
175
229
176
230
let mut expected_stacks = HashMap :: < String , usize > :: new ( ) ;
177
- expected_stacks. insert ( "rustc;EventB;EventA" . into ( ) , 1 ) ;
178
- expected_stacks. insert ( "rustc;EventB" . into ( ) , 2 ) ;
179
- expected_stacks. insert ( "rustc;EventA" . into ( ) , 1 ) ;
231
+ expected_stacks. insert ( "rustc;e2;e3" . into ( ) , 1 ) ;
232
+ expected_stacks. insert ( "rustc;e2" . into ( ) , 2 ) ;
233
+ expected_stacks. insert ( "rustc;e1" . into ( ) , 3 ) ;
234
+ expected_stacks. insert ( "rustc" . into ( ) , 1 ) ;
180
235
181
236
assert_eq ! ( expected_stacks, recorded_stacks) ;
182
237
}
0 commit comments