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..e22e24e60e4c06510eec0559d2af09b794ffb758 100644 |
| --- a/base/profiler/tracked_time.cc |
| +++ b/base/profiler/tracked_time.cc |
| @@ -4,12 +4,28 @@ |
| #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 { |
| +inline bool IsProfilerTimingEnabled() { |
| + // This initialization is not thread safe. In particular, some early calls |
|
Mark Mentovai
2013/12/05 23:54:04
Nit: thread-safe (with dash).
qsr
2013/12/06 14:29:43
Done.
|
| + // might see |timing_disabled| being false, even if this is incorrect. This is |
| + // OK, as the timing is only disabled for performance reasons, and having a |
| + // few calls to TimeTicks::Now() is acceptable, while needing to use a lock or |
| + // a memory barrier would be more costly. |
| + static bool timing_disabled = |
| + CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| + switches::kProfilerTiming) == "0"; |
|
jar (doing other things)
2013/12/05 23:51:06
You can indeed change the name to avoid negatives.
Mark Mentovai
2013/12/05 23:56:05
jar wrote:
qsr
2013/12/06 14:29:43
Done.
no sievers
2013/12/09 18:59:29
Or you could just use LazyInstance (or Singleton),
|
| + return !timing_disabled; |
| +} |
| +} // namespace |
| + |
| namespace tracked_objects { |
| Duration::Duration() : ms_(0) {} |
| @@ -51,15 +67,18 @@ TrackedTime::TrackedTime(const base::TimeTicks& time) |
| // static |
| TrackedTime TrackedTime::Now() { |
| + if (IsProfilerTimingEnabled()) { |
|
jar (doing other things)
2013/12/05 23:51:06
nit: Early return, inducing less indentation, etc.
Mark Mentovai
2013/12/05 23:54:04
I’d rather flip the logic. Having the “real” defin
qsr
2013/12/06 14:29:43
Done.
|
| #if defined(OS_WIN) |
| - // Use lock-free accessor to 32 bit time. |
| - // Note that TimeTicks::Now() is built on this, so we have "compatible" |
| - // times when we down-convert a TimeTicks sample. |
| - return TrackedTime(base::TimeTicks::UnprotectedNow()); |
| + // Use lock-free accessor to 32 bit time. |
| + // Note that TimeTicks::Now() is built on this, so we have "compatible" |
| + // times when we down-convert a TimeTicks sample. |
| + return TrackedTime(base::TimeTicks::UnprotectedNow()); |
| #else |
| - // Posix has nice cheap 64 bit times, so we just down-convert it. |
| - return TrackedTime(base::TimeTicks::Now()); |
| + // Posix has nice cheap 64 bit times, so we just down-convert it. |
| + return TrackedTime(base::TimeTicks::Now()); |
| #endif // OS_WIN |
| + } |
| + return TrackedTime(); |
| } |
| Duration TrackedTime::operator-(const TrackedTime& other) const { |