Chromium Code Reviews| Index: base/profiler/tracked_time.cc |
| diff --git a/base/profiler/tracked_time.cc b/base/profiler/tracked_time.cc |
| index 7791c3adc6b8580f09ccffd100bc6a2dd241c81f..1c2393f487019a69c0b4995681dcfe871415c9a9 100644 |
| --- a/base/profiler/tracked_time.cc |
| +++ b/base/profiler/tracked_time.cc |
| @@ -4,12 +4,36 @@ |
| #include "base/profiler/tracked_time.h" |
| +#include "base/base_switches.h" |
| +#include "base/command_line.h" |
| #include "build/build_config.h" |
| #if defined(OS_WIN) |
| #include <mmsystem.h> // Declare timeGetTime()... after including build_config. |
| #endif |
| +namespace { |
| +enum ProfilerTimingState { |
| + 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 |
| + // 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 |
| + |
| namespace tracked_objects { |
| Duration::Duration() : ms_(0) {} |
| @@ -51,6 +75,8 @@ TrackedTime::TrackedTime(const base::TimeTicks& time) |
| // static |
| TrackedTime TrackedTime::Now() { |
| + if (!IsProfilerTimingEnabled()) |
| + return TrackedTime(); |
|
no sievers
2013/12/06 20:13:54
What functionally does this break exactly?
Seems w
jar (doing other things)
2013/12/06 21:57:39
This stops getting timing... but still gets call c
|
| #if defined(OS_WIN) |
| // Use lock-free accessor to 32 bit time. |
| // Note that TimeTicks::Now() is built on this, so we have "compatible" |