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

Side by Side Diff: base/tracked_objects.cc

Issue 9181002: Track parent-child relations during profiling (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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 | Annotate | Revision Log
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 #include "base/tracked_objects.h" 5 #include "base/tracked_objects.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 DCHECK_EQ(parent_stack_.top(), &birth); 384 DCHECK_EQ(parent_stack_.top(), &birth);
385 parent_stack_.pop(); 385 parent_stack_.pop();
386 } 386 }
387 } 387 }
388 388
389 // static 389 // static
390 Births* ThreadData::TallyABirthIfActive(const Location& location) { 390 Births* ThreadData::TallyABirthIfActive(const Location& location) {
391 if (!kTrackAllTaskObjects) 391 if (!kTrackAllTaskObjects)
392 return NULL; // Not compiled in. 392 return NULL; // Not compiled in.
393 393
394 if (!tracking_status()) 394 if (!TrackingStatus())
395 return NULL; 395 return NULL;
396 ThreadData* current_thread_data = Get(); 396 ThreadData* current_thread_data = Get();
397 if (!current_thread_data) 397 if (!current_thread_data)
398 return NULL; 398 return NULL;
399 return current_thread_data->TallyABirth(location); 399 return current_thread_data->TallyABirth(location);
400 } 400 }
401 401
402 // static 402 // static
403 void ThreadData::TallyRunOnNamedThreadIfTracking( 403 void ThreadData::TallyRunOnNamedThreadIfTracking(
404 const base::TrackingInfo& completed_task, 404 const base::TrackingInfo& completed_task,
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 // we get the lock earlier in this method. 613 // we get the lock earlier in this method.
614 status_ = kInitialStartupState; 614 status_ = kInitialStartupState;
615 if (!kTrackParentChildLinks && 615 if (!kTrackParentChildLinks &&
616 kInitialStartupState == PROFILING_CHILDREN_ACTIVE) 616 kInitialStartupState == PROFILING_CHILDREN_ACTIVE)
617 status_ = PROFILING_ACTIVE; 617 status_ = PROFILING_ACTIVE;
618 DCHECK(status_ != UNINITIALIZED); 618 DCHECK(status_ != UNINITIALIZED);
619 return true; 619 return true;
620 } 620 }
621 621
622 // static 622 // static
623 bool ThreadData::InitializeAndSetTrackingStatus(bool status) { 623 bool ThreadData::InitializeAndSetTrackingStatus(Status status) {
624 DCHECK_GE(status, DEACTIVATED);
625 DCHECK_LE(status, PROFILING_CHILDREN_ACTIVE);
626
624 if (!Initialize()) // No-op if already initialized. 627 if (!Initialize()) // No-op if already initialized.
625 return false; // Not compiled in. 628 return false; // Not compiled in.
626 629
627 if (!status) { 630 if (!kTrackParentChildLinks && status > DEACTIVATED)
628 status_ = DEACTIVATED; 631 status = PROFILING_ACTIVE;
629 } else { 632 status_ = status;
630 if (kTrackParentChildLinks)
631 status_ = PROFILING_CHILDREN_ACTIVE;
632 else
633 status_ = PROFILING_ACTIVE;
634 }
635 return true; 633 return true;
636 } 634 }
637 635
638 // static 636 // static
639 bool ThreadData::tracking_status() { 637 ThreadData::Status ThreadData::status() {
638 return status_;
639 }
640
641 // static
642 bool ThreadData::TrackingStatus() {
640 return status_ > DEACTIVATED; 643 return status_ > DEACTIVATED;
641 } 644 }
642 645
643 // static 646 // static
644 bool ThreadData::tracking_parent_child_status() { 647 bool ThreadData::TrackingParentChildStatus() {
645 return status_ >= PROFILING_CHILDREN_ACTIVE; 648 return status_ >= PROFILING_CHILDREN_ACTIVE;
646 } 649 }
647 650
648 // static 651 // static
649 TrackedTime ThreadData::NowForStartOfRun(const Births* parent) { 652 TrackedTime ThreadData::NowForStartOfRun(const Births* parent) {
650 if (kTrackParentChildLinks && parent && status_ > PROFILING_ACTIVE) { 653 if (kTrackParentChildLinks && parent && status_ > PROFILING_ACTIVE) {
651 ThreadData* current_thread_data = Get(); 654 ThreadData* current_thread_data = Get();
652 if (current_thread_data) 655 if (current_thread_data)
653 current_thread_data->parent_stack_.push(parent); 656 current_thread_data->parent_stack_.push(parent);
654 } 657 }
655 return Now(); 658 return Now();
656 } 659 }
657 660
658 // static 661 // static
659 TrackedTime ThreadData::NowForEndOfRun() { 662 TrackedTime ThreadData::NowForEndOfRun() {
660 return Now(); 663 return Now();
661 } 664 }
662 665
663 // static 666 // static
664 TrackedTime ThreadData::Now() { 667 TrackedTime ThreadData::Now() {
665 if (kTrackAllTaskObjects && tracking_status()) 668 if (kTrackAllTaskObjects && TrackingStatus())
666 return TrackedTime::Now(); 669 return TrackedTime::Now();
667 return TrackedTime(); // Super fast when disabled, or not compiled. 670 return TrackedTime(); // Super fast when disabled, or not compiled.
668 } 671 }
669 672
670 // static 673 // static
671 void ThreadData::EnsureCleanupWasCalled(int major_threads_shutdown_count) { 674 void ThreadData::EnsureCleanupWasCalled(int major_threads_shutdown_count) {
672 base::AutoLock lock(*list_lock_.Pointer()); 675 base::AutoLock lock(*list_lock_.Pointer());
673 if (worker_thread_data_creation_count_ == 0) 676 if (worker_thread_data_creation_count_ == 0)
674 return; // We haven't really run much, and couldn't have leaked. 677 return; // We haven't really run much, and couldn't have leaked.
675 // Verify that we've at least shutdown/cleanup the major namesd threads. The 678 // Verify that we've at least shutdown/cleanup the major namesd threads. The
676 // caller should tell us how many thread shutdowns should have taken place by 679 // caller should tell us how many thread shutdowns should have taken place by
677 // now. 680 // now.
678 return; // TODO(jar): until this is working on XP, don't run the real test. 681 return; // TODO(jar): until this is working on XP, don't run the real test.
679 CHECK_GT(cleanup_count_, major_threads_shutdown_count); 682 CHECK_GT(cleanup_count_, major_threads_shutdown_count);
680 } 683 }
681 684
682 // static 685 // static
683 void ThreadData::ShutdownSingleThreadedCleanup(bool leak) { 686 void ThreadData::ShutdownSingleThreadedCleanup(bool leak) {
684 // This is only called from test code, where we need to cleanup so that 687 // This is only called from test code, where we need to cleanup so that
685 // additional tests can be run. 688 // additional tests can be run.
686 // We must be single threaded... but be careful anyway. 689 // We must be single threaded... but be careful anyway.
687 if (!InitializeAndSetTrackingStatus(false)) 690 if (!InitializeAndSetTrackingStatus(DEACTIVATED))
688 return; 691 return;
689 ThreadData* thread_data_list; 692 ThreadData* thread_data_list;
690 { 693 {
691 base::AutoLock lock(*list_lock_.Pointer()); 694 base::AutoLock lock(*list_lock_.Pointer());
692 thread_data_list = all_thread_data_list_head_; 695 thread_data_list = all_thread_data_list_head_;
693 all_thread_data_list_head_ = NULL; 696 all_thread_data_list_head_ = NULL;
694 ++incarnation_counter_; 697 ++incarnation_counter_;
695 // To be clean, break apart the retired worker list (though we leak them). 698 // To be clean, break apart the retired worker list (though we leak them).
696 while (first_retired_worker_) { 699 while (first_retired_worker_) {
697 ThreadData* worker = first_retired_worker_; 700 ThreadData* worker = first_retired_worker_;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 ++it) { 828 ++it) {
826 base::DictionaryValue* parent_child = new base::DictionaryValue; 829 base::DictionaryValue* parent_child = new base::DictionaryValue;
827 it->first->ToValue("parent", parent_child); 830 it->first->ToValue("parent", parent_child);
828 it->second->ToValue("child", parent_child); 831 it->second->ToValue("child", parent_child);
829 descendants->Append(parent_child); 832 descendants->Append(parent_child);
830 } 833 }
831 dictionary->Set("descendants", descendants); 834 dictionary->Set("descendants", descendants);
832 } 835 }
833 836
834 } // namespace tracked_objects 837 } // namespace tracked_objects
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698