OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/common/profiling.h" | 5 #include "chrome/common/profiling.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/profiler.h" | 10 #include "base/debug/profiler.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 return profile_name; | 34 return profile_name; |
35 } | 35 } |
36 | 36 |
37 void FlushProfilingData(base::Thread* thread) { | 37 void FlushProfilingData(base::Thread* thread) { |
38 static const int kProfilingFlushSeconds = 10; | 38 static const int kProfilingFlushSeconds = 10; |
39 | 39 |
40 if (!Profiling::BeingProfiled()) | 40 if (!Profiling::BeingProfiled()) |
41 return; | 41 return; |
42 | 42 |
43 base::debug::FlushProfiling(); | 43 base::debug::FlushProfiling(); |
44 static int flush_seconds = 0; | 44 static int flush_seconds; |
45 if (!flush_seconds) { | 45 if (!flush_seconds) { |
46 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 46 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
47 std::string profiling_flush = | 47 std::string profiling_flush = |
48 command_line.GetSwitchValueASCII(switches::kProfilingFlush); | 48 command_line.GetSwitchValueASCII(switches::kProfilingFlush); |
49 if (!profiling_flush.empty()) { | 49 if (!profiling_flush.empty()) { |
50 flush_seconds = atoi(profiling_flush.c_str()); | 50 flush_seconds = atoi(profiling_flush.c_str()); |
51 DCHECK(flush_seconds > 0); | 51 DCHECK(flush_seconds > 0); |
52 } else { | 52 } else { |
53 flush_seconds = kProfilingFlushSeconds; | 53 flush_seconds = kProfilingFlushSeconds; |
54 } | 54 } |
55 } | 55 } |
56 thread->message_loop()->PostDelayedTask( | 56 thread->message_loop()->PostDelayedTask( |
57 FROM_HERE, base::Bind(&FlushProfilingData, thread), flush_seconds * 1000); | 57 FROM_HERE, |
| 58 base::Bind(&FlushProfilingData, thread), |
| 59 base::TimeDelta::FromSeconds(flush_seconds)); |
58 } | 60 } |
59 | 61 |
60 class ProfilingThreadControl { | 62 class ProfilingThreadControl { |
61 public: | 63 public: |
62 ProfilingThreadControl() : thread_(NULL) {} | 64 ProfilingThreadControl() : thread_(NULL) {} |
63 | 65 |
64 void Start() { | 66 void Start() { |
65 base::AutoLock locked(lock_); | 67 base::AutoLock locked(lock_); |
66 | 68 |
67 if (thread_ && thread_->IsRunning()) | 69 if (thread_ && thread_->IsRunning()) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 return base::debug::BeingProfiled(); | 134 return base::debug::BeingProfiled(); |
133 } | 135 } |
134 | 136 |
135 // static | 137 // static |
136 void Profiling::Toggle() { | 138 void Profiling::Toggle() { |
137 if (BeingProfiled()) | 139 if (BeingProfiled()) |
138 Stop(); | 140 Stop(); |
139 else | 141 else |
140 Start(); | 142 Start(); |
141 } | 143 } |
OLD | NEW |