Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2537)

Side by Side Diff: base/tracked_objects_unittest.cc

Issue 1124493002: Cleanup: given that TLS slot can't fail to initialize, remove bool return values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@parchild
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« base/tracked_objects.cc ('K') | « base/tracked_objects.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 static unsigned int GetTestTime() { return test_time_; } 112 static unsigned int GetTestTime() { return test_time_; }
113 113
114 // Test time in milliseconds. 114 // Test time in milliseconds.
115 static unsigned int test_time_; 115 static unsigned int test_time_;
116 }; 116 };
117 117
118 // static 118 // static
119 unsigned int TrackedObjectsTest::test_time_; 119 unsigned int TrackedObjectsTest::test_time_;
120 120
121 TEST_F(TrackedObjectsTest, TaskStopwatchNoStartStop) { 121 TEST_F(TrackedObjectsTest, TaskStopwatchNoStartStop) {
122 if (!ThreadData::InitializeAndSetTrackingStatus( 122 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
123 ThreadData::PROFILING_ACTIVE)) {
124 // Don't run the test if task tracking is not compiled in.
125 return;
126 }
127 123
128 // Check that creating and destroying a stopwatch without starting it doesn't 124 // Check that creating and destroying a stopwatch without starting it doesn't
129 // crash. 125 // crash.
130 TaskStopwatch stopwatch; 126 TaskStopwatch stopwatch;
131 } 127 }
132 128
133 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { 129 TEST_F(TrackedObjectsTest, MinimalStartupShutdown) {
134 // Minimal test doesn't even create any tasks. 130 // Minimal test doesn't even create any tasks.
135 if (!ThreadData::InitializeAndSetTrackingStatus( 131 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
136 ThreadData::PROFILING_ACTIVE)) {
137 // Don't run the test if task tracking is not compiled in.
138 return;
139 }
140 132
141 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. 133 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread.
142 ThreadData* data = ThreadData::Get(); 134 ThreadData* data = ThreadData::Get();
143 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. 135 EXPECT_TRUE(ThreadData::first()); // Now class was constructed.
144 ASSERT_TRUE(data); 136 ASSERT_TRUE(data);
145 EXPECT_FALSE(data->next()); 137 EXPECT_FALSE(data->next());
146 EXPECT_EQ(data, ThreadData::Get()); 138 EXPECT_EQ(data, ThreadData::Get());
147 ThreadData::BirthMap birth_map; 139 ThreadData::BirthMap birth_map;
148 ThreadData::DeathsSnapshot deaths; 140 ThreadData::DeathsSnapshot deaths;
149 data->SnapshotMaps(0, &birth_map, &deaths); 141 data->SnapshotMaps(0, &birth_map, &deaths);
150 EXPECT_EQ(0u, birth_map.size()); 142 EXPECT_EQ(0u, birth_map.size());
151 EXPECT_EQ(0u, deaths.size()); 143 EXPECT_EQ(0u, deaths.size());
152 144
153 // Clean up with no leaking. 145 // Clean up with no leaking.
154 Reset(); 146 Reset();
155 147
156 // Do it again, just to be sure we reset state completely. 148 // Do it again, just to be sure we reset state completely.
157 EXPECT_TRUE( 149 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
158 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE));
159 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. 150 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread.
160 data = ThreadData::Get(); 151 data = ThreadData::Get();
161 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. 152 EXPECT_TRUE(ThreadData::first()); // Now class was constructed.
162 ASSERT_TRUE(data); 153 ASSERT_TRUE(data);
163 EXPECT_FALSE(data->next()); 154 EXPECT_FALSE(data->next());
164 EXPECT_EQ(data, ThreadData::Get()); 155 EXPECT_EQ(data, ThreadData::Get());
165 birth_map.clear(); 156 birth_map.clear();
166 deaths.clear(); 157 deaths.clear();
167 data->SnapshotMaps(0, &birth_map, &deaths); 158 data->SnapshotMaps(0, &birth_map, &deaths);
168 EXPECT_EQ(0u, birth_map.size()); 159 EXPECT_EQ(0u, birth_map.size());
169 EXPECT_EQ(0u, deaths.size()); 160 EXPECT_EQ(0u, deaths.size());
170 } 161 }
171 162
172 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { 163 TEST_F(TrackedObjectsTest, TinyStartupShutdown) {
173 if (!ThreadData::InitializeAndSetTrackingStatus( 164 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
174 ThreadData::PROFILING_ACTIVE)) {
175 // Don't run the test if task tracking is not compiled in.
176 return;
177 }
178 165
179 // Instigate tracking on a single tracked object, on our thread. 166 // Instigate tracking on a single tracked object, on our thread.
180 const char kFunction[] = "TinyStartupShutdown"; 167 const char kFunction[] = "TinyStartupShutdown";
181 Location location(kFunction, kFile, kLineNumber, NULL); 168 Location location(kFunction, kFile, kLineNumber, NULL);
182 ThreadData::TallyABirthIfActive(location); 169 ThreadData::TallyABirthIfActive(location);
183 170
184 ThreadData* data = ThreadData::first(); 171 ThreadData* data = ThreadData::first();
185 ASSERT_TRUE(data); 172 ASSERT_TRUE(data);
186 EXPECT_FALSE(data->next()); 173 EXPECT_FALSE(data->next());
187 EXPECT_EQ(data, ThreadData::Get()); 174 EXPECT_EQ(data, ThreadData::Get());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 process_data_phase.tasks[0].death_data.run_duration_max); 230 process_data_phase.tasks[0].death_data.run_duration_max);
244 EXPECT_EQ(time_elapsed, 231 EXPECT_EQ(time_elapsed,
245 process_data_phase.tasks[0].death_data.run_duration_sample); 232 process_data_phase.tasks[0].death_data.run_duration_sample);
246 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sum); 233 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sum);
247 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_max); 234 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_max);
248 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sample); 235 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sample);
249 EXPECT_EQ(kWorkerThreadName, process_data_phase.tasks[0].death_thread_name); 236 EXPECT_EQ(kWorkerThreadName, process_data_phase.tasks[0].death_thread_name);
250 } 237 }
251 238
252 TEST_F(TrackedObjectsTest, DeathDataTestRecordDeath) { 239 TEST_F(TrackedObjectsTest, DeathDataTestRecordDeath) {
253 if (!ThreadData::InitializeAndSetTrackingStatus( 240 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
254 ThreadData::PROFILING_ACTIVE)) {
255 // Don't run the test if task tracking is not compiled in.
256 return;
257 }
258 241
259 scoped_ptr<DeathData> data(new DeathData()); 242 scoped_ptr<DeathData> data(new DeathData());
260 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); 243 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL));
261 EXPECT_EQ(data->run_duration_sum(), 0); 244 EXPECT_EQ(data->run_duration_sum(), 0);
262 EXPECT_EQ(data->run_duration_max(), 0); 245 EXPECT_EQ(data->run_duration_max(), 0);
263 EXPECT_EQ(data->run_duration_sample(), 0); 246 EXPECT_EQ(data->run_duration_sample(), 0);
264 EXPECT_EQ(data->queue_duration_sum(), 0); 247 EXPECT_EQ(data->queue_duration_sum(), 0);
265 EXPECT_EQ(data->queue_duration_max(), 0); 248 EXPECT_EQ(data->queue_duration_max(), 0);
266 EXPECT_EQ(data->queue_duration_sample(), 0); 249 EXPECT_EQ(data->queue_duration_sample(), 0);
267 EXPECT_EQ(data->count(), 0); 250 EXPECT_EQ(data->count(), 0);
(...skipping 18 matching lines...) Expand all
286 EXPECT_EQ(data->run_duration_max(), run_ms); 269 EXPECT_EQ(data->run_duration_max(), run_ms);
287 EXPECT_EQ(data->run_duration_sample(), run_ms); 270 EXPECT_EQ(data->run_duration_sample(), run_ms);
288 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); 271 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms);
289 EXPECT_EQ(data->queue_duration_max(), queue_ms); 272 EXPECT_EQ(data->queue_duration_max(), queue_ms);
290 EXPECT_EQ(data->queue_duration_sample(), queue_ms); 273 EXPECT_EQ(data->queue_duration_sample(), queue_ms);
291 EXPECT_EQ(data->count(), 2); 274 EXPECT_EQ(data->count(), 2);
292 EXPECT_EQ(nullptr, data->last_phase_snapshot()); 275 EXPECT_EQ(nullptr, data->last_phase_snapshot());
293 } 276 }
294 277
295 TEST_F(TrackedObjectsTest, DeathDataTest2Phases) { 278 TEST_F(TrackedObjectsTest, DeathDataTest2Phases) {
296 if (!ThreadData::InitializeAndSetTrackingStatus( 279 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
297 ThreadData::PROFILING_ACTIVE)) {
298 // Don't run the test if task tracking is not compiled in.
299 return;
300 }
301 280
302 scoped_ptr<DeathData> data(new DeathData()); 281 scoped_ptr<DeathData> data(new DeathData());
303 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); 282 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL));
304 283
305 int32 run_ms = 42; 284 int32 run_ms = 42;
306 int32 queue_ms = 8; 285 int32 queue_ms = 8;
307 286
308 const int kUnrandomInt = 0; // Fake random int that ensure we sample data. 287 const int kUnrandomInt = 0; // Fake random int that ensure we sample data.
309 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); 288 data->RecordDeath(queue_ms, run_ms, kUnrandomInt);
310 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); 289 data->RecordDeath(queue_ms, run_ms, kUnrandomInt);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 EXPECT_EQ(2 * queue_ms, 334 EXPECT_EQ(2 * queue_ms,
356 data->last_phase_snapshot()->death_data.queue_duration_sum); 335 data->last_phase_snapshot()->death_data.queue_duration_sum);
357 EXPECT_EQ(queue_ms, 336 EXPECT_EQ(queue_ms,
358 data->last_phase_snapshot()->death_data.queue_duration_max); 337 data->last_phase_snapshot()->death_data.queue_duration_max);
359 EXPECT_EQ(queue_ms, 338 EXPECT_EQ(queue_ms,
360 data->last_phase_snapshot()->death_data.queue_duration_sample); 339 data->last_phase_snapshot()->death_data.queue_duration_sample);
361 EXPECT_EQ(nullptr, data->last_phase_snapshot()->prev); 340 EXPECT_EQ(nullptr, data->last_phase_snapshot()->prev);
362 } 341 }
363 342
364 TEST_F(TrackedObjectsTest, Delta) { 343 TEST_F(TrackedObjectsTest, Delta) {
365 if (!ThreadData::InitializeAndSetTrackingStatus( 344 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
366 ThreadData::PROFILING_ACTIVE)) {
367 // Don't run the test if task tracking is not compiled in.
368 return;
369 }
370 345
371 DeathDataSnapshot snapshot; 346 DeathDataSnapshot snapshot;
372 snapshot.count = 10; 347 snapshot.count = 10;
373 snapshot.run_duration_sum = 100; 348 snapshot.run_duration_sum = 100;
374 snapshot.run_duration_max = 50; 349 snapshot.run_duration_max = 50;
375 snapshot.run_duration_sample = 25; 350 snapshot.run_duration_sample = 25;
376 snapshot.queue_duration_sum = 200; 351 snapshot.queue_duration_sum = 200;
377 snapshot.queue_duration_max = 101; 352 snapshot.queue_duration_max = 101;
378 snapshot.queue_duration_sample = 26; 353 snapshot.queue_duration_sample = 26;
379 354
(...skipping 11 matching lines...) Expand all
391 EXPECT_EQ(5, delta.run_duration_sum); 366 EXPECT_EQ(5, delta.run_duration_sum);
392 EXPECT_EQ(50, delta.run_duration_max); 367 EXPECT_EQ(50, delta.run_duration_max);
393 EXPECT_EQ(25, delta.run_duration_sample); 368 EXPECT_EQ(25, delta.run_duration_sample);
394 EXPECT_EQ(10, delta.queue_duration_sum); 369 EXPECT_EQ(10, delta.queue_duration_sum);
395 EXPECT_EQ(101, delta.queue_duration_max); 370 EXPECT_EQ(101, delta.queue_duration_max);
396 EXPECT_EQ(26, delta.queue_duration_sample); 371 EXPECT_EQ(26, delta.queue_duration_sample);
397 } 372 }
398 373
399 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotWorkerThread) { 374 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotWorkerThread) {
400 // Start in the deactivated state. 375 // Start in the deactivated state.
401 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { 376 ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED);
402 // Don't run the test if task tracking is not compiled in.
403 return;
404 }
405 377
406 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread"; 378 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread";
407 Location location(kFunction, kFile, kLineNumber, NULL); 379 Location location(kFunction, kFile, kLineNumber, NULL);
408 TallyABirth(location, std::string()); 380 TallyABirth(location, std::string());
409 381
410 ProcessDataSnapshot process_data; 382 ProcessDataSnapshot process_data;
411 ThreadData::Snapshot(0, &process_data); 383 ThreadData::Snapshot(0, &process_data);
412 384
413 ASSERT_EQ(1u, process_data.phased_snapshots.size()); 385 ASSERT_EQ(1u, process_data.phased_snapshots.size());
414 386
415 auto it = process_data.phased_snapshots.find(0); 387 auto it = process_data.phased_snapshots.find(0);
416 ASSERT_TRUE(it != process_data.phased_snapshots.end()); 388 ASSERT_TRUE(it != process_data.phased_snapshots.end());
417 const ProcessDataPhaseSnapshot& process_data_phase = it->second; 389 const ProcessDataPhaseSnapshot& process_data_phase = it->second;
418 390
419 ASSERT_EQ(0u, process_data_phase.tasks.size()); 391 ASSERT_EQ(0u, process_data_phase.tasks.size());
420 392
421 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 393 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
422 } 394 }
423 395
424 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) { 396 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotMainThread) {
425 // Start in the deactivated state. 397 // Start in the deactivated state.
426 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { 398 ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED);
427 // Don't run the test if task tracking is not compiled in.
428 return;
429 }
430 399
431 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread"; 400 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotMainThread";
432 Location location(kFunction, kFile, kLineNumber, NULL); 401 Location location(kFunction, kFile, kLineNumber, NULL);
433 TallyABirth(location, kMainThreadName); 402 TallyABirth(location, kMainThreadName);
434 403
435 ProcessDataSnapshot process_data; 404 ProcessDataSnapshot process_data;
436 ThreadData::Snapshot(0, &process_data); 405 ThreadData::Snapshot(0, &process_data);
437 406
438 ASSERT_EQ(1u, process_data.phased_snapshots.size()); 407 ASSERT_EQ(1u, process_data.phased_snapshots.size());
439 408
440 auto it = process_data.phased_snapshots.find(0); 409 auto it = process_data.phased_snapshots.find(0);
441 ASSERT_TRUE(it != process_data.phased_snapshots.end()); 410 ASSERT_TRUE(it != process_data.phased_snapshots.end());
442 const ProcessDataPhaseSnapshot& process_data_phase = it->second; 411 const ProcessDataPhaseSnapshot& process_data_phase = it->second;
443 412
444 ASSERT_EQ(0u, process_data_phase.tasks.size()); 413 ASSERT_EQ(0u, process_data_phase.tasks.size());
445 414
446 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 415 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
447 } 416 }
448 417
449 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) { 418 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotWorkerThread) {
450 if (!ThreadData::InitializeAndSetTrackingStatus( 419 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
451 ThreadData::PROFILING_ACTIVE)) {
452 // Don't run the test if task tracking is not compiled in.
453 return;
454 }
455 420
456 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread"; 421 const char kFunction[] = "BirthOnlyToSnapshotWorkerThread";
457 Location location(kFunction, kFile, kLineNumber, NULL); 422 Location location(kFunction, kFile, kLineNumber, NULL);
458 TallyABirth(location, std::string()); 423 TallyABirth(location, std::string());
459 424
460 ProcessDataSnapshot process_data; 425 ProcessDataSnapshot process_data;
461 ThreadData::Snapshot(0, &process_data); 426 ThreadData::Snapshot(0, &process_data);
462 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName, 427 ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName,
463 kStillAlive, 1, 0, 0); 428 kStillAlive, 1, 0, 0);
464 } 429 }
465 430
466 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) { 431 TEST_F(TrackedObjectsTest, BirthOnlyToSnapshotMainThread) {
467 if (!ThreadData::InitializeAndSetTrackingStatus( 432 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
468 ThreadData::PROFILING_ACTIVE)) {
469 // Don't run the test if task tracking is not compiled in.
470 return;
471 }
472 433
473 const char kFunction[] = "BirthOnlyToSnapshotMainThread"; 434 const char kFunction[] = "BirthOnlyToSnapshotMainThread";
474 Location location(kFunction, kFile, kLineNumber, NULL); 435 Location location(kFunction, kFile, kLineNumber, NULL);
475 TallyABirth(location, kMainThreadName); 436 TallyABirth(location, kMainThreadName);
476 437
477 ProcessDataSnapshot process_data; 438 ProcessDataSnapshot process_data;
478 ThreadData::Snapshot(0, &process_data); 439 ThreadData::Snapshot(0, &process_data);
479 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive, 440 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive,
480 1, 0, 0); 441 1, 0, 0);
481 } 442 }
482 443
483 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) { 444 TEST_F(TrackedObjectsTest, LifeCycleToSnapshotMainThread) {
484 if (!ThreadData::InitializeAndSetTrackingStatus( 445 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
485 ThreadData::PROFILING_ACTIVE)) {
486 // Don't run the test if task tracking is not compiled in.
487 return;
488 }
489 446
490 const char kFunction[] = "LifeCycleToSnapshotMainThread"; 447 const char kFunction[] = "LifeCycleToSnapshotMainThread";
491 Location location(kFunction, kFile, kLineNumber, NULL); 448 Location location(kFunction, kFile, kLineNumber, NULL);
492 TallyABirth(location, kMainThreadName); 449 TallyABirth(location, kMainThreadName);
493 450
494 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 451 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
495 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 452 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
496 // TrackingInfo will call TallyABirth() during construction. 453 // TrackingInfo will call TallyABirth() during construction.
497 base::TrackingInfo pending_task(location, kDelayedStartTime); 454 base::TrackingInfo pending_task(location, kDelayedStartTime);
498 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 455 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
499 456
500 const unsigned int kStartOfRun = 5; 457 const unsigned int kStartOfRun = 5;
501 const unsigned int kEndOfRun = 7; 458 const unsigned int kEndOfRun = 7;
502 SetTestTime(kStartOfRun); 459 SetTestTime(kStartOfRun);
503 TaskStopwatch stopwatch; 460 TaskStopwatch stopwatch;
504 stopwatch.Start(); 461 stopwatch.Start();
505 SetTestTime(kEndOfRun); 462 SetTestTime(kEndOfRun);
506 stopwatch.Stop(); 463 stopwatch.Stop();
507 464
508 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 465 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
509 466
510 ProcessDataSnapshot process_data; 467 ProcessDataSnapshot process_data;
511 ThreadData::Snapshot(0, &process_data); 468 ThreadData::Snapshot(0, &process_data);
512 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 469 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
513 kMainThreadName, 1, 2, 4); 470 kMainThreadName, 1, 2, 4);
514 } 471 }
515 472
516 TEST_F(TrackedObjectsTest, TwoPhases) { 473 TEST_F(TrackedObjectsTest, TwoPhases) {
517 if (!ThreadData::InitializeAndSetTrackingStatus( 474 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
518 ThreadData::PROFILING_ACTIVE)) {
519 // Don't run the test if task tracking is not compiled in.
520 return;
521 }
522 475
523 const char kFunction[] = "TwoPhases"; 476 const char kFunction[] = "TwoPhases";
524 Location location(kFunction, kFile, kLineNumber, NULL); 477 Location location(kFunction, kFile, kLineNumber, NULL);
525 TallyABirth(location, kMainThreadName); 478 TallyABirth(location, kMainThreadName);
526 479
527 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 480 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
528 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 481 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
529 // TrackingInfo will call TallyABirth() during construction. 482 // TrackingInfo will call TallyABirth() during construction.
530 base::TrackingInfo pending_task(location, kDelayedStartTime); 483 base::TrackingInfo pending_task(location, kDelayedStartTime);
531 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 484 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sum); 563 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sum);
611 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_max); 564 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_max);
612 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sample); 565 EXPECT_EQ(2, process_data_phase1.tasks[0].death_data.queue_duration_sample);
613 566
614 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name); 567 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name);
615 568
616 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 569 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
617 } 570 }
618 571
619 TEST_F(TrackedObjectsTest, ThreePhases) { 572 TEST_F(TrackedObjectsTest, ThreePhases) {
620 if (!ThreadData::InitializeAndSetTrackingStatus( 573 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
621 ThreadData::PROFILING_ACTIVE)) {
622 // Don't run the test if task tracking is not compiled in.
623 return;
624 }
625 574
626 const char kFunction[] = "ThreePhases"; 575 const char kFunction[] = "ThreePhases";
627 Location location(kFunction, kFile, kLineNumber, NULL); 576 Location location(kFunction, kFile, kLineNumber, NULL);
628 577
629 // Phase 0 578 // Phase 0
630 { 579 {
631 TallyABirth(location, kMainThreadName); 580 TallyABirth(location, kMainThreadName);
632 581
633 // TrackingInfo will call TallyABirth() during construction. 582 // TrackingInfo will call TallyABirth() during construction.
634 SetTestTime(10); 583 SetTestTime(10);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_sum); 704 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_sum);
756 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_max); 705 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_max);
757 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_sample); 706 EXPECT_EQ(3, process_data_phase2.tasks[0].death_data.queue_duration_sample);
758 707
759 EXPECT_EQ(kMainThreadName, process_data_phase2.tasks[0].death_thread_name); 708 EXPECT_EQ(kMainThreadName, process_data_phase2.tasks[0].death_thread_name);
760 709
761 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 710 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
762 } 711 }
763 712
764 TEST_F(TrackedObjectsTest, TwoPhasesSecondEmpty) { 713 TEST_F(TrackedObjectsTest, TwoPhasesSecondEmpty) {
765 if (!ThreadData::InitializeAndSetTrackingStatus( 714 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
766 ThreadData::PROFILING_ACTIVE)) {
767 // Don't run the test if task tracking is not compiled in.
768 return;
769 }
770 715
771 const char kFunction[] = "TwoPhasesSecondEmpty"; 716 const char kFunction[] = "TwoPhasesSecondEmpty";
772 Location location(kFunction, kFile, kLineNumber, NULL); 717 Location location(kFunction, kFile, kLineNumber, NULL);
773 ThreadData::InitializeThreadContext(kMainThreadName); 718 ThreadData::InitializeThreadContext(kMainThreadName);
774 719
775 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 720 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
776 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 721 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
777 // TrackingInfo will call TallyABirth() during construction. 722 // TrackingInfo will call TallyABirth() during construction.
778 base::TrackingInfo pending_task(location, kDelayedStartTime); 723 base::TrackingInfo pending_task(location, kDelayedStartTime);
779 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 724 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 auto it1 = process_data.phased_snapshots.find(1); 767 auto it1 = process_data.phased_snapshots.find(1);
823 ASSERT_TRUE(it1 != process_data.phased_snapshots.end()); 768 ASSERT_TRUE(it1 != process_data.phased_snapshots.end());
824 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second; 769 const ProcessDataPhaseSnapshot& process_data_phase1 = it1->second;
825 770
826 ASSERT_EQ(0u, process_data_phase1.tasks.size()); 771 ASSERT_EQ(0u, process_data_phase1.tasks.size());
827 772
828 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 773 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
829 } 774 }
830 775
831 TEST_F(TrackedObjectsTest, TwoPhasesFirstEmpty) { 776 TEST_F(TrackedObjectsTest, TwoPhasesFirstEmpty) {
832 if (!ThreadData::InitializeAndSetTrackingStatus( 777 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
833 ThreadData::PROFILING_ACTIVE)) {
834 // Don't run the test if task tracking is not compiled in.
835 return;
836 }
837 778
838 ThreadData::OnProfilingPhaseCompleted(0); 779 ThreadData::OnProfilingPhaseCompleted(0);
839 780
840 const char kFunction[] = "TwoPhasesSecondEmpty"; 781 const char kFunction[] = "TwoPhasesSecondEmpty";
841 Location location(kFunction, kFile, kLineNumber, NULL); 782 Location location(kFunction, kFile, kLineNumber, NULL);
842 ThreadData::InitializeThreadContext(kMainThreadName); 783 ThreadData::InitializeThreadContext(kMainThreadName);
843 784
844 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 785 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
845 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 786 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
846 // TrackingInfo will call TallyABirth() during construction. 787 // TrackingInfo will call TallyABirth() during construction.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name); 828 EXPECT_EQ(kMainThreadName, process_data_phase1.tasks[0].death_thread_name);
888 829
889 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 830 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
890 } 831 }
891 832
892 // We will deactivate tracking after the birth, and before the death, and 833 // We will deactivate tracking after the birth, and before the death, and
893 // demonstrate that the lifecycle is completely tallied. This ensures that 834 // demonstrate that the lifecycle is completely tallied. This ensures that
894 // our tallied births are matched by tallied deaths (except for when the 835 // our tallied births are matched by tallied deaths (except for when the
895 // task is still running, or is queued). 836 // task is still running, or is queued).
896 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) { 837 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToSnapshotMainThread) {
897 if (!ThreadData::InitializeAndSetTrackingStatus( 838 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
898 ThreadData::PROFILING_ACTIVE)) {
899 // Don't run the test if task tracking is not compiled in.
900 return;
901 }
902 839
903 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread"; 840 const char kFunction[] = "LifeCycleMidDeactivatedToSnapshotMainThread";
904 Location location(kFunction, kFile, kLineNumber, NULL); 841 Location location(kFunction, kFile, kLineNumber, NULL);
905 TallyABirth(location, kMainThreadName); 842 TallyABirth(location, kMainThreadName);
906 843
907 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 844 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
908 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 845 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
909 // TrackingInfo will call TallyABirth() during construction. 846 // TrackingInfo will call TallyABirth() during construction.
910 base::TrackingInfo pending_task(location, kDelayedStartTime); 847 base::TrackingInfo pending_task(location, kDelayedStartTime);
911 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 848 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
912 849
913 // Turn off tracking now that we have births. 850 // Turn off tracking now that we have births.
914 EXPECT_TRUE( 851 ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED);
915 ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED));
916 852
917 const unsigned int kStartOfRun = 5; 853 const unsigned int kStartOfRun = 5;
918 const unsigned int kEndOfRun = 7; 854 const unsigned int kEndOfRun = 7;
919 SetTestTime(kStartOfRun); 855 SetTestTime(kStartOfRun);
920 TaskStopwatch stopwatch; 856 TaskStopwatch stopwatch;
921 stopwatch.Start(); 857 stopwatch.Start();
922 SetTestTime(kEndOfRun); 858 SetTestTime(kEndOfRun);
923 stopwatch.Stop(); 859 stopwatch.Stop();
924 860
925 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 861 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
926 862
927 ProcessDataSnapshot process_data; 863 ProcessDataSnapshot process_data;
928 ThreadData::Snapshot(0, &process_data); 864 ThreadData::Snapshot(0, &process_data);
929 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 865 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
930 kMainThreadName, 1, 2, 4); 866 kMainThreadName, 1, 2, 4);
931 } 867 }
932 868
933 // We will deactivate tracking before starting a life cycle, and neither 869 // We will deactivate tracking before starting a life cycle, and neither
934 // the birth nor the death will be recorded. 870 // the birth nor the death will be recorded.
935 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) { 871 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToSnapshotMainThread) {
936 // Start in the deactivated state. 872 // Start in the deactivated state.
937 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) { 873 ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED);
938 // Don't run the test if task tracking is not compiled in.
939 return;
940 }
941 874
942 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread"; 875 const char kFunction[] = "LifeCyclePreDeactivatedToSnapshotMainThread";
943 Location location(kFunction, kFile, kLineNumber, NULL); 876 Location location(kFunction, kFile, kLineNumber, NULL);
944 TallyABirth(location, kMainThreadName); 877 TallyABirth(location, kMainThreadName);
945 878
946 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 879 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
947 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 880 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
948 // TrackingInfo will call TallyABirth() during construction. 881 // TrackingInfo will call TallyABirth() during construction.
949 base::TrackingInfo pending_task(location, kDelayedStartTime); 882 base::TrackingInfo pending_task(location, kDelayedStartTime);
950 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 883 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
(...skipping 16 matching lines...) Expand all
967 auto it = process_data.phased_snapshots.find(0); 900 auto it = process_data.phased_snapshots.find(0);
968 ASSERT_TRUE(it != process_data.phased_snapshots.end()); 901 ASSERT_TRUE(it != process_data.phased_snapshots.end());
969 const ProcessDataPhaseSnapshot& process_data_phase = it->second; 902 const ProcessDataPhaseSnapshot& process_data_phase = it->second;
970 903
971 ASSERT_EQ(0u, process_data_phase.tasks.size()); 904 ASSERT_EQ(0u, process_data_phase.tasks.size());
972 905
973 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 906 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
974 } 907 }
975 908
976 TEST_F(TrackedObjectsTest, TwoLives) { 909 TEST_F(TrackedObjectsTest, TwoLives) {
977 if (!ThreadData::InitializeAndSetTrackingStatus( 910 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
978 ThreadData::PROFILING_ACTIVE)) {
979 // Don't run the test if task tracking is not compiled in.
980 return;
981 }
982 911
983 const char kFunction[] = "TwoLives"; 912 const char kFunction[] = "TwoLives";
984 Location location(kFunction, kFile, kLineNumber, NULL); 913 Location location(kFunction, kFile, kLineNumber, NULL);
985 TallyABirth(location, kMainThreadName); 914 TallyABirth(location, kMainThreadName);
986 915
987 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 916 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
988 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 917 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
989 // TrackingInfo will call TallyABirth() during construction. 918 // TrackingInfo will call TallyABirth() during construction.
990 base::TrackingInfo pending_task(location, kDelayedStartTime); 919 base::TrackingInfo pending_task(location, kDelayedStartTime);
991 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 920 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
(...skipping 19 matching lines...) Expand all
1011 940
1012 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2); 941 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2);
1013 942
1014 ProcessDataSnapshot process_data; 943 ProcessDataSnapshot process_data;
1015 ThreadData::Snapshot(0, &process_data); 944 ThreadData::Snapshot(0, &process_data);
1016 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 945 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
1017 kMainThreadName, 2, 2, 4); 946 kMainThreadName, 2, 2, 4);
1018 } 947 }
1019 948
1020 TEST_F(TrackedObjectsTest, DifferentLives) { 949 TEST_F(TrackedObjectsTest, DifferentLives) {
1021 if (!ThreadData::InitializeAndSetTrackingStatus( 950 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
1022 ThreadData::PROFILING_ACTIVE)) {
1023 // Don't run the test if task tracking is not compiled in.
1024 return;
1025 }
1026 951
1027 // Use a well named thread. 952 // Use a well named thread.
1028 ThreadData::InitializeThreadContext(kMainThreadName); 953 ThreadData::InitializeThreadContext(kMainThreadName);
1029 const char kFunction[] = "DifferentLives"; 954 const char kFunction[] = "DifferentLives";
1030 Location location(kFunction, kFile, kLineNumber, NULL); 955 Location location(kFunction, kFile, kLineNumber, NULL);
1031 956
1032 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 957 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
1033 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 958 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
1034 // TrackingInfo will call TallyABirth() during construction. 959 // TrackingInfo will call TallyABirth() during construction.
1035 base::TrackingInfo pending_task(location, kDelayedStartTime); 960 base::TrackingInfo pending_task(location, kDelayedStartTime);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.run_duration_max); 1012 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.run_duration_max);
1088 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.run_duration_sample); 1013 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.run_duration_sample);
1089 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_sum); 1014 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_sum);
1090 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_max); 1015 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_max);
1091 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_sample); 1016 EXPECT_EQ(0, process_data_phase.tasks[1].death_data.queue_duration_sample);
1092 EXPECT_EQ(kStillAlive, process_data_phase.tasks[1].death_thread_name); 1017 EXPECT_EQ(kStillAlive, process_data_phase.tasks[1].death_thread_name);
1093 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 1018 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
1094 } 1019 }
1095 1020
1096 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) { 1021 TEST_F(TrackedObjectsTest, TaskWithNestedExclusion) {
1097 if (!ThreadData::InitializeAndSetTrackingStatus( 1022 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
1098 ThreadData::PROFILING_ACTIVE)) {
1099 // Don't run the test if task tracking is not compiled in.
1100 return;
1101 }
1102 1023
1103 const char kFunction[] = "TaskWithNestedExclusion"; 1024 const char kFunction[] = "TaskWithNestedExclusion";
1104 Location location(kFunction, kFile, kLineNumber, NULL); 1025 Location location(kFunction, kFile, kLineNumber, NULL);
1105 TallyABirth(location, kMainThreadName); 1026 TallyABirth(location, kMainThreadName);
1106 1027
1107 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 1028 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
1108 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 1029 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
1109 // TrackingInfo will call TallyABirth() during construction. 1030 // TrackingInfo will call TallyABirth() during construction.
1110 base::TrackingInfo pending_task(location, kDelayedStartTime); 1031 base::TrackingInfo pending_task(location, kDelayedStartTime);
1111 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 1032 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
(...skipping 13 matching lines...) Expand all
1125 1046
1126 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); 1047 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
1127 1048
1128 ProcessDataSnapshot process_data; 1049 ProcessDataSnapshot process_data;
1129 ThreadData::Snapshot(0, &process_data); 1050 ThreadData::Snapshot(0, &process_data);
1130 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 1051 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
1131 kMainThreadName, 1, 6, 4); 1052 kMainThreadName, 1, 6, 4);
1132 } 1053 }
1133 1054
1134 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) { 1055 TEST_F(TrackedObjectsTest, TaskWith2NestedExclusions) {
1135 if (!ThreadData::InitializeAndSetTrackingStatus( 1056 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
1136 ThreadData::PROFILING_ACTIVE)) {
1137 // Don't run the test if task tracking is not compiled in.
1138 return;
1139 }
1140 1057
1141 const char kFunction[] = "TaskWith2NestedExclusions"; 1058 const char kFunction[] = "TaskWith2NestedExclusions";
1142 Location location(kFunction, kFile, kLineNumber, NULL); 1059 Location location(kFunction, kFile, kLineNumber, NULL);
1143 TallyABirth(location, kMainThreadName); 1060 TallyABirth(location, kMainThreadName);
1144 1061
1145 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 1062 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
1146 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 1063 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
1147 // TrackingInfo will call TallyABirth() during construction. 1064 // TrackingInfo will call TallyABirth() during construction.
1148 base::TrackingInfo pending_task(location, kDelayedStartTime); 1065 base::TrackingInfo pending_task(location, kDelayedStartTime);
1149 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 1066 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
(...skipping 19 matching lines...) Expand all
1169 1086
1170 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch); 1087 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
1171 1088
1172 ProcessDataSnapshot process_data; 1089 ProcessDataSnapshot process_data;
1173 ThreadData::Snapshot(0, &process_data); 1090 ThreadData::Snapshot(0, &process_data);
1174 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, 1091 ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
1175 kMainThreadName, 1, 13, 4); 1092 kMainThreadName, 1, 13, 4);
1176 } 1093 }
1177 1094
1178 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) { 1095 TEST_F(TrackedObjectsTest, TaskWithNestedExclusionWithNestedTask) {
1179 if (!ThreadData::InitializeAndSetTrackingStatus( 1096 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
1180 ThreadData::PROFILING_ACTIVE)) {
1181 // Don't run the test if task tracking is not compiled in.
1182 return;
1183 }
1184 1097
1185 const char kFunction[] = "TaskWithNestedExclusionWithNestedTask"; 1098 const char kFunction[] = "TaskWithNestedExclusionWithNestedTask";
1186 Location location(kFunction, kFile, kLineNumber, NULL); 1099 Location location(kFunction, kFile, kLineNumber, NULL);
1187 1100
1188 const int kSecondFakeLineNumber = 999; 1101 const int kSecondFakeLineNumber = 999;
1189 1102
1190 TallyABirth(location, kMainThreadName); 1103 TallyABirth(location, kMainThreadName);
1191 1104
1192 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1); 1105 const TrackedTime kTimePosted = TrackedTime::FromMilliseconds(1);
1193 const base::TimeTicks kDelayedStartTime = base::TimeTicks(); 1106 const base::TimeTicks kDelayedStartTime = base::TimeTicks();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_max); 1177 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_max);
1265 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample); 1178 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample);
1266 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum); 1179 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum);
1267 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max); 1180 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max);
1268 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample); 1181 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample);
1269 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name); 1182 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name);
1270 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 1183 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
1271 } 1184 }
1272 1185
1273 } // namespace tracked_objects 1186 } // namespace tracked_objects
OLDNEW
« base/tracked_objects.cc ('K') | « base/tracked_objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698