OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Test of classes in the tracked_objects.h classes. | 5 // Test of classes in the tracked_objects.h classes. |
6 | 6 |
7 #include "base/tracked_objects.h" | 7 #include "base/tracked_objects.h" |
8 | 8 |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // Test time in milliseconds. | 116 // Test time in milliseconds. |
117 static unsigned int test_time_; | 117 static unsigned int test_time_; |
118 }; | 118 }; |
119 | 119 |
120 // static | 120 // static |
121 unsigned int TrackedObjectsTest::test_time_; | 121 unsigned int TrackedObjectsTest::test_time_; |
122 | 122 |
123 TEST_F(TrackedObjectsTest, TaskStopwatchNoStartStop) { | 123 TEST_F(TrackedObjectsTest, TaskStopwatchNoStartStop) { |
124 if (!ThreadData::InitializeAndSetTrackingStatus( | 124 if (!ThreadData::InitializeAndSetTrackingStatus( |
125 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 125 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 126 // Don't run the test if task tracking is not compiled in. |
126 return; | 127 return; |
127 } | 128 } |
128 | 129 |
129 // Check that creating and destroying a stopwatch without starting it doesn't | 130 // Check that creating and destroying a stopwatch without starting it doesn't |
130 // crash. | 131 // crash. |
131 TaskStopwatch stopwatch; | 132 TaskStopwatch stopwatch; |
132 } | 133 } |
133 | 134 |
134 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { | 135 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { |
135 // Minimal test doesn't even create any tasks. | 136 // Minimal test doesn't even create any tasks. |
136 if (!ThreadData::InitializeAndSetTrackingStatus( | 137 if (!ThreadData::InitializeAndSetTrackingStatus( |
137 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 138 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 139 // Don't run the test if task tracking is not compiled in. |
138 return; | 140 return; |
139 } | 141 } |
140 | 142 |
141 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. | 143 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
142 ThreadData* data = ThreadData::Get(); | 144 ThreadData* data = ThreadData::Get(); |
143 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. | 145 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
144 ASSERT_TRUE(data); | 146 ASSERT_TRUE(data); |
145 EXPECT_FALSE(data->next()); | 147 EXPECT_FALSE(data->next()); |
146 EXPECT_EQ(data, ThreadData::Get()); | 148 EXPECT_EQ(data, ThreadData::Get()); |
147 ThreadData::BirthMap birth_map; | 149 ThreadData::BirthMap birth_map; |
148 ThreadData::DeathMap death_map; | 150 ThreadData::DeathMap death_map; |
149 ThreadData::ParentChildSet parent_child_set; | 151 ThreadData::ParentChildSet parent_child_set; |
150 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); | 152 data->SnapshotMaps(&birth_map, &death_map, nullptr, &parent_child_set); |
151 EXPECT_EQ(0u, birth_map.size()); | 153 EXPECT_EQ(0u, birth_map.size()); |
152 EXPECT_EQ(0u, death_map.size()); | 154 EXPECT_EQ(0u, death_map.size()); |
153 EXPECT_EQ(0u, parent_child_set.size()); | 155 EXPECT_EQ(0u, parent_child_set.size()); |
154 | 156 |
155 // Clean up with no leaking. | 157 // Clean up with no leaking. |
156 Reset(); | 158 Reset(); |
157 | 159 |
158 // Do it again, just to be sure we reset state completely. | 160 // Do it again, just to be sure we reset state completely. |
159 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( | 161 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( |
160 ThreadData::PROFILING_CHILDREN_ACTIVE)); | 162 ThreadData::PROFILING_CHILDREN_ACTIVE)); |
161 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. | 163 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
162 data = ThreadData::Get(); | 164 data = ThreadData::Get(); |
163 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. | 165 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
164 ASSERT_TRUE(data); | 166 ASSERT_TRUE(data); |
165 EXPECT_FALSE(data->next()); | 167 EXPECT_FALSE(data->next()); |
166 EXPECT_EQ(data, ThreadData::Get()); | 168 EXPECT_EQ(data, ThreadData::Get()); |
167 birth_map.clear(); | 169 birth_map.clear(); |
168 death_map.clear(); | 170 death_map.clear(); |
169 parent_child_set.clear(); | 171 parent_child_set.clear(); |
170 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); | 172 data->SnapshotMaps(&birth_map, &death_map, nullptr, &parent_child_set); |
171 EXPECT_EQ(0u, birth_map.size()); | 173 EXPECT_EQ(0u, birth_map.size()); |
172 EXPECT_EQ(0u, death_map.size()); | 174 EXPECT_EQ(0u, death_map.size()); |
173 EXPECT_EQ(0u, parent_child_set.size()); | 175 EXPECT_EQ(0u, parent_child_set.size()); |
174 } | 176 } |
175 | 177 |
176 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { | 178 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { |
177 if (!ThreadData::InitializeAndSetTrackingStatus( | 179 if (!ThreadData::InitializeAndSetTrackingStatus( |
178 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 180 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 181 // Don't run the test if task tracking is not compiled in. |
179 return; | 182 return; |
180 } | 183 } |
181 | 184 |
182 // Instigate tracking on a single tracked object, on our thread. | 185 // Instigate tracking on a single tracked object, on our thread. |
183 const char kFunction[] = "TinyStartupShutdown"; | 186 const char kFunction[] = "TinyStartupShutdown"; |
184 Location location(kFunction, kFile, kLineNumber, NULL); | 187 Location location(kFunction, kFile, kLineNumber, NULL); |
185 Births* first_birth = ThreadData::TallyABirthIfActive(location); | 188 Births* first_birth = ThreadData::TallyABirthIfActive(location); |
186 | 189 |
187 ThreadData* data = ThreadData::first(); | 190 ThreadData* data = ThreadData::first(); |
188 ASSERT_TRUE(data); | 191 ASSERT_TRUE(data); |
189 EXPECT_FALSE(data->next()); | 192 EXPECT_FALSE(data->next()); |
190 EXPECT_EQ(data, ThreadData::Get()); | 193 EXPECT_EQ(data, ThreadData::Get()); |
191 ThreadData::BirthMap birth_map; | 194 ThreadData::BirthMap birth_map; |
192 ThreadData::DeathMap death_map; | 195 ThreadData::DeathMap death_map; |
193 ThreadData::ParentChildSet parent_child_set; | 196 ThreadData::ParentChildSet parent_child_set; |
194 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); | 197 data->SnapshotMaps(&birth_map, &death_map, nullptr, &parent_child_set); |
195 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 198 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
196 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. | 199 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. |
197 EXPECT_EQ(0u, death_map.size()); // No deaths. | 200 EXPECT_EQ(0u, death_map.size()); // No deaths. |
198 EXPECT_EQ(0u, parent_child_set.size()); // No children. | 201 EXPECT_EQ(0u, parent_child_set.size()); // No children. |
199 | 202 |
200 | 203 |
201 // Now instigate another birth, while we are timing the run of the first | 204 // Now instigate another birth, while we are timing the run of the first |
202 // execution. | 205 // execution. |
203 ThreadData::PrepareForStartOfRun(first_birth); | 206 ThreadData::PrepareForStartOfRun(first_birth); |
204 // Create a child (using the same birth location). | 207 // Create a child (using the same birth location). |
205 // TrackingInfo will call TallyABirth() during construction. | 208 // TrackingInfo will call TallyABirth() during construction. |
206 const int32 start_time = 1; | 209 const int32 start_time = 1; |
207 base::TimeTicks kBogusBirthTime = base::TimeTicks() + | 210 base::TimeTicks kBogusBirthTime = base::TimeTicks() + |
208 base::TimeDelta::FromMilliseconds(start_time); | 211 base::TimeDelta::FromMilliseconds(start_time); |
209 base::TrackingInfo pending_task(location, kBogusBirthTime); | 212 base::TrackingInfo pending_task(location, kBogusBirthTime); |
210 SetTestTime(1); | 213 SetTestTime(1); |
211 TaskStopwatch stopwatch; | 214 TaskStopwatch stopwatch; |
212 stopwatch.Start(); | 215 stopwatch.Start(); |
213 // Finally conclude the outer run. | 216 // Finally conclude the outer run. |
214 const int32 time_elapsed = 1000; | 217 const int32 time_elapsed = 1000; |
215 SetTestTime(start_time + time_elapsed); | 218 SetTestTime(start_time + time_elapsed); |
216 stopwatch.Stop(); | 219 stopwatch.Stop(); |
217 | 220 |
218 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 221 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
219 | 222 |
220 birth_map.clear(); | 223 birth_map.clear(); |
221 death_map.clear(); | 224 death_map.clear(); |
222 parent_child_set.clear(); | 225 parent_child_set.clear(); |
223 data->SnapshotMaps(&birth_map, &death_map, &parent_child_set); | 226 data->SnapshotMaps(&birth_map, &death_map, nullptr, &parent_child_set); |
224 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 227 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
225 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. | 228 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. |
226 EXPECT_EQ(1u, death_map.size()); // 1 location. | 229 EXPECT_EQ(1u, death_map.size()); // 1 location. |
227 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. | 230 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. |
228 if (ThreadData::TrackingParentChildStatus()) { | 231 if (ThreadData::TrackingParentChildStatus()) { |
229 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. | 232 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. |
230 EXPECT_EQ(parent_child_set.begin()->first, | 233 EXPECT_EQ(parent_child_set.begin()->first, |
231 parent_child_set.begin()->second); | 234 parent_child_set.begin()->second); |
232 } else { | 235 } else { |
233 EXPECT_EQ(0u, parent_child_set.size()); // no stats. | 236 EXPECT_EQ(0u, parent_child_set.size()); // no stats. |
234 } | 237 } |
235 | 238 |
236 // The births were at the same location as the one known death. | 239 // The births were at the same location as the one known death. |
237 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); | 240 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); |
238 | 241 |
239 ProcessDataSnapshot process_data; | 242 ProcessDataSnapshot process_data; |
240 ThreadData::Snapshot(&process_data); | 243 ThreadData::Snapshot(0, &process_data); |
241 | 244 |
242 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); | 245 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); |
243 auto it = process_data.phased_process_data_snapshots.find(0); | 246 auto it = process_data.phased_process_data_snapshots.find(0); |
244 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); | 247 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); |
245 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | 248 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
246 ASSERT_EQ(1u, process_data_phase.tasks.size()); | 249 ASSERT_EQ(1u, process_data_phase.tasks.size()); |
247 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); | 250 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); |
248 EXPECT_EQ(kFunction, | 251 EXPECT_EQ(kFunction, |
249 process_data_phase.tasks[0].birth.location.function_name); | 252 process_data_phase.tasks[0].birth.location.function_name); |
250 EXPECT_EQ(kLineNumber, | 253 EXPECT_EQ(kLineNumber, |
(...skipping 30 matching lines...) Expand all Loading... |
281 EXPECT_EQ(kWorkerThreadName, | 284 EXPECT_EQ(kWorkerThreadName, |
282 process_data_phase.descendants[0].child.thread_name); | 285 process_data_phase.descendants[0].child.thread_name); |
283 } else { | 286 } else { |
284 EXPECT_EQ(0u, process_data_phase.descendants.size()); | 287 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
285 } | 288 } |
286 } | 289 } |
287 | 290 |
288 TEST_F(TrackedObjectsTest, DeathDataTest) { | 291 TEST_F(TrackedObjectsTest, DeathDataTest) { |
289 if (!ThreadData::InitializeAndSetTrackingStatus( | 292 if (!ThreadData::InitializeAndSetTrackingStatus( |
290 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 293 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 294 // Don't run the test if task tracking is not compiled in. |
291 return; | 295 return; |
292 } | 296 } |
293 | 297 |
294 scoped_ptr<DeathData> data(new DeathData()); | 298 scoped_ptr<DeathData> data(new DeathData()); |
295 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); | 299 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); |
296 EXPECT_EQ(data->run_duration_sum(), 0); | 300 EXPECT_EQ(data->run_duration_sum(), 0); |
297 EXPECT_EQ(data->run_duration_sample(), 0); | 301 EXPECT_EQ(data->run_duration_sample(), 0); |
298 EXPECT_EQ(data->queue_duration_sum(), 0); | 302 EXPECT_EQ(data->queue_duration_sum(), 0); |
299 EXPECT_EQ(data->queue_duration_sample(), 0); | 303 EXPECT_EQ(data->queue_duration_sample(), 0); |
300 EXPECT_EQ(data->count(), 0); | 304 EXPECT_EQ(data->count(), 0); |
(...skipping 22 matching lines...) Expand all Loading... |
323 EXPECT_EQ(run_ms, snapshot.run_duration_max); | 327 EXPECT_EQ(run_ms, snapshot.run_duration_max); |
324 EXPECT_EQ(run_ms, snapshot.run_duration_sample); | 328 EXPECT_EQ(run_ms, snapshot.run_duration_sample); |
325 EXPECT_EQ(2 * queue_ms, snapshot.queue_duration_sum); | 329 EXPECT_EQ(2 * queue_ms, snapshot.queue_duration_sum); |
326 EXPECT_EQ(queue_ms, snapshot.queue_duration_max); | 330 EXPECT_EQ(queue_ms, snapshot.queue_duration_max); |
327 EXPECT_EQ(queue_ms, snapshot.queue_duration_sample); | 331 EXPECT_EQ(queue_ms, snapshot.queue_duration_sample); |
328 } | 332 } |
329 | 333 |
330 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotWorkerThread) { | 334 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotWorkerThread) { |
331 // Start in the deactivated state. | 335 // Start in the deactivated state. |
332 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { | 336 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { |
| 337 // Don't run the test if task tracking is not compiled in. |
333 return; | 338 return; |
334 } | 339 } |
335 | 340 |
336 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread"; | 341 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread"; |
337 Location location(kFunction, kFile, kLineNumber, NULL); | 342 Location location(kFunction, kFile, kLineNumber, NULL); |
338 TallyABirth(location, std::string()); | 343 TallyABirth(location, std::string()); |
339 | 344 |
340 ProcessDataSnapshot process_data; | 345 ProcessDataSnapshot process_data; |
341 ThreadData::Snapshot(&process_data); | 346 ThreadData::Snapshot(0, &process_data); |
342 | 347 |
343 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); | 348 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); |
344 auto it = process_data.phased_process_data_snapshots.find(0); | 349 auto it = process_data.phased_process_data_snapshots.find(0); |
345 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); | 350 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); |
346 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | 351 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
347 | 352 |
348 EXPECT_EQ(0u, process_data_phase.tasks.size()); | 353 EXPECT_EQ(0u, process_data_phase.tasks.size()); |
349 EXPECT_EQ(0u, process_data_phase.descendants.size()); | 354 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
350 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 355 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
351 } | 356 } |
352 | 357 |
353 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) { | 358 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) { |
354 // Start in the deactivated state. | 359 // Start in the deactivated state. |
355 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { | 360 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { |
| 361 // Don't run the test if task tracking is not compiled in. |
356 return; | 362 return; |
357 } | 363 } |
358 | 364 |
359 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread"; | 365 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread"; |
360 Location location(kFunction, kFile, kLineNumber, NULL); | 366 Location location(kFunction, kFile, kLineNumber, NULL); |
361 TallyABirth(location, kMainThreadName); | 367 TallyABirth(location, kMainThreadName); |
362 | 368 |
363 ProcessDataSnapshot process_data; | 369 ProcessDataSnapshot process_data; |
364 ThreadData::Snapshot(&process_data); | 370 ThreadData::Snapshot(0, &process_data); |
365 | 371 |
366 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); | 372 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); |
367 auto it = process_data.phased_process_data_snapshots.find(0); | 373 auto it = process_data.phased_process_data_snapshots.find(0); |
368 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); | 374 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); |
369 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | 375 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
370 | 376 |
371 EXPECT_EQ(0u, process_data_phase.tasks.size()); | 377 EXPECT_EQ(0u, process_data_phase.tasks.size()); |
372 EXPECT_EQ(0u, process_data_phase.descendants.size()); | 378 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
373 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 379 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
374 } | 380 } |
375 | 381 |
376 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { | 382 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { |
377 if (!ThreadData::InitializeAndSetTrackingStatus( | 383 if (!ThreadData::InitializeAndSetTrackingStatus( |
378 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 384 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 385 // Don't run the test if task tracking is not compiled in. |
379 return; | 386 return; |
380 } | 387 } |
381 | 388 |
382 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; | 389 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; |
383 Location location(kFunction, kFile, kLineNumber, NULL); | 390 Location location(kFunction, kFile, kLineNumber, NULL); |
384 TallyABirth(location, std::string()); | 391 TallyABirth(location, std::string()); |
385 | 392 |
386 ProcessDataSnapshot process_data; | 393 ProcessDataSnapshot process_data; |
387 ThreadData::Snapshot(&process_data); | 394 ThreadData::Snapshot(0, &process_data); |
388 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, | 395 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, |
389 kStillAlive, 1, 0, 0); | 396 kStillAlive, 1, 0, 0); |
390 } | 397 } |
391 | 398 |
392 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { | 399 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { |
393 if (!ThreadData::InitializeAndSetTrackingStatus( | 400 if (!ThreadData::InitializeAndSetTrackingStatus( |
394 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 401 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 402 // Don't run the test if task tracking is not compiled in. |
395 return; | 403 return; |
396 } | 404 } |
397 | 405 |
398 const char kFunction[] = "BirthOnlyToSnapshotMainThread"; | 406 const char kFunction[] = "BirthOnlyToSnapshotMainThread"; |
399 Location location(kFunction, kFile, kLineNumber, NULL); | 407 Location location(kFunction, kFile, kLineNumber, NULL); |
400 TallyABirth(location, kMainThreadName); | 408 TallyABirth(location, kMainThreadName); |
401 | 409 |
402 ProcessDataSnapshot process_data; | 410 ProcessDataSnapshot process_data; |
403 ThreadData::Snapshot(&process_data); | 411 ThreadData::Snapshot(0, &process_data); |
404 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, | 412 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, |
405 1, 0, 0); | 413 1, 0, 0); |
406 } | 414 } |
407 | 415 |
408 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { | 416 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { |
409 if (!ThreadData::InitializeAndSetTrackingStatus( | 417 if (!ThreadData::InitializeAndSetTrackingStatus( |
410 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 418 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 419 // Don't run the test if task tracking is not compiled in. |
411 return; | 420 return; |
412 } | 421 } |
413 | 422 |
414 const char kFunction[] = "LifeCycleToSnapshotMainThread"; | 423 const char kFunction[] = "LifeCycleToSnapshotMainThread"; |
415 Location location(kFunction, kFile, kLineNumber, NULL); | 424 Location location(kFunction, kFile, kLineNumber, NULL); |
416 TallyABirth(location, kMainThreadName); | 425 TallyABirth(location, kMainThreadName); |
417 | 426 |
418 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 427 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
419 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 428 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
420 // TrackingInfo will call TallyABirth() during construction. | 429 // TrackingInfo will call TallyABirth() during construction. |
421 base::TrackingInfo pending_task(location, kDelayedStartTime); | 430 base::TrackingInfo pending_task(location, kDelayedStartTime); |
422 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 431 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
423 | 432 |
424 const unsigned int kStartOfRun = 5; | 433 const unsigned int kStartOfRun = 5; |
425 const unsigned int kEndOfRun = 7; | 434 const unsigned int kEndOfRun = 7; |
426 SetTestTime(kStartOfRun); | 435 SetTestTime(kStartOfRun); |
427 TaskStopwatch stopwatch; | 436 TaskStopwatch stopwatch; |
428 stopwatch.Start(); | 437 stopwatch.Start(); |
429 SetTestTime(kEndOfRun); | 438 SetTestTime(kEndOfRun); |
430 stopwatch.Stop(); | 439 stopwatch.Stop(); |
431 | 440 |
432 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 441 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
433 | 442 |
434 ProcessDataSnapshot process_data; | 443 ProcessDataSnapshot process_data; |
435 ThreadData::Snapshot(&process_data); | 444 ThreadData::Snapshot(0, &process_data); |
436 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 445 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
437 kMainThreadName, 1, 2, 4); | 446 kMainThreadName, 1, 2, 4); |
438 } | 447 } |
439 | 448 |
| 449 TEST_F(TrackedObjectsTest, TwoPhases) { |
| 450 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 451 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 452 // Don't run the test if task tracking is not compiled in. |
| 453 return; |
| 454 } |
| 455 |
| 456 const char kFunction[] = "TwoPhases"; |
| 457 Location location(kFunction, kFile, kLineNumber, NULL); |
| 458 TallyABirth(location, kMainThreadName); |
| 459 |
| 460 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 461 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 462 // TrackingInfo will call TallyABirth() during construction. |
| 463 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 464 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 465 |
| 466 const unsigned int kStartOfRun = 5; |
| 467 const unsigned int kEndOfRun = 7; |
| 468 SetTestTime(kStartOfRun); |
| 469 TaskStopwatch stopwatch; |
| 470 stopwatch.Start(); |
| 471 SetTestTime(kEndOfRun); |
| 472 stopwatch.Stop(); |
| 473 |
| 474 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 475 |
| 476 ThreadData::OnProfilingPhaseCompletion(0); |
| 477 |
| 478 TallyABirth(location, kMainThreadName); |
| 479 |
| 480 const TrackedTime kTimePosted1 = TrackedTime::FromMilliseconds(9); |
| 481 const base::TimeTicks kDelayedStartTime1 = base::TimeTicks(); |
| 482 // TrackingInfo will call TallyABirth() during construction. |
| 483 base::TrackingInfo pending_task1(location, kDelayedStartTime1); |
| 484 pending_task1.time_posted = kTimePosted1; // Overwrite implied Now(). |
| 485 |
| 486 const unsigned int kStartOfRun1 = 11; |
| 487 const unsigned int kEndOfRun1 = 21; |
| 488 SetTestTime(kStartOfRun1); |
| 489 TaskStopwatch stopwatch1; |
| 490 stopwatch1.Start(); |
| 491 SetTestTime(kEndOfRun1); |
| 492 stopwatch1.Stop(); |
| 493 |
| 494 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task1, stopwatch1); |
| 495 |
| 496 ProcessDataSnapshot process_data; |
| 497 ThreadData::Snapshot(1, &process_data); |
| 498 |
| 499 ASSERT_EQ(2u, process_data.phased_process_data_snapshots.size()); |
| 500 |
| 501 auto it0 = process_data.phased_process_data_snapshots.find(0); |
| 502 ASSERT_TRUE(it0 != process_data.phased_process_data_snapshots.end()); |
| 503 const ProcessDataPhaseSnapshot& process_data_phase0 = it0->second; |
| 504 |
| 505 ASSERT_EQ(1u, process_data_phase0.tasks.size()); |
| 506 |
| 507 EXPECT_EQ(kFile, process_data_phase0.tasks[0].birth.location.file_name); |
| 508 EXPECT_EQ(kFunction, |
| 509 process_data_phase0.tasks[0].birth.location.function_name); |
| 510 EXPECT_EQ(kLineNumber, |
| 511 process_data_phase0.tasks[0].birth.location.line_number); |
| 512 |
| 513 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].birth.thread_name); |
| 514 |
| 515 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count); |
| 516 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sum); |
| 517 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_max); |
| 518 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sample); |
| 519 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sum); |
| 520 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_max); |
| 521 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sample); |
| 522 |
| 523 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name); |
| 524 |
| 525 EXPECT_EQ(0u, process_data_phase0.descendants.size()); |
| 526 |
| 527 auto it1 = process_data.phased_process_data_snapshots.find(1); |
| 528 ASSERT_TRUE(it1 != process_data.phased_process_data_snapshots.end()); |
| 529 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second; |
| 530 |
| 531 ASSERT_EQ(1u, process_data_phase1.tasks.size()); |
| 532 |
| 533 EXPECT_EQ(kFile, process_data_phase1.tasks[0].birth.location.file_name); |
| 534 EXPECT_EQ(kFunction, |
| 535 process_data_phase1.tasks[0].birth.location.function_name); |
| 536 EXPECT_EQ(kLineNumber, |
| 537 process_data_phase1.tasks[0].birth.location.line_number); |
| 538 |
| 539 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].birth.thread_name); |
| 540 |
| 541 EXPECT_EQ(1, process_data_phase1.tasks[0].death_data.count); |
| 542 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_sum); |
| 543 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_max); |
| 544 EXPECT_EQ(10, process_data_phase1.tasks[0].death_data.run_duration_sample); |
| 545 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sum); |
| 546 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_max); |
| 547 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sample); |
| 548 |
| 549 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name); |
| 550 |
| 551 EXPECT_EQ(0u, process_data_phase1.descendants.size()); |
| 552 |
| 553 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 554 } |
| 555 |
| 556 TEST_F(TrackedObjectsTest, TwoPhasesSecondEmpty) { |
| 557 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 558 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 559 // Don't run the test if task tracking is not compiled in. |
| 560 return; |
| 561 } |
| 562 |
| 563 const char kFunction[] = "TwoPhasesSecondEmpty"; |
| 564 Location location(kFunction, kFile, kLineNumber, NULL); |
| 565 ThreadData::InitializeThreadContext(kMainThreadName); |
| 566 |
| 567 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
| 568 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
| 569 // TrackingInfo will call TallyABirth() during construction. |
| 570 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 571 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 572 |
| 573 const unsigned int kStartOfRun = 5; |
| 574 const unsigned int kEndOfRun = 7; |
| 575 SetTestTime(kStartOfRun); |
| 576 TaskStopwatch stopwatch; |
| 577 stopwatch.Start(); |
| 578 SetTestTime(kEndOfRun); |
| 579 stopwatch.Stop(); |
| 580 |
| 581 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 582 |
| 583 ThreadData::OnProfilingPhaseCompletion(0); |
| 584 |
| 585 ProcessDataSnapshot process_data; |
| 586 ThreadData::Snapshot(1, &process_data); |
| 587 |
| 588 ASSERT_EQ(2u, process_data.phased_process_data_snapshots.size()); |
| 589 |
| 590 auto it0 = process_data.phased_process_data_snapshots.find(0); |
| 591 ASSERT_TRUE(it0 != process_data.phased_process_data_snapshots.end()); |
| 592 const ProcessDataPhaseSnapshot& process_data_phase0 = it0->second; |
| 593 |
| 594 ASSERT_EQ(1u, process_data_phase0.tasks.size()); |
| 595 |
| 596 EXPECT_EQ(kFile, process_data_phase0.tasks[0].birth.location.file_name); |
| 597 EXPECT_EQ(kFunction, |
| 598 process_data_phase0.tasks[0].birth.location.function_name); |
| 599 EXPECT_EQ(kLineNumber, |
| 600 process_data_phase0.tasks[0].birth.location.line_number); |
| 601 |
| 602 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].birth.thread_name); |
| 603 |
| 604 EXPECT_EQ(1, process_data_phase0.tasks[0].death_data.count); |
| 605 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sum); |
| 606 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_max); |
| 607 EXPECT_EQ(2, process_data_phase0.tasks[0].death_data.run_duration_sample); |
| 608 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sum); |
| 609 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_max); |
| 610 EXPECT_EQ(4, process_data_phase0.tasks[0].death_data.queue_duration_sample); |
| 611 |
| 612 EXPECT_EQ(kMainThreadName, process_data_phase0.tasks[0].death_thread_name); |
| 613 |
| 614 EXPECT_EQ(0u, process_data_phase0.descendants.size()); |
| 615 |
| 616 auto it1 = process_data.phased_process_data_snapshots.find(1); |
| 617 ASSERT_TRUE(it1 != process_data.phased_process_data_snapshots.end()); |
| 618 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second; |
| 619 |
| 620 ASSERT_EQ(0u, process_data_phase1.tasks.size()); |
| 621 |
| 622 EXPECT_EQ(0u, process_data_phase1.descendants.size()); |
| 623 |
| 624 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 625 } |
| 626 |
440 // We will deactivate tracking after the birth, and before the death, and | 627 // We will deactivate tracking after the birth, and before the death, and |
441 // demonstrate that the lifecycle is completely tallied. This ensures that | 628 // demonstrate that the lifecycle is completely tallied. This ensures that |
442 // our tallied births are matched by tallied deaths (except for when the | 629 // our tallied births are matched by tallied deaths (except for when the |
443 // task is still running, or is queued). | 630 // task is still running, or is queued). |
444 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { | 631 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { |
445 if (!ThreadData::InitializeAndSetTrackingStatus( | 632 if (!ThreadData::InitializeAndSetTrackingStatus( |
446 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 633 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 634 // Don't run the test if task tracking is not compiled in. |
447 return; | 635 return; |
448 } | 636 } |
449 | 637 |
450 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; | 638 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; |
451 Location location(kFunction, kFile, kLineNumber, NULL); | 639 Location location(kFunction, kFile, kLineNumber, NULL); |
452 TallyABirth(location, kMainThreadName); | 640 TallyABirth(location, kMainThreadName); |
453 | 641 |
454 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 642 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
455 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 643 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
456 // TrackingInfo will call TallyABirth() during construction. | 644 // TrackingInfo will call TallyABirth() during construction. |
457 base::TrackingInfo pending_task(location, kDelayedStartTime); | 645 base::TrackingInfo pending_task(location, kDelayedStartTime); |
458 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 646 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
459 | 647 |
460 // Turn off tracking now that we have births. | 648 // Turn off tracking now that we have births. |
461 EXPECT_TRUE( | 649 EXPECT_TRUE( |
462 ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)); | 650 ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)); |
463 | 651 |
464 const unsigned int kStartOfRun = 5; | 652 const unsigned int kStartOfRun = 5; |
465 const unsigned int kEndOfRun = 7; | 653 const unsigned int kEndOfRun = 7; |
466 SetTestTime(kStartOfRun); | 654 SetTestTime(kStartOfRun); |
467 TaskStopwatch stopwatch; | 655 TaskStopwatch stopwatch; |
468 stopwatch.Start(); | 656 stopwatch.Start(); |
469 SetTestTime(kEndOfRun); | 657 SetTestTime(kEndOfRun); |
470 stopwatch.Stop(); | 658 stopwatch.Stop(); |
471 | 659 |
472 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 660 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
473 | 661 |
474 ProcessDataSnapshot process_data; | 662 ProcessDataSnapshot process_data; |
475 ThreadData::Snapshot(&process_data); | 663 ThreadData::Snapshot(0, &process_data); |
476 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 664 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
477 kMainThreadName, 1, 2, 4); | 665 kMainThreadName, 1, 2, 4); |
478 } | 666 } |
479 | 667 |
480 // We will deactivate tracking before starting a life cycle, and neither | 668 // We will deactivate tracking before starting a life cycle, and neither |
481 // the birth nor the death will be recorded. | 669 // the birth nor the death will be recorded. |
482 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { | 670 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { |
483 // Start in the deactivated state. | 671 // Start in the deactivated state. |
484 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { | 672 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { |
| 673 // Don't run the test if task tracking is not compiled in. |
485 return; | 674 return; |
486 } | 675 } |
487 | 676 |
488 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread"; | 677 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread"; |
489 Location location(kFunction, kFile, kLineNumber, NULL); | 678 Location location(kFunction, kFile, kLineNumber, NULL); |
490 TallyABirth(location, kMainThreadName); | 679 TallyABirth(location, kMainThreadName); |
491 | 680 |
492 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 681 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
493 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 682 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
494 // TrackingInfo will call TallyABirth() during construction. | 683 // TrackingInfo will call TallyABirth() during construction. |
495 base::TrackingInfo pending_task(location, kDelayedStartTime); | 684 base::TrackingInfo pending_task(location, kDelayedStartTime); |
496 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 685 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
497 | 686 |
498 const unsigned int kStartOfRun = 5; | 687 const unsigned int kStartOfRun = 5; |
499 const unsigned int kEndOfRun = 7; | 688 const unsigned int kEndOfRun = 7; |
500 SetTestTime(kStartOfRun); | 689 SetTestTime(kStartOfRun); |
501 TaskStopwatch stopwatch; | 690 TaskStopwatch stopwatch; |
502 stopwatch.Start(); | 691 stopwatch.Start(); |
503 SetTestTime(kEndOfRun); | 692 SetTestTime(kEndOfRun); |
504 stopwatch.Stop(); | 693 stopwatch.Stop(); |
505 | 694 |
506 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 695 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
507 | 696 |
508 ProcessDataSnapshot process_data; | 697 ProcessDataSnapshot process_data; |
509 ThreadData::Snapshot(&process_data); | 698 ThreadData::Snapshot(0, &process_data); |
510 | 699 |
511 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); | 700 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); |
512 auto it = process_data.phased_process_data_snapshots.find(0); | 701 auto it = process_data.phased_process_data_snapshots.find(0); |
513 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); | 702 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); |
514 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | 703 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
515 | 704 |
516 EXPECT_EQ(0u, process_data_phase.tasks.size()); | 705 EXPECT_EQ(0u, process_data_phase.tasks.size()); |
517 EXPECT_EQ(0u, process_data_phase.descendants.size()); | 706 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
518 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 707 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
519 } | 708 } |
520 | 709 |
521 TEST_F(TrackedObjectsTest, TwoLives) { | 710 TEST_F(TrackedObjectsTest, TwoLives) { |
522 if (!ThreadData::InitializeAndSetTrackingStatus( | 711 if (!ThreadData::InitializeAndSetTrackingStatus( |
523 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 712 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 713 // Don't run the test if task tracking is not compiled in. |
524 return; | 714 return; |
525 } | 715 } |
526 | 716 |
527 const char kFunction[] = "TwoLives"; | 717 const char kFunction[] = "TwoLives"; |
528 Location location(kFunction, kFile, kLineNumber, NULL); | 718 Location location(kFunction, kFile, kLineNumber, NULL); |
529 TallyABirth(location, kMainThreadName); | 719 TallyABirth(location, kMainThreadName); |
530 | 720 |
531 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 721 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
532 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 722 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
533 // TrackingInfo will call TallyABirth() during construction. | 723 // TrackingInfo will call TallyABirth() during construction. |
(...skipping 15 matching lines...) Expand all Loading... |
549 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). | 739 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
550 SetTestTime(kStartOfRun); | 740 SetTestTime(kStartOfRun); |
551 TaskStopwatch stopwatch2; | 741 TaskStopwatch stopwatch2; |
552 stopwatch2.Start(); | 742 stopwatch2.Start(); |
553 SetTestTime(kEndOfRun); | 743 SetTestTime(kEndOfRun); |
554 stopwatch2.Stop(); | 744 stopwatch2.Stop(); |
555 | 745 |
556 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2); | 746 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2); |
557 | 747 |
558 ProcessDataSnapshot process_data; | 748 ProcessDataSnapshot process_data; |
559 ThreadData::Snapshot(&process_data); | 749 ThreadData::Snapshot(0, &process_data); |
560 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 750 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
561 kMainThreadName, 2, 2, 4); | 751 kMainThreadName, 2, 2, 4); |
562 } | 752 } |
563 | 753 |
564 TEST_F(TrackedObjectsTest, DifferentLives) { | 754 TEST_F(TrackedObjectsTest, DifferentLives) { |
565 if (!ThreadData::InitializeAndSetTrackingStatus( | 755 if (!ThreadData::InitializeAndSetTrackingStatus( |
566 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 756 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 757 // Don't run the test if task tracking is not compiled in. |
567 return; | 758 return; |
568 } | 759 } |
569 | 760 |
570 // Use a well named thread. | 761 // Use a well named thread. |
571 ThreadData::InitializeThreadContext(kMainThreadName); | 762 ThreadData::InitializeThreadContext(kMainThreadName); |
572 const char kFunction[] = "DifferentLives"; | 763 const char kFunction[] = "DifferentLives"; |
573 Location location(kFunction, kFile, kLineNumber, NULL); | 764 Location location(kFunction, kFile, kLineNumber, NULL); |
574 | 765 |
575 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 766 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
576 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 767 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
(...skipping 12 matching lines...) Expand all Loading... |
589 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 780 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
590 | 781 |
591 const int kSecondFakeLineNumber = 999; | 782 const int kSecondFakeLineNumber = 999; |
592 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); | 783 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); |
593 | 784 |
594 // TrackingInfo will call TallyABirth() during construction. | 785 // TrackingInfo will call TallyABirth() during construction. |
595 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); | 786 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); |
596 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). | 787 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
597 | 788 |
598 ProcessDataSnapshot process_data; | 789 ProcessDataSnapshot process_data; |
599 ThreadData::Snapshot(&process_data); | 790 ThreadData::Snapshot(0, &process_data); |
600 | 791 |
601 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); | 792 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); |
602 auto it = process_data.phased_process_data_snapshots.find(0); | 793 auto it = process_data.phased_process_data_snapshots.find(0); |
603 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); | 794 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); |
604 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | 795 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
605 | 796 |
606 ASSERT_EQ(2u, process_data_phase.tasks.size()); | 797 ASSERT_EQ(2u, process_data_phase.tasks.size()); |
607 | 798 |
608 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); | 799 EXPECT_EQ(kFile, process_data_phase.tasks[0].birth.location.file_name); |
609 EXPECT_EQ(kFunction, | 800 EXPECT_EQ(kFunction, |
(...skipping 23 matching lines...) Expand all Loading... |
633 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_max); | 824 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_max); |
634 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_sample); | 825 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_sample); |
635 EXPECT_EQ(kStillAlive, process_data_phase.tasks[1].death_thread_name); | 826 EXPECT_EQ(kStillAlive, process_data_phase.tasks[1].death_thread_name); |
636 EXPECT_EQ(0u, process_data_phase.descendants.size()); | 827 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
637 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 828 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
638 } | 829 } |
639 | 830 |
640 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) { | 831 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) { |
641 if (!ThreadData::InitializeAndSetTrackingStatus( | 832 if (!ThreadData::InitializeAndSetTrackingStatus( |
642 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 833 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 834 // Don't run the test if task tracking is not compiled in. |
643 return; | 835 return; |
644 } | 836 } |
645 | 837 |
646 const char kFunction[] = "TaskWithNestedExclusion"; | 838 const char kFunction[] = "TaskWithNestedExclusion"; |
647 Location location(kFunction, kFile, kLineNumber, NULL); | 839 Location location(kFunction, kFile, kLineNumber, NULL); |
648 TallyABirth(location, kMainThreadName); | 840 TallyABirth(location, kMainThreadName); |
649 | 841 |
650 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 842 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
651 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 843 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
652 // TrackingInfo will call TallyABirth() during construction. | 844 // TrackingInfo will call TallyABirth() during construction. |
653 base::TrackingInfo pending_task(location, kDelayedStartTime); | 845 base::TrackingInfo pending_task(location, kDelayedStartTime); |
654 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 846 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
655 | 847 |
656 SetTestTime(5); | 848 SetTestTime(5); |
657 TaskStopwatch task_stopwatch; | 849 TaskStopwatch task_stopwatch; |
658 task_stopwatch.Start(); | 850 task_stopwatch.Start(); |
659 { | 851 { |
660 SetTestTime(8); | 852 SetTestTime(8); |
661 TaskStopwatch exclusion_stopwatch; | 853 TaskStopwatch exclusion_stopwatch; |
662 exclusion_stopwatch.Start(); | 854 exclusion_stopwatch.Start(); |
663 SetTestTime(12); | 855 SetTestTime(12); |
664 exclusion_stopwatch.Stop(); | 856 exclusion_stopwatch.Stop(); |
665 } | 857 } |
666 SetTestTime(15); | 858 SetTestTime(15); |
667 task_stopwatch.Stop(); | 859 task_stopwatch.Stop(); |
668 | 860 |
669 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); | 861 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); |
670 | 862 |
671 ProcessDataSnapshot process_data; | 863 ProcessDataSnapshot process_data; |
672 ThreadData::Snapshot(&process_data); | 864 ThreadData::Snapshot(0, &process_data); |
673 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 865 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
674 kMainThreadName, 1, 6, 4); | 866 kMainThreadName, 1, 6, 4); |
675 } | 867 } |
676 | 868 |
677 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) { | 869 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) { |
678 if (!ThreadData::InitializeAndSetTrackingStatus( | 870 if (!ThreadData::InitializeAndSetTrackingStatus( |
679 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 871 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 872 // Don't run the test if task tracking is not compiled in. |
680 return; | 873 return; |
681 } | 874 } |
682 | 875 |
683 const char kFunction[] = "TaskWith2NestedExclusions"; | 876 const char kFunction[] = "TaskWith2NestedExclusions"; |
684 Location location(kFunction, kFile, kLineNumber, NULL); | 877 Location location(kFunction, kFile, kLineNumber, NULL); |
685 TallyABirth(location, kMainThreadName); | 878 TallyABirth(location, kMainThreadName); |
686 | 879 |
687 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); | 880 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); |
688 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); | 881 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); |
689 // TrackingInfo will call TallyABirth() during construction. | 882 // TrackingInfo will call TallyABirth() during construction. |
(...skipping 15 matching lines...) Expand all Loading... |
705 exclusion_stopwatch2.Start(); | 898 exclusion_stopwatch2.Start(); |
706 SetTestTime(18); | 899 SetTestTime(18); |
707 exclusion_stopwatch2.Stop(); | 900 exclusion_stopwatch2.Stop(); |
708 } | 901 } |
709 SetTestTime(25); | 902 SetTestTime(25); |
710 task_stopwatch.Stop(); | 903 task_stopwatch.Stop(); |
711 | 904 |
712 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); | 905 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); |
713 | 906 |
714 ProcessDataSnapshot process_data; | 907 ProcessDataSnapshot process_data; |
715 ThreadData::Snapshot(&process_data); | 908 ThreadData::Snapshot(0, &process_data); |
716 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, | 909 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, |
717 kMainThreadName, 1, 13, 4); | 910 kMainThreadName, 1, 13, 4); |
718 } | 911 } |
719 | 912 |
720 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) { | 913 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) { |
721 if (!ThreadData::InitializeAndSetTrackingStatus( | 914 if (!ThreadData::InitializeAndSetTrackingStatus( |
722 ThreadData::PROFILING_CHILDREN_ACTIVE)) { | 915 ThreadData::PROFILING_CHILDREN_ACTIVE)) { |
| 916 // Don't run the test if task tracking is not compiled in. |
723 return; | 917 return; |
724 } | 918 } |
725 | 919 |
726 const char kFunction[] = "TaskWithNestedExclusionWithNestedTask"; | 920 const char kFunction[] = "TaskWithNestedExclusionWithNestedTask"; |
727 Location location(kFunction, kFile, kLineNumber, NULL); | 921 Location location(kFunction, kFile, kLineNumber, NULL); |
728 | 922 |
729 const int kSecondFakeLineNumber = 999; | 923 const int kSecondFakeLineNumber = 999; |
730 | 924 |
731 TallyABirth(location, kMainThreadName); | 925 TallyABirth(location, kMainThreadName); |
732 | 926 |
(...skipping 25 matching lines...) Expand all Loading... |
758 } | 952 } |
759 SetTestTime(12); | 953 SetTestTime(12); |
760 exclusion_stopwatch.Stop(); | 954 exclusion_stopwatch.Stop(); |
761 } | 955 } |
762 SetTestTime(15); | 956 SetTestTime(15); |
763 task_stopwatch.Stop(); | 957 task_stopwatch.Stop(); |
764 | 958 |
765 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); | 959 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); |
766 | 960 |
767 ProcessDataSnapshot process_data; | 961 ProcessDataSnapshot process_data; |
768 ThreadData::Snapshot(&process_data); | 962 ThreadData::Snapshot(0, &process_data); |
769 | 963 |
770 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); | 964 ASSERT_EQ(1u, process_data.phased_process_data_snapshots.size()); |
771 auto it = process_data.phased_process_data_snapshots.find(0); | 965 auto it = process_data.phased_process_data_snapshots.find(0); |
772 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); | 966 ASSERT_TRUE(it != process_data.phased_process_data_snapshots.end()); |
773 const ProcessDataPhaseSnapshot& process_data_phase = it->second; | 967 const ProcessDataPhaseSnapshot& process_data_phase = it->second; |
774 | 968 |
775 // The order in which the two task follow is platform-dependent. | 969 // The order in which the two task follow is platform-dependent. |
776 int t0 = | 970 int t0 = |
777 (process_data_phase.tasks[0].birth.location.line_number == kLineNumber) | 971 (process_data_phase.tasks[0].birth.location.line_number == kLineNumber) |
778 ? 0 | 972 ? 0 |
(...skipping 27 matching lines...) Expand all Loading... |
806 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample); | 1000 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample); |
807 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum); | 1001 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum); |
808 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max); | 1002 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max); |
809 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample); | 1003 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample); |
810 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name); | 1004 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name); |
811 EXPECT_EQ(0u, process_data_phase.descendants.size()); | 1005 EXPECT_EQ(0u, process_data_phase.descendants.size()); |
812 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 1006 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
813 } | 1007 } |
814 | 1008 |
815 } // namespace tracked_objects | 1009 } // namespace tracked_objects |
OLD | NEW |