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 "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" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/location.h" |
| 13 #include "base/single_thread_task_runner.h" |
13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
14 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
15 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
16 #include "gin/public/debug.h" | 17 #include "gin/public/debug.h" |
17 #include "v8/include/v8.h" | 18 #include "v8/include/v8.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 base::debug::AddDynamicSymbol add_dynamic_symbol_func = NULL; | 22 base::debug::AddDynamicSymbol add_dynamic_symbol_func = NULL; |
22 base::debug::MoveDynamicSymbol move_dynamic_symbol_func = NULL; | 23 base::debug::MoveDynamicSymbol move_dynamic_symbol_func = NULL; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 *base::CommandLine::ForCurrentProcess(); | 76 *base::CommandLine::ForCurrentProcess(); |
76 std::string profiling_flush = | 77 std::string profiling_flush = |
77 command_line.GetSwitchValueASCII(switches::kProfilingFlush); | 78 command_line.GetSwitchValueASCII(switches::kProfilingFlush); |
78 if (!profiling_flush.empty()) { | 79 if (!profiling_flush.empty()) { |
79 flush_seconds = atoi(profiling_flush.c_str()); | 80 flush_seconds = atoi(profiling_flush.c_str()); |
80 DCHECK(flush_seconds > 0); | 81 DCHECK(flush_seconds > 0); |
81 } else { | 82 } else { |
82 flush_seconds = kProfilingFlushSeconds; | 83 flush_seconds = kProfilingFlushSeconds; |
83 } | 84 } |
84 } | 85 } |
85 thread->message_loop()->PostDelayedTask( | 86 thread->task_runner()->PostDelayedTask( |
86 FROM_HERE, | 87 FROM_HERE, base::Bind(&FlushProfilingData, thread), |
87 base::Bind(&FlushProfilingData, thread), | |
88 base::TimeDelta::FromSeconds(flush_seconds)); | 88 base::TimeDelta::FromSeconds(flush_seconds)); |
89 } | 89 } |
90 | 90 |
91 class ProfilingThreadControl { | 91 class ProfilingThreadControl { |
92 public: | 92 public: |
93 ProfilingThreadControl() : thread_(NULL) {} | 93 ProfilingThreadControl() : thread_(NULL) {} |
94 | 94 |
95 void Start() { | 95 void Start() { |
96 base::AutoLock locked(lock_); | 96 base::AutoLock locked(lock_); |
97 | 97 |
98 if (thread_ && thread_->IsRunning()) | 98 if (thread_ && thread_->IsRunning()) |
99 return; | 99 return; |
100 thread_ = new base::Thread("Profiling_Flush"); | 100 thread_ = new base::Thread("Profiling_Flush"); |
101 thread_->Start(); | 101 thread_->Start(); |
102 thread_->message_loop()->PostTask( | 102 thread_->task_runner()->PostTask(FROM_HERE, |
103 FROM_HERE, base::Bind(&FlushProfilingData, thread_)); | 103 base::Bind(&FlushProfilingData, thread_)); |
104 } | 104 } |
105 | 105 |
106 void Stop() { | 106 void Stop() { |
107 base::AutoLock locked(lock_); | 107 base::AutoLock locked(lock_); |
108 | 108 |
109 if (!thread_ || !thread_->IsRunning()) | 109 if (!thread_ || !thread_->IsRunning()) |
110 return; | 110 return; |
111 thread_->Stop(); | 111 thread_->Stop(); |
112 delete thread_; | 112 delete thread_; |
113 thread_ = NULL; | 113 thread_ = NULL; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 return base::debug::BeingProfiled(); | 190 return base::debug::BeingProfiled(); |
191 } | 191 } |
192 | 192 |
193 // static | 193 // static |
194 void Profiling::Toggle() { | 194 void Profiling::Toggle() { |
195 if (BeingProfiled()) | 195 if (BeingProfiled()) |
196 Stop(); | 196 Stop(); |
197 else | 197 else |
198 Start(); | 198 Start(); |
199 } | 199 } |
OLD | NEW |