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

Side by Side Diff: base/tracked_objects.cc

Issue 2973543002: Record task durations on Renderer Main & Compositor threads.
Patch Set: Fix layering issues. Created 3 years, 4 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
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 <ctype.h> 7 #include <ctype.h>
8 #include <limits.h> 8 #include <limits.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 10
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 ThreadData::list_lock_ = LAZY_INSTANCE_INITIALIZER; 516 ThreadData::list_lock_ = LAZY_INSTANCE_INITIALIZER;
517 517
518 // static 518 // static
519 base::subtle::Atomic32 ThreadData::status_ = ThreadData::UNINITIALIZED; 519 base::subtle::Atomic32 ThreadData::status_ = ThreadData::UNINITIALIZED;
520 520
521 ThreadData::ThreadData(const std::string& sanitized_thread_name) 521 ThreadData::ThreadData(const std::string& sanitized_thread_name)
522 : next_(NULL), 522 : next_(NULL),
523 next_retired_thread_data_(NULL), 523 next_retired_thread_data_(NULL),
524 sanitized_thread_name_(sanitized_thread_name), 524 sanitized_thread_name_(sanitized_thread_name),
525 incarnation_count_for_pool_(-1), 525 incarnation_count_for_pool_(-1),
526 current_stopwatch_(NULL) { 526 current_stopwatch_(NULL),
527 task_length_recording_enabled_for_uma_(false) {
527 DCHECK(sanitized_thread_name_.empty() || 528 DCHECK(sanitized_thread_name_.empty() ||
528 !isdigit(sanitized_thread_name_.back())); 529 !isdigit(sanitized_thread_name_.back()));
529 PushToHeadOfList(); // Which sets real incarnation_count_for_pool_. 530 PushToHeadOfList(); // Which sets real incarnation_count_for_pool_.
530 } 531 }
531 532
532 ThreadData::~ThreadData() { 533 ThreadData::~ThreadData() {
533 } 534 }
534 535
535 void ThreadData::PushToHeadOfList() { 536 void ThreadData::PushToHeadOfList() {
536 // Toss in a hint of randomness (atop the uniniitalized value). 537 // Toss in a hint of randomness (atop the uniniitalized value).
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 } 863 }
863 864
864 void ThreadData::OnProfilingPhaseCompletedOnThread(int profiling_phase) { 865 void ThreadData::OnProfilingPhaseCompletedOnThread(int profiling_phase) {
865 base::AutoLock lock(map_lock_); 866 base::AutoLock lock(map_lock_);
866 867
867 for (auto& death : death_map_) { 868 for (auto& death : death_map_) {
868 death.second.OnProfilingPhaseCompleted(profiling_phase); 869 death.second.OnProfilingPhaseCompleted(profiling_phase);
869 } 870 }
870 } 871 }
871 872
873 void ThreadData::EnableTaskDurationRecordingForUMA() {
874 task_length_recording_enabled_for_uma_ = true;
875 }
876
872 void ThreadData::EnsureTlsInitialization() { 877 void ThreadData::EnsureTlsInitialization() {
873 if (base::subtle::Acquire_Load(&status_) >= DEACTIVATED) 878 if (base::subtle::Acquire_Load(&status_) >= DEACTIVATED)
874 return; // Someone else did the initialization. 879 return; // Someone else did the initialization.
875 // Due to racy lazy initialization in tests, we'll need to recheck status_ 880 // Due to racy lazy initialization in tests, we'll need to recheck status_
876 // after we acquire the lock. 881 // after we acquire the lock.
877 882
878 // Ensure that we don't double initialize tls. We are called when single 883 // Ensure that we don't double initialize tls. We are called when single
879 // threaded in the product, but some tests may be racy and lazy about our 884 // threaded in the product, but some tests may be racy and lazy about our
880 // initialization. 885 // initialization.
881 base::AutoLock lock(*list_lock_.Pointer()); 886 base::AutoLock lock(*list_lock_.Pointer());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 // static 935 // static
931 void ThreadData::EnableProfilerTiming() { 936 void ThreadData::EnableProfilerTiming() {
932 base::subtle::NoBarrier_Store(&g_profiler_timing_enabled, ENABLED_TIMING); 937 base::subtle::NoBarrier_Store(&g_profiler_timing_enabled, ENABLED_TIMING);
933 } 938 }
934 939
935 // static 940 // static
936 base::TimeTicks ThreadData::Now() { 941 base::TimeTicks ThreadData::Now() {
937 if (now_function_for_testing_) 942 if (now_function_for_testing_)
938 return base::TimeTicks() + 943 return base::TimeTicks() +
939 base::TimeDelta::FromMilliseconds((*now_function_for_testing_)()); 944 base::TimeDelta::FromMilliseconds((*now_function_for_testing_)());
945
940 if (IsProfilerTimingEnabled() && TrackingStatus()) 946 if (IsProfilerTimingEnabled() && TrackingStatus())
941 return base::TimeTicks::Now(); 947 return base::TimeTicks::Now();
942 return base::TimeTicks(); // Super fast when disabled, or not compiled. 948 return base::TimeTicks(); // Super fast when disabled, or not compiled.
943 } 949 }
944 950
945 // static 951 // static
952 base::TimeTicks ThreadData::Now(const ThreadData* thread_data) {
953 base::TimeTicks now = ThreadData::Now();
954 if (!now.is_null())
955 return now;
956 if (!thread_data)
957 return base::TimeTicks();
958 if (thread_data->task_length_recording_enabled_for_uma())
959 return base::TimeTicks::Now();
960 return base::TimeTicks();
961 }
962
963 // static
946 void ThreadData::EnsureCleanupWasCalled(int major_threads_shutdown_count) { 964 void ThreadData::EnsureCleanupWasCalled(int major_threads_shutdown_count) {
947 base::AutoLock lock(*list_lock_.Pointer()); 965 base::AutoLock lock(*list_lock_.Pointer());
948 966
949 // TODO(jar): until this is working on XP, don't run the real test. 967 // TODO(jar): until this is working on XP, don't run the real test.
950 #if 0 968 #if 0
951 // Verify that we've at least shutdown/cleanup the major namesd threads. The 969 // Verify that we've at least shutdown/cleanup the major namesd threads. The
952 // caller should tell us how many thread shutdowns should have taken place by 970 // caller should tell us how many thread shutdowns should have taken place by
953 // now. 971 // now.
954 CHECK_GT(cleanup_count_, major_threads_shutdown_count); 972 CHECK_GT(cleanup_count_, major_threads_shutdown_count);
955 #endif 973 #endif
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 DCHECK(state_ != RUNNING); 1080 DCHECK(state_ != RUNNING);
1063 DCHECK(child_ == NULL); 1081 DCHECK(child_ == NULL);
1064 #endif 1082 #endif
1065 } 1083 }
1066 1084
1067 void TaskStopwatch::Start() { 1085 void TaskStopwatch::Start() {
1068 #if DCHECK_IS_ON() 1086 #if DCHECK_IS_ON()
1069 DCHECK(state_ == CREATED); 1087 DCHECK(state_ == CREATED);
1070 state_ = RUNNING; 1088 state_ = RUNNING;
1071 #endif 1089 #endif
1072 1090 current_thread_data_ = ThreadData::Get();
1073 start_time_ = ThreadData::Now(); 1091 start_time_ = ThreadData::Now(current_thread_data_);
1074 #if BUILDFLAG(USE_ALLOCATOR_SHIM) 1092 #if BUILDFLAG(USE_ALLOCATOR_SHIM)
1075 if (heap_tracking_enabled_) 1093 if (heap_tracking_enabled_)
1076 heap_usage_.Start(); 1094 heap_usage_.Start();
1077 #endif 1095 #endif
1078 1096
1079 current_thread_data_ = ThreadData::Get();
1080 if (!current_thread_data_) 1097 if (!current_thread_data_)
1081 return; 1098 return;
1082 1099
1083 parent_ = current_thread_data_->current_stopwatch_; 1100 parent_ = current_thread_data_->current_stopwatch_;
1084 #if DCHECK_IS_ON() 1101 #if DCHECK_IS_ON()
1085 if (parent_) { 1102 if (parent_) {
1086 DCHECK(parent_->state_ == RUNNING); 1103 DCHECK(parent_->state_ == RUNNING);
1087 DCHECK(parent_->child_ == NULL); 1104 DCHECK(parent_->child_ == NULL);
1088 parent_->child_ = this; 1105 parent_->child_ = this;
1089 } 1106 }
1090 #endif 1107 #endif
1091 current_thread_data_->current_stopwatch_ = this; 1108 current_thread_data_->current_stopwatch_ = this;
1092 } 1109 }
1093 1110
1094 void TaskStopwatch::Stop() { 1111 void TaskStopwatch::Stop() {
1095 const base::TimeTicks end_time = ThreadData::Now(); 1112 const base::TimeTicks end_time = ThreadData::Now(current_thread_data_);
1096 #if DCHECK_IS_ON() 1113 #if DCHECK_IS_ON()
1097 DCHECK(state_ == RUNNING); 1114 DCHECK(state_ == RUNNING);
1098 state_ = STOPPED; 1115 state_ = STOPPED;
1099 DCHECK(child_ == NULL); 1116 DCHECK(child_ == NULL);
1100 #endif 1117 #endif
1101 #if BUILDFLAG(USE_ALLOCATOR_SHIM) 1118 #if BUILDFLAG(USE_ALLOCATOR_SHIM)
1102 if (heap_tracking_enabled_) 1119 if (heap_tracking_enabled_)
1103 heap_usage_.Stop(true); 1120 heap_usage_.Stop(true);
1104 #endif 1121 #endif
1105 1122
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 #endif 1213 #endif
1197 } 1214 }
1198 1215
1199 ProcessDataSnapshot::ProcessDataSnapshot(const ProcessDataSnapshot& other) = 1216 ProcessDataSnapshot::ProcessDataSnapshot(const ProcessDataSnapshot& other) =
1200 default; 1217 default;
1201 1218
1202 ProcessDataSnapshot::~ProcessDataSnapshot() { 1219 ProcessDataSnapshot::~ProcessDataSnapshot() {
1203 } 1220 }
1204 1221
1205 } // namespace tracked_objects 1222 } // namespace tracked_objects
OLDNEW
« base/tracked_objects.h ('K') | « base/tracked_objects.h ('k') | base/tracking_info.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698