| 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 #include "base/tracked_objects.h" | 5 #include "base/tracked_objects.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 using base::TimeDelta; | 22 using base::TimeDelta; |
| 23 | 23 |
| 24 namespace base { | 24 namespace base { |
| 25 class TimeDelta; | 25 class TimeDelta; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace tracked_objects { | 28 namespace tracked_objects { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 // Flag to compile out almost all of the task tracking code. | |
| 32 const bool kTrackAllTaskObjects = true; | |
| 33 | |
| 34 // TODO(jar): Evaluate the perf impact of enabling this. If the perf impact is | 31 // TODO(jar): Evaluate the perf impact of enabling this. If the perf impact is |
| 35 // negligible, enable by default. | 32 // negligible, enable by default. |
| 36 // Flag to compile out parent-child link recording. | 33 // Flag to compile out parent-child link recording. |
| 37 const bool kTrackParentChildLinks = false; | 34 const bool kTrackParentChildLinks = false; |
| 38 | 35 |
| 39 // When ThreadData is first initialized, should we start in an ACTIVE state to | 36 // When ThreadData is first initialized, should we start in an ACTIVE state to |
| 40 // record all of the startup-time tasks, or should we start up DEACTIVATED, so | 37 // record all of the startup-time tasks, or should we start up DEACTIVATED, so |
| 41 // that we only record after parsing the command line flag --enable-tracking. | 38 // that we only record after parsing the command line flag --enable-tracking. |
| 42 // Note that the flag may force either state, so this really controls only the | 39 // Note that the flag may force either state, so this really controls only the |
| 43 // period of time up until that flag is parsed. If there is no flag seen, then | 40 // period of time up until that flag is parsed. If there is no flag seen, then |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 356 |
| 360 tls_index_.Set(worker_thread_data); | 357 tls_index_.Set(worker_thread_data); |
| 361 return worker_thread_data; | 358 return worker_thread_data; |
| 362 } | 359 } |
| 363 | 360 |
| 364 // static | 361 // static |
| 365 void ThreadData::OnThreadTermination(void* thread_data) { | 362 void ThreadData::OnThreadTermination(void* thread_data) { |
| 366 DCHECK(thread_data); // TLS should *never* call us with a NULL. | 363 DCHECK(thread_data); // TLS should *never* call us with a NULL. |
| 367 // We must NOT do any allocations during this callback. There is a chance | 364 // We must NOT do any allocations during this callback. There is a chance |
| 368 // that the allocator is no longer active on this thread. | 365 // that the allocator is no longer active on this thread. |
| 369 if (!kTrackAllTaskObjects) | |
| 370 return; // Not compiled in. | |
| 371 reinterpret_cast<ThreadData*>(thread_data)->OnThreadTerminationCleanup(); | 366 reinterpret_cast<ThreadData*>(thread_data)->OnThreadTerminationCleanup(); |
| 372 } | 367 } |
| 373 | 368 |
| 374 void ThreadData::OnThreadTerminationCleanup() { | 369 void ThreadData::OnThreadTerminationCleanup() { |
| 375 // The list_lock_ was created when we registered the callback, so it won't be | 370 // The list_lock_ was created when we registered the callback, so it won't be |
| 376 // allocated here despite the lazy reference. | 371 // allocated here despite the lazy reference. |
| 377 base::AutoLock lock(*list_lock_.Pointer()); | 372 base::AutoLock lock(*list_lock_.Pointer()); |
| 378 if (incarnation_counter_ != incarnation_count_for_pool_) | 373 if (incarnation_counter_ != incarnation_count_for_pool_) |
| 379 return; // ThreadData was constructed in an earlier unit test. | 374 return; // ThreadData was constructed in an earlier unit test. |
| 380 ++cleanup_count_; | 375 ++cleanup_count_; |
| 381 // Only worker threads need to be retired and reused. | 376 // Only worker threads need to be retired and reused. |
| 382 if (!worker_thread_number_) { | 377 if (!worker_thread_number_) { |
| 383 return; | 378 return; |
| 384 } | 379 } |
| 385 // We must NOT do any allocations during this callback. | 380 // We must NOT do any allocations during this callback. |
| 386 // Using the simple linked lists avoids all allocations. | 381 // Using the simple linked lists avoids all allocations. |
| 387 DCHECK_EQ(this->next_retired_worker_, reinterpret_cast<ThreadData*>(NULL)); | 382 DCHECK_EQ(this->next_retired_worker_, reinterpret_cast<ThreadData*>(NULL)); |
| 388 this->next_retired_worker_ = first_retired_worker_; | 383 this->next_retired_worker_ = first_retired_worker_; |
| 389 first_retired_worker_ = this; | 384 first_retired_worker_ = this; |
| 390 } | 385 } |
| 391 | 386 |
| 392 // static | 387 // static |
| 393 void ThreadData::Snapshot(ProcessDataSnapshot* process_data) { | 388 void ThreadData::Snapshot(ProcessDataSnapshot* process_data_snapshot) { |
| 394 // Add births that have run to completion to |collected_data|. | 389 ThreadData::SnapshotCurrentPhase( |
| 395 // |birth_counts| tracks the total number of births recorded at each location | 390 &process_data_snapshot->phased_process_data_snapshots[0]); |
| 396 // for which we have not seen a death count. | |
| 397 BirthCountMap birth_counts; | |
| 398 ThreadData::SnapshotAllExecutedTasks(process_data, &birth_counts); | |
| 399 | |
| 400 // Add births that are still active -- i.e. objects that have tallied a birth, | |
| 401 // but have not yet tallied a matching death, and hence must be either | |
| 402 // running, queued up, or being held in limbo for future posting. | |
| 403 for (BirthCountMap::const_iterator it = birth_counts.begin(); | |
| 404 it != birth_counts.end(); ++it) { | |
| 405 if (it->second > 0) { | |
| 406 process_data->tasks.push_back( | |
| 407 TaskSnapshot(*it->first, DeathData(it->second), "Still_Alive")); | |
| 408 } | |
| 409 } | |
| 410 } | 391 } |
| 411 | 392 |
| 412 Births* ThreadData::TallyABirth(const Location& location) { | 393 Births* ThreadData::TallyABirth(const Location& location) { |
| 413 BirthMap::iterator it = birth_map_.find(location); | 394 BirthMap::iterator it = birth_map_.find(location); |
| 414 Births* child; | 395 Births* child; |
| 415 if (it != birth_map_.end()) { | 396 if (it != birth_map_.end()) { |
| 416 child = it->second; | 397 child = it->second; |
| 417 child->RecordBirth(); | 398 child->RecordBirth(); |
| 418 } else { | 399 } else { |
| 419 child = new Births(location, *this); // Leak this. | 400 child = new Births(location, *this); // Leak this. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 if (!kTrackParentChildLinks) | 453 if (!kTrackParentChildLinks) |
| 473 return; | 454 return; |
| 474 if (!parent_stack_.empty()) { // We might get turned off. | 455 if (!parent_stack_.empty()) { // We might get turned off. |
| 475 DCHECK_EQ(parent_stack_.top(), &birth); | 456 DCHECK_EQ(parent_stack_.top(), &birth); |
| 476 parent_stack_.pop(); | 457 parent_stack_.pop(); |
| 477 } | 458 } |
| 478 } | 459 } |
| 479 | 460 |
| 480 // static | 461 // static |
| 481 Births* ThreadData::TallyABirthIfActive(const Location& location) { | 462 Births* ThreadData::TallyABirthIfActive(const Location& location) { |
| 482 if (!kTrackAllTaskObjects) | |
| 483 return NULL; // Not compiled in. | |
| 484 | |
| 485 if (!TrackingStatus()) | 463 if (!TrackingStatus()) |
| 486 return NULL; | 464 return NULL; |
| 487 ThreadData* current_thread_data = Get(); | 465 ThreadData* current_thread_data = Get(); |
| 488 if (!current_thread_data) | 466 if (!current_thread_data) |
| 489 return NULL; | 467 return NULL; |
| 490 return current_thread_data->TallyABirth(location); | 468 return current_thread_data->TallyABirth(location); |
| 491 } | 469 } |
| 492 | 470 |
| 493 // static | 471 // static |
| 494 void ThreadData::TallyRunOnNamedThreadIfTracking( | 472 void ThreadData::TallyRunOnNamedThreadIfTracking( |
| 495 const base::TrackingInfo& completed_task, | 473 const base::TrackingInfo& completed_task, |
| 496 const TaskStopwatch& stopwatch) { | 474 const TaskStopwatch& stopwatch) { |
| 497 if (!kTrackAllTaskObjects) | |
| 498 return; // Not compiled in. | |
| 499 | |
| 500 // Even if we have been DEACTIVATED, we will process any pending births so | 475 // Even if we have been DEACTIVATED, we will process any pending births so |
| 501 // that our data structures (which counted the outstanding births) remain | 476 // that our data structures (which counted the outstanding births) remain |
| 502 // consistent. | 477 // consistent. |
| 503 const Births* birth = completed_task.birth_tally; | 478 const Births* birth = completed_task.birth_tally; |
| 504 if (!birth) | 479 if (!birth) |
| 505 return; | 480 return; |
| 506 ThreadData* current_thread_data = stopwatch.GetThreadData(); | 481 ThreadData* current_thread_data = stopwatch.GetThreadData(); |
| 507 if (!current_thread_data) | 482 if (!current_thread_data) |
| 508 return; | 483 return; |
| 509 | 484 |
| 510 // Watch out for a race where status_ is changing, and hence one or both | 485 // Watch out for a race where status_ is changing, and hence one or both |
| 511 // of start_of_run or end_of_run is zero. In that case, we didn't bother to | 486 // of start_of_run or end_of_run is zero. In that case, we didn't bother to |
| 512 // get a time value since we "weren't tracking" and we were trying to be | 487 // get a time value since we "weren't tracking" and we were trying to be |
| 513 // efficient by not calling for a genuine time value. For simplicity, we'll | 488 // efficient by not calling for a genuine time value. For simplicity, we'll |
| 514 // use a default zero duration when we can't calculate a true value. | 489 // use a default zero duration when we can't calculate a true value. |
| 515 TrackedTime start_of_run = stopwatch.StartTime(); | 490 TrackedTime start_of_run = stopwatch.StartTime(); |
| 516 int32 queue_duration = 0; | 491 int32 queue_duration = 0; |
| 517 if (!start_of_run.is_null()) { | 492 if (!start_of_run.is_null()) { |
| 518 queue_duration = (start_of_run - completed_task.EffectiveTimePosted()) | 493 queue_duration = (start_of_run - completed_task.EffectiveTimePosted()) |
| 519 .InMilliseconds(); | 494 .InMilliseconds(); |
| 520 } | 495 } |
| 521 current_thread_data->TallyADeath(*birth, queue_duration, stopwatch); | 496 current_thread_data->TallyADeath(*birth, queue_duration, stopwatch); |
| 522 } | 497 } |
| 523 | 498 |
| 524 // static | 499 // static |
| 525 void ThreadData::TallyRunOnWorkerThreadIfTracking( | 500 void ThreadData::TallyRunOnWorkerThreadIfTracking( |
| 526 const Births* birth, | 501 const Births* birth, |
| 527 const TrackedTime& time_posted, | 502 const TrackedTime& time_posted, |
| 528 const TaskStopwatch& stopwatch) { | 503 const TaskStopwatch& stopwatch) { |
| 529 if (!kTrackAllTaskObjects) | |
| 530 return; // Not compiled in. | |
| 531 | |
| 532 // Even if we have been DEACTIVATED, we will process any pending births so | 504 // Even if we have been DEACTIVATED, we will process any pending births so |
| 533 // that our data structures (which counted the outstanding births) remain | 505 // that our data structures (which counted the outstanding births) remain |
| 534 // consistent. | 506 // consistent. |
| 535 if (!birth) | 507 if (!birth) |
| 536 return; | 508 return; |
| 537 | 509 |
| 538 // TODO(jar): Support the option to coalesce all worker-thread activity under | 510 // TODO(jar): Support the option to coalesce all worker-thread activity under |
| 539 // one ThreadData instance that uses locks to protect *all* access. This will | 511 // one ThreadData instance that uses locks to protect *all* access. This will |
| 540 // reduce memory (making it provably bounded), but run incrementally slower | 512 // reduce memory (making it provably bounded), but run incrementally slower |
| 541 // (since we'll use locks on TallyABirth and TallyADeath). The good news is | 513 // (since we'll use locks on TallyABirth and TallyADeath). The good news is |
| (...skipping 11 matching lines...) Expand all Loading... |
| 553 if (!start_of_run.is_null()) { | 525 if (!start_of_run.is_null()) { |
| 554 queue_duration = (start_of_run - time_posted).InMilliseconds(); | 526 queue_duration = (start_of_run - time_posted).InMilliseconds(); |
| 555 } | 527 } |
| 556 current_thread_data->TallyADeath(*birth, queue_duration, stopwatch); | 528 current_thread_data->TallyADeath(*birth, queue_duration, stopwatch); |
| 557 } | 529 } |
| 558 | 530 |
| 559 // static | 531 // static |
| 560 void ThreadData::TallyRunInAScopedRegionIfTracking( | 532 void ThreadData::TallyRunInAScopedRegionIfTracking( |
| 561 const Births* birth, | 533 const Births* birth, |
| 562 const TaskStopwatch& stopwatch) { | 534 const TaskStopwatch& stopwatch) { |
| 563 if (!kTrackAllTaskObjects) | |
| 564 return; // Not compiled in. | |
| 565 | |
| 566 // Even if we have been DEACTIVATED, we will process any pending births so | 535 // Even if we have been DEACTIVATED, we will process any pending births so |
| 567 // that our data structures (which counted the outstanding births) remain | 536 // that our data structures (which counted the outstanding births) remain |
| 568 // consistent. | 537 // consistent. |
| 569 if (!birth) | 538 if (!birth) |
| 570 return; | 539 return; |
| 571 | 540 |
| 572 ThreadData* current_thread_data = stopwatch.GetThreadData(); | 541 ThreadData* current_thread_data = stopwatch.GetThreadData(); |
| 573 if (!current_thread_data) | 542 if (!current_thread_data) |
| 574 return; | 543 return; |
| 575 | 544 |
| 576 int32 queue_duration = 0; | 545 int32 queue_duration = 0; |
| 577 current_thread_data->TallyADeath(*birth, queue_duration, stopwatch); | 546 current_thread_data->TallyADeath(*birth, queue_duration, stopwatch); |
| 578 } | 547 } |
| 579 | 548 |
| 580 // static | 549 // static |
| 581 void ThreadData::SnapshotAllExecutedTasks(ProcessDataSnapshot* process_data, | 550 void ThreadData::SnapshotAllExecutedTasks( |
| 582 BirthCountMap* birth_counts) { | 551 ProcessDataPhaseSnapshot* process_data_phase, |
| 583 if (!kTrackAllTaskObjects) | 552 BirthCountMap* birth_counts) { |
| 584 return; // Not compiled in. | |
| 585 | |
| 586 // Get an unchanging copy of a ThreadData list. | 553 // Get an unchanging copy of a ThreadData list. |
| 587 ThreadData* my_list = ThreadData::first(); | 554 ThreadData* my_list = ThreadData::first(); |
| 588 | 555 |
| 589 // Gather data serially. | 556 // Gather data serially. |
| 590 // This hackish approach *can* get some slighly corrupt tallies, as we are | 557 // This hackish approach *can* get some slighly corrupt tallies, as we are |
| 591 // grabbing values without the protection of a lock, but it has the advantage | 558 // grabbing values without the protection of a lock, but it has the advantage |
| 592 // of working even with threads that don't have message loops. If a user | 559 // of working even with threads that don't have message loops. If a user |
| 593 // sees any strangeness, they can always just run their stats gathering a | 560 // sees any strangeness, they can always just run their stats gathering a |
| 594 // second time. | 561 // second time. |
| 595 for (ThreadData* thread_data = my_list; | 562 for (ThreadData* thread_data = my_list; |
| 596 thread_data; | 563 thread_data; |
| 597 thread_data = thread_data->next()) { | 564 thread_data = thread_data->next()) { |
| 598 thread_data->SnapshotExecutedTasks(process_data, birth_counts); | 565 thread_data->SnapshotExecutedTasks(process_data_phase, birth_counts); |
| 599 } | 566 } |
| 600 } | 567 } |
| 601 | 568 |
| 602 void ThreadData::SnapshotExecutedTasks(ProcessDataSnapshot* process_data, | 569 // static |
| 603 BirthCountMap* birth_counts) { | 570 void ThreadData::SnapshotCurrentPhase( |
| 571 ProcessDataPhaseSnapshot* process_data_phase) { |
| 572 // Add births that have run to completion to |collected_data|. |
| 573 // |birth_counts| tracks the total number of births recorded at each location |
| 574 // for which we have not seen a death count. |
| 575 BirthCountMap birth_counts; |
| 576 ThreadData::SnapshotAllExecutedTasks(process_data_phase, &birth_counts); |
| 577 |
| 578 // Add births that are still active -- i.e. objects that have tallied a birth, |
| 579 // but have not yet tallied a matching death, and hence must be either |
| 580 // running, queued up, or being held in limbo for future posting. |
| 581 for (const auto& birth_count : birth_counts) { |
| 582 if (birth_count.second > 0) { |
| 583 process_data_phase->tasks.push_back(TaskSnapshot( |
| 584 *birth_count.first, DeathData(birth_count.second), "Still_Alive")); |
| 585 } |
| 586 } |
| 587 } |
| 588 |
| 589 void ThreadData::SnapshotExecutedTasks( |
| 590 ProcessDataPhaseSnapshot* process_data_phase, |
| 591 BirthCountMap* birth_counts) { |
| 604 // Get copy of data, so that the data will not change during the iterations | 592 // Get copy of data, so that the data will not change during the iterations |
| 605 // and processing. | 593 // and processing. |
| 606 ThreadData::BirthMap birth_map; | 594 ThreadData::BirthMap birth_map; |
| 607 ThreadData::DeathMap death_map; | 595 ThreadData::DeathMap death_map; |
| 608 ThreadData::ParentChildSet parent_child_set; | 596 ThreadData::ParentChildSet parent_child_set; |
| 609 SnapshotMaps(&birth_map, &death_map, &parent_child_set); | 597 SnapshotMaps(&birth_map, &death_map, &parent_child_set); |
| 610 | 598 |
| 611 for (ThreadData::DeathMap::const_iterator it = death_map.begin(); | 599 for (const auto& death : death_map) { |
| 612 it != death_map.end(); ++it) { | 600 process_data_phase->tasks.push_back( |
| 613 process_data->tasks.push_back( | 601 TaskSnapshot(*death.first, death.second, thread_name())); |
| 614 TaskSnapshot(*it->first, it->second, thread_name())); | 602 (*birth_counts)[death.first] -= death.first->birth_count(); |
| 615 (*birth_counts)[it->first] -= it->first->birth_count(); | |
| 616 } | 603 } |
| 617 | 604 |
| 618 for (ThreadData::BirthMap::const_iterator it = birth_map.begin(); | 605 for (const auto& birth : birth_map) { |
| 619 it != birth_map.end(); ++it) { | 606 (*birth_counts)[birth.second] += birth.second->birth_count(); |
| 620 (*birth_counts)[it->second] += it->second->birth_count(); | |
| 621 } | 607 } |
| 622 | 608 |
| 623 if (!kTrackParentChildLinks) | 609 if (!kTrackParentChildLinks) |
| 624 return; | 610 return; |
| 625 | 611 |
| 626 for (ThreadData::ParentChildSet::const_iterator it = parent_child_set.begin(); | 612 for (const auto& parent_child : parent_child_set) { |
| 627 it != parent_child_set.end(); ++it) { | 613 process_data_phase->descendants.push_back( |
| 628 process_data->descendants.push_back(ParentChildPairSnapshot(*it)); | 614 ParentChildPairSnapshot(parent_child)); |
| 629 } | 615 } |
| 630 } | 616 } |
| 631 | 617 |
| 632 // This may be called from another thread. | 618 // This may be called from another thread. |
| 633 void ThreadData::SnapshotMaps(BirthMap* birth_map, | 619 void ThreadData::SnapshotMaps(BirthMap* birth_map, |
| 634 DeathMap* death_map, | 620 DeathMap* death_map, |
| 635 ParentChildSet* parent_child_set) { | 621 ParentChildSet* parent_child_set) { |
| 636 base::AutoLock lock(map_lock_); | 622 base::AutoLock lock(map_lock_); |
| 637 for (BirthMap::const_iterator it = birth_map_.begin(); | 623 for (const auto& birth : birth_map_) |
| 638 it != birth_map_.end(); ++it) | 624 (*birth_map)[birth.first] = birth.second; |
| 639 (*birth_map)[it->first] = it->second; | 625 for (const auto& death : death_map_) |
| 640 for (DeathMap::iterator it = death_map_.begin(); | 626 (*death_map)[death.first] = death.second; |
| 641 it != death_map_.end(); ++it) { | |
| 642 (*death_map)[it->first] = it->second; | |
| 643 } | |
| 644 | 627 |
| 645 if (!kTrackParentChildLinks) | 628 if (!kTrackParentChildLinks) |
| 646 return; | 629 return; |
| 647 | 630 |
| 648 for (ParentChildSet::iterator it = parent_child_set_.begin(); | 631 for (const auto& parent_child : parent_child_set_) |
| 649 it != parent_child_set_.end(); ++it) | 632 parent_child_set->insert(parent_child); |
| 650 parent_child_set->insert(*it); | |
| 651 } | 633 } |
| 652 | 634 |
| 653 static void OptionallyInitializeAlternateTimer() { | 635 static void OptionallyInitializeAlternateTimer() { |
| 654 NowFunction* alternate_time_source = GetAlternateTimeSource(); | 636 NowFunction* alternate_time_source = GetAlternateTimeSource(); |
| 655 if (alternate_time_source) | 637 if (alternate_time_source) |
| 656 ThreadData::SetAlternateTimeSource(alternate_time_source); | 638 ThreadData::SetAlternateTimeSource(alternate_time_source); |
| 657 } | 639 } |
| 658 | 640 |
| 659 bool ThreadData::Initialize() { | 641 bool ThreadData::Initialize() { |
| 660 if (!kTrackAllTaskObjects) | |
| 661 return false; // Not compiled in. | |
| 662 if (status_ >= DEACTIVATED) | 642 if (status_ >= DEACTIVATED) |
| 663 return true; // Someone else did the initialization. | 643 return true; // Someone else did the initialization. |
| 664 // Due to racy lazy initialization in tests, we'll need to recheck status_ | 644 // Due to racy lazy initialization in tests, we'll need to recheck status_ |
| 665 // after we acquire the lock. | 645 // after we acquire the lock. |
| 666 | 646 |
| 667 // Ensure that we don't double initialize tls. We are called when single | 647 // Ensure that we don't double initialize tls. We are called when single |
| 668 // threaded in the product, but some tests may be racy and lazy about our | 648 // threaded in the product, but some tests may be racy and lazy about our |
| 669 // initialization. | 649 // initialization. |
| 670 base::AutoLock lock(*list_lock_.Pointer()); | 650 base::AutoLock lock(*list_lock_.Pointer()); |
| 671 if (status_ >= DEACTIVATED) | 651 if (status_ >= DEACTIVATED) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 | 732 |
| 753 // static | 733 // static |
| 754 void ThreadData::EnableProfilerTiming() { | 734 void ThreadData::EnableProfilerTiming() { |
| 755 base::subtle::NoBarrier_Store(&g_profiler_timing_enabled, ENABLED_TIMING); | 735 base::subtle::NoBarrier_Store(&g_profiler_timing_enabled, ENABLED_TIMING); |
| 756 } | 736 } |
| 757 | 737 |
| 758 // static | 738 // static |
| 759 TrackedTime ThreadData::Now() { | 739 TrackedTime ThreadData::Now() { |
| 760 if (kAllowAlternateTimeSourceHandling && now_function_) | 740 if (kAllowAlternateTimeSourceHandling && now_function_) |
| 761 return TrackedTime::FromMilliseconds((*now_function_)()); | 741 return TrackedTime::FromMilliseconds((*now_function_)()); |
| 762 if (kTrackAllTaskObjects && IsProfilerTimingEnabled() && TrackingStatus()) | 742 if (IsProfilerTimingEnabled() && TrackingStatus()) |
| 763 return TrackedTime::Now(); | 743 return TrackedTime::Now(); |
| 764 return TrackedTime(); // Super fast when disabled, or not compiled. | 744 return TrackedTime(); // Super fast when disabled, or not compiled. |
| 765 } | 745 } |
| 766 | 746 |
| 767 // static | 747 // static |
| 768 void ThreadData::EnsureCleanupWasCalled(int major_threads_shutdown_count) { | 748 void ThreadData::EnsureCleanupWasCalled(int major_threads_shutdown_count) { |
| 769 base::AutoLock lock(*list_lock_.Pointer()); | 749 base::AutoLock lock(*list_lock_.Pointer()); |
| 770 if (worker_thread_data_creation_count_ == 0) | 750 if (worker_thread_data_creation_count_ == 0) |
| 771 return; // We haven't really run much, and couldn't have leaked. | 751 return; // We haven't really run much, and couldn't have leaked. |
| 772 | 752 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 ParentChildPairSnapshot::ParentChildPairSnapshot( | 932 ParentChildPairSnapshot::ParentChildPairSnapshot( |
| 953 const ThreadData::ParentChildPair& parent_child) | 933 const ThreadData::ParentChildPair& parent_child) |
| 954 : parent(*parent_child.first), | 934 : parent(*parent_child.first), |
| 955 child(*parent_child.second) { | 935 child(*parent_child.second) { |
| 956 } | 936 } |
| 957 | 937 |
| 958 ParentChildPairSnapshot::~ParentChildPairSnapshot() { | 938 ParentChildPairSnapshot::~ParentChildPairSnapshot() { |
| 959 } | 939 } |
| 960 | 940 |
| 961 //------------------------------------------------------------------------------ | 941 //------------------------------------------------------------------------------ |
| 962 // ProcessDataSnapshot | 942 // ProcessDataPhaseSnapshot |
| 943 |
| 944 ProcessDataPhaseSnapshot::ProcessDataPhaseSnapshot() { |
| 945 } |
| 946 |
| 947 ProcessDataPhaseSnapshot::~ProcessDataPhaseSnapshot() { |
| 948 } |
| 949 |
| 950 //------------------------------------------------------------------------------ |
| 951 // ProcessDataPhaseSnapshot |
| 963 | 952 |
| 964 ProcessDataSnapshot::ProcessDataSnapshot() | 953 ProcessDataSnapshot::ProcessDataSnapshot() |
| 965 #if !defined(OS_NACL) | 954 #if !defined(OS_NACL) |
| 966 : process_id(base::GetCurrentProcId()) { | 955 : process_id(base::GetCurrentProcId()) { |
| 967 #else | 956 #else |
| 968 : process_id(0) { | 957 : process_id(base::kNullProcessId) { |
| 969 #endif | 958 #endif |
| 970 } | 959 } |
| 971 | 960 |
| 972 ProcessDataSnapshot::~ProcessDataSnapshot() { | 961 ProcessDataSnapshot::~ProcessDataSnapshot() { |
| 973 } | 962 } |
| 974 | 963 |
| 975 } // namespace tracked_objects | 964 } // namespace tracked_objects |
| OLD | NEW |