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

Side by Side Diff: base/tracked_objects.cc

Issue 706203003: Update from https://crrev.com/303153 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « base/tracked_objects.h ('k') | base/win/win_util.h » ('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 <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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 // Control whether an alternate time source (Now() function) is supported by 48 // Control whether an alternate time source (Now() function) is supported by
49 // the ThreadData class. This compile time flag should be set to true if we 49 // the ThreadData class. This compile time flag should be set to true if we
50 // want other modules (such as a memory allocator, or a thread-specific CPU time 50 // want other modules (such as a memory allocator, or a thread-specific CPU time
51 // clock) to be able to provide a thread-specific Now() function. Without this 51 // clock) to be able to provide a thread-specific Now() function. Without this
52 // compile-time flag, the code will only support the wall-clock time. This flag 52 // compile-time flag, the code will only support the wall-clock time. This flag
53 // can be flipped to efficiently disable this path (if there is a performance 53 // can be flipped to efficiently disable this path (if there is a performance
54 // problem with its presence). 54 // problem with its presence).
55 static const bool kAllowAlternateTimeSourceHandling = true; 55 static const bool kAllowAlternateTimeSourceHandling = true;
56 56
57 // Possible states of the profiler timing enabledness.
58 enum {
59 UNDEFINED_TIMING,
60 ENABLED_TIMING,
61 DISABLED_TIMING,
62 };
63
64 // State of the profiler timing enabledness.
65 base::subtle::Atomic32 g_profiler_timing_enabled = UNDEFINED_TIMING;
66
67 // Returns whether profiler timing is enabled. The default is true, but this may
68 // be overridden by a command-line flag. Some platforms may programmatically set
69 // this command-line flag to the "off" value if it's not specified.
70 // This in turn can be overridden by explicitly calling
71 // ThreadData::EnableProfilerTiming, say, based on a field trial.
57 inline bool IsProfilerTimingEnabled() { 72 inline bool IsProfilerTimingEnabled() {
58 enum { 73 // Reading |g_profiler_timing_enabled| is done without barrier because
59 UNDEFINED_TIMING, 74 // multiple initialization is not an issue while the barrier can be relatively
60 ENABLED_TIMING, 75 // costly given that this method is sometimes called in a tight loop.
61 DISABLED_TIMING,
62 };
63 static base::subtle::Atomic32 timing_enabled = UNDEFINED_TIMING;
64 // Reading |timing_enabled| is done without barrier because multiple
65 // initialization is not an issue while the barrier can be relatively costly
66 // given that this method is sometimes called in a tight loop.
67 base::subtle::Atomic32 current_timing_enabled = 76 base::subtle::Atomic32 current_timing_enabled =
68 base::subtle::NoBarrier_Load(&timing_enabled); 77 base::subtle::NoBarrier_Load(&g_profiler_timing_enabled);
69 if (current_timing_enabled == UNDEFINED_TIMING) { 78 if (current_timing_enabled == UNDEFINED_TIMING) {
70 if (!CommandLine::InitializedForCurrentProcess()) 79 if (!CommandLine::InitializedForCurrentProcess())
71 return true; 80 return true;
72 current_timing_enabled = 81 current_timing_enabled =
73 (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 82 (CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
74 switches::kProfilerTiming) == 83 switches::kProfilerTiming) ==
75 switches::kProfilerTimingDisabledValue) 84 switches::kProfilerTimingDisabledValue)
76 ? DISABLED_TIMING 85 ? DISABLED_TIMING
77 : ENABLED_TIMING; 86 : ENABLED_TIMING;
78 base::subtle::NoBarrier_Store(&timing_enabled, current_timing_enabled); 87 base::subtle::NoBarrier_Store(&g_profiler_timing_enabled,
88 current_timing_enabled);
79 } 89 }
80 return current_timing_enabled == ENABLED_TIMING; 90 return current_timing_enabled == ENABLED_TIMING;
81 } 91 }
82 92
83 } // namespace 93 } // namespace
84 94
85 //------------------------------------------------------------------------------ 95 //------------------------------------------------------------------------------
86 // DeathData tallies durations when a death takes place. 96 // DeathData tallies durations when a death takes place.
87 97
88 DeathData::DeathData() { 98 DeathData::DeathData() {
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 } 778 }
769 779
770 // static 780 // static
771 void ThreadData::SetAlternateTimeSource(NowFunction* now_function) { 781 void ThreadData::SetAlternateTimeSource(NowFunction* now_function) {
772 DCHECK(now_function); 782 DCHECK(now_function);
773 if (kAllowAlternateTimeSourceHandling) 783 if (kAllowAlternateTimeSourceHandling)
774 now_function_ = now_function; 784 now_function_ = now_function;
775 } 785 }
776 786
777 // static 787 // static
788 void ThreadData::EnableProfilerTiming() {
789 base::subtle::NoBarrier_Store(&g_profiler_timing_enabled, ENABLED_TIMING);
790 }
791
792 // static
778 TrackedTime ThreadData::Now() { 793 TrackedTime ThreadData::Now() {
779 if (kAllowAlternateTimeSourceHandling && now_function_) 794 if (kAllowAlternateTimeSourceHandling && now_function_)
780 return TrackedTime::FromMilliseconds((*now_function_)()); 795 return TrackedTime::FromMilliseconds((*now_function_)());
781 if (kTrackAllTaskObjects && IsProfilerTimingEnabled() && TrackingStatus()) 796 if (kTrackAllTaskObjects && IsProfilerTimingEnabled() && TrackingStatus())
782 return TrackedTime::Now(); 797 return TrackedTime::Now();
783 return TrackedTime(); // Super fast when disabled, or not compiled. 798 return TrackedTime(); // Super fast when disabled, or not compiled.
784 } 799 }
785 800
786 // static 801 // static
787 void ThreadData::EnsureCleanupWasCalled(int major_threads_shutdown_count) { 802 void ThreadData::EnsureCleanupWasCalled(int major_threads_shutdown_count) {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 : process_id(base::GetCurrentProcId()) { 1000 : process_id(base::GetCurrentProcId()) {
986 #else 1001 #else
987 : process_id(0) { 1002 : process_id(0) {
988 #endif 1003 #endif
989 } 1004 }
990 1005
991 ProcessDataSnapshot::~ProcessDataSnapshot() { 1006 ProcessDataSnapshot::~ProcessDataSnapshot() {
992 } 1007 }
993 1008
994 } // namespace tracked_objects 1009 } // namespace tracked_objects
OLDNEW
« no previous file with comments | « base/tracked_objects.h ('k') | base/win/win_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698