Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/profiler/tracked_time.h" | 5 #include "base/profiler/tracked_time.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | |
| 8 #include "base/command_line.h" | |
| 7 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 8 | 10 |
| 9 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
| 10 #include <mmsystem.h> // Declare timeGetTime()... after including build_config. | 12 #include <mmsystem.h> // Declare timeGetTime()... after including build_config. |
| 11 #endif | 13 #endif |
| 12 | 14 |
| 15 namespace { | |
| 16 inline bool IsProfilerTimingDisabled() { | |
|
jar (doing other things)
2013/12/02 19:01:50
Nit: code is IMO always much more confusing when n
qsr
2013/12/03 11:33:44
Done. But I didn't change the static variable, as
| |
| 17 // This initialization is not thread safe. In particular, some early calls | |
| 18 // might see |timing_disabled| being false, even if this is incorrect. This is | |
| 19 // OK, as the timing is only disabled for performance reasons, and having a | |
| 20 // few calls to TimeTicks::Now() is acceptable, while needing to use a lock or | |
| 21 // a memory barrier would be more costly. | |
| 22 static bool timing_disabled = CommandLine::ForCurrentProcess()->HasSwitch( | |
| 23 switches::kDisableProfilerTiming) && | |
| 24 !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 25 switches::kEnableProfilerTiming); | |
| 26 return timing_disabled; | |
| 27 } | |
| 28 } // namespace | |
| 29 | |
| 13 namespace tracked_objects { | 30 namespace tracked_objects { |
| 14 | 31 |
| 15 Duration::Duration() : ms_(0) {} | 32 Duration::Duration() : ms_(0) {} |
| 16 Duration::Duration(int32 duration) : ms_(duration) {} | 33 Duration::Duration(int32 duration) : ms_(duration) {} |
| 17 | 34 |
| 18 Duration& Duration::operator+=(const Duration& other) { | 35 Duration& Duration::operator+=(const Duration& other) { |
| 19 ms_ += other.ms_; | 36 ms_ += other.ms_; |
| 20 return *this; | 37 return *this; |
| 21 } | 38 } |
| 22 | 39 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 44 //------------------------------------------------------------------------------ | 61 //------------------------------------------------------------------------------ |
| 45 | 62 |
| 46 TrackedTime::TrackedTime() : ms_(0) {} | 63 TrackedTime::TrackedTime() : ms_(0) {} |
| 47 TrackedTime::TrackedTime(int32 ms) : ms_(ms) {} | 64 TrackedTime::TrackedTime(int32 ms) : ms_(ms) {} |
| 48 TrackedTime::TrackedTime(const base::TimeTicks& time) | 65 TrackedTime::TrackedTime(const base::TimeTicks& time) |
| 49 : ms_((time - base::TimeTicks()).InMilliseconds()) { | 66 : ms_((time - base::TimeTicks()).InMilliseconds()) { |
| 50 } | 67 } |
| 51 | 68 |
| 52 // static | 69 // static |
| 53 TrackedTime TrackedTime::Now() { | 70 TrackedTime TrackedTime::Now() { |
| 71 if (IsProfilerTimingDisabled()) | |
| 72 return TrackedTime(); | |
| 54 #if defined(OS_WIN) | 73 #if defined(OS_WIN) |
| 55 // Use lock-free accessor to 32 bit time. | 74 // Use lock-free accessor to 32 bit time. |
| 56 // Note that TimeTicks::Now() is built on this, so we have "compatible" | 75 // Note that TimeTicks::Now() is built on this, so we have "compatible" |
| 57 // times when we down-convert a TimeTicks sample. | 76 // times when we down-convert a TimeTicks sample. |
| 58 return TrackedTime(base::TimeTicks::UnprotectedNow()); | 77 return TrackedTime(base::TimeTicks::UnprotectedNow()); |
| 59 #else | 78 #else |
| 60 // Posix has nice cheap 64 bit times, so we just down-convert it. | 79 // Posix has nice cheap 64 bit times, so we just down-convert it. |
| 61 return TrackedTime(base::TimeTicks::Now()); | 80 return TrackedTime(base::TimeTicks::Now()); |
| 62 #endif // OS_WIN | 81 #endif // OS_WIN |
| 63 } | 82 } |
| 64 | 83 |
| 65 Duration TrackedTime::operator-(const TrackedTime& other) const { | 84 Duration TrackedTime::operator-(const TrackedTime& other) const { |
| 66 return Duration(ms_ - other.ms_); | 85 return Duration(ms_ - other.ms_); |
| 67 } | 86 } |
| 68 | 87 |
| 69 TrackedTime TrackedTime::operator+(const Duration& other) const { | 88 TrackedTime TrackedTime::operator+(const Duration& other) const { |
| 70 return TrackedTime(ms_ + other.ms_); | 89 return TrackedTime(ms_ + other.ms_); |
| 71 } | 90 } |
| 72 | 91 |
| 73 bool TrackedTime::is_null() const { return ms_ == 0; } | 92 bool TrackedTime::is_null() const { return ms_ == 0; } |
| 74 | 93 |
| 75 } // namespace tracked_objects | 94 } // namespace tracked_objects |
| OLD | NEW |