| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, base::Bind(&FlushProfilingData, thread), flush_seconds * 1000); |
| 58 } | 58 } |
| 59 | 59 |
| 60 class ProfilingThreadControl { | 60 class ProfilingThreadControl { |
| 61 public: | 61 public: |
| 62 ProfilingThreadControl() {} | 62 ProfilingThreadControl() {} |
| 63 | 63 |
| 64 void Start() { | 64 void Start() { |
| 65 base::AutoLock locked(lock_); | 65 base::AutoLock locked(lock_); |
| 66 | 66 |
| 67 if (thread_ && thread_->IsRunning()) | 67 if (thread_ && thread_->IsRunning()) |
| 68 return; | 68 return; |
| 69 thread_ = new base::Thread("Profiling_Flush"); | 69 thread_ = new base::Thread("Profiling_Flush"); |
| 70 thread_->Start(); | 70 thread_->Start(); |
| 71 thread_->message_loop()->PostTask( | 71 thread_->message_loop()->PostTask( |
| 72 FROM_HERE, base::Bind(FlushProfilingData, thread_)); | 72 FROM_HERE, base::Bind(&FlushProfilingData, thread_)); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void Stop() { | 75 void Stop() { |
| 76 base::AutoLock locked(lock_); | 76 base::AutoLock locked(lock_); |
| 77 | 77 |
| 78 if (!thread_ || !thread_->IsRunning()) | 78 if (!thread_ || !thread_->IsRunning()) |
| 79 return; | 79 return; |
| 80 thread_->Stop(); | 80 thread_->Stop(); |
| 81 delete thread_; | 81 delete thread_; |
| 82 thread_ = NULL; | 82 thread_ = NULL; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 return base::debug::BeingProfiled(); | 132 return base::debug::BeingProfiled(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // static | 135 // static |
| 136 void Profiling::Toggle() { | 136 void Profiling::Toggle() { |
| 137 if (BeingProfiled()) | 137 if (BeingProfiled()) |
| 138 Stop(); | 138 Stop(); |
| 139 else | 139 else |
| 140 Start(); | 140 Start(); |
| 141 } | 141 } |
| OLD | NEW |