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

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

Powered by Google App Engine
This is Rietveld 408576698