Chromium Code Reviews| Index: base/profiler/cpu_profiler.h |
| diff --git a/base/profiler/cpu_profiler.h b/base/profiler/cpu_profiler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1f0e1082f19944001fa9f16a2348ee26d9b33dfe |
| --- /dev/null |
| +++ b/base/profiler/cpu_profiler.h |
| @@ -0,0 +1,93 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BASE_PROFILER_CPU_PROFILER_H_ |
| +#define BASE_PROFILER_CPU_PROFILER_H_ |
| + |
| +#include <map> |
| + |
| +#include "base/base_export.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/strings/string16.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "base/timer/timer.h" |
| + |
| +#if defined(OS_WIN) |
| +struct _CONTEXT; |
| +#endif |
| + |
| +namespace base { |
| + |
| +class SamplingThread : public PlatformThread::Delegate { |
| + public: |
| + SamplingThread(); |
| + ~SamplingThread() override; |
| + |
| + // Implementation of PlatformThread::Delegate: |
| + void ThreadMain() override; |
| + |
| + void Stop(); |
| + |
| + void GetSamples(); |
| + |
| + private: |
| + bool thread_running_; |
| + |
| + base::WaitableEvent waitable_event_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SamplingThread); |
| +}; |
| + |
| +#if defined(OS_WIN) |
| +struct StackTraceEntry { |
| + DWORD64 rsp; |
| + DWORD64 rip; |
| + HMODULE module; |
| +}; |
| +#endif |
| + |
|
cpu_(ooo_6.6-7.5)
2015/02/05 22:41:47
please review the const-ness of each member functi
Mike Wittman
2015/02/06 20:01:14
Done.
|
| +class BASE_EXPORT CpuProfiler { |
| + public: |
| + static void Initialize(const std::map<std::string, std::string>* params); |
| + static CpuProfiler* GetInstance(); |
| + static bool IsPlatformSupported(); |
| + static void Stop(); |
|
cpu_(ooo_6.6-7.5)
2015/02/05 22:41:48
wondering about Stop(), shouldn't it be a member i
Mike Wittman
2015/02/06 20:01:14
Yes, we can do away with the static instance entir
|
| + |
| + std::string GetStringParam(const std::string& key); |
| + int GetIntParam(const std::string& key); |
| + int64 GetInt64Param(const std::string& key); |
| + |
|
cpu_(ooo_6.6-7.5)
2015/02/05 22:41:48
does OnTimer() need to be public?
Mike Wittman
2015/02/06 20:01:15
No. Made it private.
|
| + void OnTimer(); |
| + |
| + private: |
| + CpuProfiler(); |
| + ~CpuProfiler(); |
| + |
| + void SetParams(const std::map<std::string, std::string>& params); |
| + |
| + void GetThreadIds(); |
| + |
| +#if defined(OS_WIN) |
| + void ProcessStack(StackTraceEntry* stack, int stack_depth); |
| + |
| + HANDLE main_thread_; |
| + int main_thread_stack_depth_; |
| + StackTraceEntry main_thread_stack_[64]; |
| + |
| + std::map<HMODULE, base::string16> modules_; |
| +#endif |
| + |
| + static CpuProfiler* g_instance_; |
| + |
| + std::map<std::string, std::string> params_; |
| + |
| + scoped_ptr<SamplingThread> sampling_thread_; |
|
cpu_(ooo_6.6-7.5)
2015/02/05 22:41:47
seems SamplingThread is an internal artifact. Is i
Mike Wittman
2015/02/06 20:01:14
Yes, done.
|
| + PlatformThreadHandle sampling_thread_handle_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CpuProfiler); |
| +}; |
| + |
| +} // namespace base |
| + |
| +#endif // BASE_PROFILER_CPU_PROFILER_H_ |