Skip to content

Commit 0fbe21d

Browse files
andjo403michaelwoerister
authored andcommitted
add description to stack collapse tests
1 parent 47f59fa commit 0fbe21d

File tree

1 file changed

+78
-23
lines changed

1 file changed

+78
-23
lines changed

tools_lib/src/stack_collapse.rs

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,116 +56,170 @@ mod test {
5656

5757
#[test]
5858
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+
5969
let events = [
6070
Event {
6171
event_kind: "Query".into(),
62-
label: "EventA".into(),
72+
label: "e1".into(),
6373
additional_data: &[],
6474
timestamp: SystemTime::UNIX_EPOCH + Duration::from_secs(1),
6575
timestamp_kind: TimestampKind::Start,
6676
thread_id: 1,
6777
},
6878
Event {
6979
event_kind: "Query".into(),
70-
label: "EventA".into(),
80+
label: "e1".into(),
7181
additional_data: &[],
7282
timestamp: SystemTime::UNIX_EPOCH + Duration::from_secs(2),
7383
timestamp_kind: TimestampKind::End,
7484
thread_id: 1,
7585
},
7686
Event {
7787
event_kind: "Query".into(),
78-
label: "EventB".into(),
88+
label: "e2".into(),
7989
additional_data: &[],
8090
timestamp: SystemTime::UNIX_EPOCH + Duration::from_secs(3),
8191
timestamp_kind: TimestampKind::Start,
8292
thread_id: 1,
8393
},
8494
Event {
8595
event_kind: "Query".into(),
86-
label: "EventA".into(),
96+
label: "e1".into(),
8797
additional_data: &[],
8898
timestamp: SystemTime::UNIX_EPOCH + Duration::from_secs(4),
8999
timestamp_kind: TimestampKind::Start,
90100
thread_id: 1,
91101
},
92102
Event {
93103
event_kind: "Query".into(),
94-
label: "EventA".into(),
104+
label: "e1".into(),
95105
additional_data: &[],
96106
timestamp: SystemTime::UNIX_EPOCH + Duration::from_secs(5),
97107
timestamp_kind: TimestampKind::End,
98108
thread_id: 1,
99109
},
100110
Event {
101111
event_kind: "Query".into(),
102-
label: "EventB".into(),
112+
label: "e2".into(),
103113
additional_data: &[],
104114
timestamp: SystemTime::UNIX_EPOCH + Duration::from_secs(6),
105115
timestamp_kind: TimestampKind::End,
106116
thread_id: 1,
107117
},
108118
];
109119

110-
let recorded_stacks = super::collapse_stacks(events.iter().cloned(), 1);
120+
let recorded_stacks = super::collapse_stacks(events.iter().cloned(), 500);
111121

112122
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);
117127

118128
assert_eq!(expected_stacks, recorded_stacks);
119129
}
120130

121131
#[test]
122132
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+
123145
let events = [
124146
Event {
125147
event_kind: "Query".into(),
126-
label: "EventA".into(),
148+
label: "e1".into(),
127149
additional_data: &[],
128150
timestamp: SystemTime::UNIX_EPOCH + Duration::from_secs(1),
129151
timestamp_kind: TimestampKind::Start,
130152
thread_id: 1,
131153
},
132154
Event {
133155
event_kind: "Query".into(),
134-
label: "EventB".into(),
156+
label: "e1".into(),
135157
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),
137175
timestamp_kind: TimestampKind::Start,
138176
thread_id: 2,
139177
},
140178
Event {
141179
event_kind: "Query".into(),
142-
label: "EventA".into(),
180+
label: "e1".into(),
143181
additional_data: &[],
144182
timestamp: SystemTime::UNIX_EPOCH + Duration::from_secs(2),
145183
timestamp_kind: TimestampKind::End,
146184
thread_id: 1,
147185
},
148186
Event {
149187
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(),
151197
additional_data: &[],
152198
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),
153207
timestamp_kind: TimestampKind::Start,
154208
thread_id: 2,
155209
},
156210
Event {
157211
event_kind: "Query".into(),
158-
label: "EventA".into(),
212+
label: "e3".into(),
159213
additional_data: &[],
160-
timestamp: SystemTime::UNIX_EPOCH + Duration::from_secs(5),
214+
timestamp: SystemTime::UNIX_EPOCH + Duration::from_secs(4),
161215
timestamp_kind: TimestampKind::End,
162216
thread_id: 2,
163217
},
164218
Event {
165219
event_kind: "Query".into(),
166-
label: "EventB".into(),
220+
label: "e2".into(),
167221
additional_data: &[],
168-
timestamp: SystemTime::UNIX_EPOCH + Duration::from_secs(6),
222+
timestamp: SystemTime::UNIX_EPOCH + Duration::from_secs(5),
169223
timestamp_kind: TimestampKind::End,
170224
thread_id: 2,
171225
},
@@ -174,9 +228,10 @@ mod test {
174228
let recorded_stacks = super::collapse_stacks(events.iter().cloned(), 1000);
175229

176230
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);
180235

181236
assert_eq!(expected_stacks, recorded_stacks);
182237
}

0 commit comments

Comments
 (0)