Chromium Code Reviews| Index: base/tracked_objects.cc |
| diff --git a/base/tracked_objects.cc b/base/tracked_objects.cc |
| index 0847d5f9163622cd65449707775fe7594de9a2b1..def7f2ebdf8b2d56e109b29a8f0e1a216ee4040e 100644 |
| --- a/base/tracked_objects.cc |
| +++ b/base/tracked_objects.cc |
| @@ -7,6 +7,8 @@ |
| #include <limits.h> |
| #include <stdlib.h> |
| +#include "base/base_switches.h" |
| +#include "base/command_line.h" |
| #include "base/compiler_specific.h" |
| #include "base/debug/leak_annotations.h" |
| #include "base/logging.h" |
| @@ -51,6 +53,27 @@ const ThreadData::Status kInitialStartupState = |
| // problem with its presence). |
| static const bool kAllowAlternateTimeSourceHandling = true; |
| +// Control whether to collect timing information. |
| +enum ProfilerTimingState { |
|
Mark Mentovai
2013/12/09 14:18:32
You can move this whole enum definition and variab
qsr
2013/12/09 14:48:32
Done.
|
| + UNDEFINED_TIMING, |
| + ENABLED_TIMING, |
| + DISABLED_TIMING, |
| +} g_timing_enabled = UNDEFINED_TIMING; |
| + |
| +inline bool IsProfilerTimingEnabled() { |
| + // This initialization is not thread-safe, so the value of |g_timing_enabled| |
| + // can be computed multiple time. This is not an issue, as the computed value |
|
Mark Mentovai
2013/12/09 14:18:32
time→times
qsr
2013/12/09 14:48:32
Done.
|
| + // will always be the same, and is side-effect free. |
| + if (g_timing_enabled == UNDEFINED_TIMING) { |
| + g_timing_enabled = (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| + switches::kProfilerTiming) == |
| + switches::kProfilerTimingDisabledValue) |
| + ? DISABLED_TIMING |
| + : ENABLED_TIMING; |
| + } |
| + return g_timing_enabled == ENABLED_TIMING; |
| +} |
| + |
| } // namespace |
| //------------------------------------------------------------------------------ |
| @@ -754,7 +777,7 @@ void ThreadData::SetAlternateTimeSource(NowFunction* now_function) { |
| TrackedTime ThreadData::Now() { |
| if (kAllowAlternateTimeSourceHandling && now_function_) |
| return TrackedTime::FromMilliseconds((*now_function_)()); |
| - if (kTrackAllTaskObjects && TrackingStatus()) |
| + if (kTrackAllTaskObjects && IsProfilerTimingEnabled() && TrackingStatus()) |
| return TrackedTime::Now(); |
| return TrackedTime(); // Super fast when disabled, or not compiled. |
| } |