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

Side by Side Diff: base/profiler/tracked_time.cc

Issue 99343002: Disable timing from chrome://profiler on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Follow review Created 7 years 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 | Annotate | Revision Log
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/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 enum ProfilerTimingState {
17 UNDEFINED_TIMING,
18 ENABLED_TIMING,
19 DISABLED_TIMING,
20 } g_timing_enabled = UNDEFINED_TIMING;
21
22 inline bool IsProfilerTimingEnabled() {
23 // This initialization is not thread-safe, so the value of |g_timing_enabled|
24 // can be computed multiple time. This is not an issue, as the computed value
25 // will always be the same, and is side-effect free.
26 if (g_timing_enabled == UNDEFINED_TIMING) {
27 g_timing_enabled = (CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
28 switches::kProfilerTiming) ==
29 switches::kProfilerTimingDisabledValue)
30 ? DISABLED_TIMING
31 : ENABLED_TIMING;
32 }
33 return g_timing_enabled == ENABLED_TIMING;
34 }
35 } // namespace
36
13 namespace tracked_objects { 37 namespace tracked_objects {
14 38
15 Duration::Duration() : ms_(0) {} 39 Duration::Duration() : ms_(0) {}
16 Duration::Duration(int32 duration) : ms_(duration) {} 40 Duration::Duration(int32 duration) : ms_(duration) {}
17 41
18 Duration& Duration::operator+=(const Duration& other) { 42 Duration& Duration::operator+=(const Duration& other) {
19 ms_ += other.ms_; 43 ms_ += other.ms_;
20 return *this; 44 return *this;
21 } 45 }
22 46
(...skipping 21 matching lines...) Expand all
44 //------------------------------------------------------------------------------ 68 //------------------------------------------------------------------------------
45 69
46 TrackedTime::TrackedTime() : ms_(0) {} 70 TrackedTime::TrackedTime() : ms_(0) {}
47 TrackedTime::TrackedTime(int32 ms) : ms_(ms) {} 71 TrackedTime::TrackedTime(int32 ms) : ms_(ms) {}
48 TrackedTime::TrackedTime(const base::TimeTicks& time) 72 TrackedTime::TrackedTime(const base::TimeTicks& time)
49 : ms_((time - base::TimeTicks()).InMilliseconds()) { 73 : ms_((time - base::TimeTicks()).InMilliseconds()) {
50 } 74 }
51 75
52 // static 76 // static
53 TrackedTime TrackedTime::Now() { 77 TrackedTime TrackedTime::Now() {
78 if (!IsProfilerTimingEnabled())
79 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
54 #if defined(OS_WIN) 80 #if defined(OS_WIN)
55 // Use lock-free accessor to 32 bit time. 81 // Use lock-free accessor to 32 bit time.
56 // Note that TimeTicks::Now() is built on this, so we have "compatible" 82 // Note that TimeTicks::Now() is built on this, so we have "compatible"
57 // times when we down-convert a TimeTicks sample. 83 // times when we down-convert a TimeTicks sample.
58 return TrackedTime(base::TimeTicks::UnprotectedNow()); 84 return TrackedTime(base::TimeTicks::UnprotectedNow());
59 #else 85 #else
60 // Posix has nice cheap 64 bit times, so we just down-convert it. 86 // Posix has nice cheap 64 bit times, so we just down-convert it.
61 return TrackedTime(base::TimeTicks::Now()); 87 return TrackedTime(base::TimeTicks::Now());
62 #endif // OS_WIN 88 #endif // OS_WIN
63 } 89 }
64 90
65 Duration TrackedTime::operator-(const TrackedTime& other) const { 91 Duration TrackedTime::operator-(const TrackedTime& other) const {
66 return Duration(ms_ - other.ms_); 92 return Duration(ms_ - other.ms_);
67 } 93 }
68 94
69 TrackedTime TrackedTime::operator+(const Duration& other) const { 95 TrackedTime TrackedTime::operator+(const Duration& other) const {
70 return TrackedTime(ms_ + other.ms_); 96 return TrackedTime(ms_ + other.ms_);
71 } 97 }
72 98
73 bool TrackedTime::is_null() const { return ms_ == 0; } 99 bool TrackedTime::is_null() const { return ms_ == 0; }
74 100
75 } // namespace tracked_objects 101 } // namespace tracked_objects
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698