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..6ce17713d4ec0373c5f47198984b4e7e6d7c62b5 |
| --- /dev/null |
| +++ b/base/profiler/cpu_profiler.h |
| @@ -0,0 +1,104 @@ |
| +// 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. |
| + |
| + |
|
cpu_(ooo_6.6-7.5)
2015/02/03 02:40:53
remove line at 5
Mike Wittman
2015/02/04 01:37:09
Done.
|
| +#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_; |
|
cpu_(ooo_6.6-7.5)
2015/02/03 02:40:53
disable copy ctor and assignment
Mike Wittman
2015/02/04 01:37:09
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(); |
| + |
| + std::string GetStringParam(const std::string& key); |
| + int GetIntParam(const std::string& key); |
| + int64 GetInt64Param(const std::string& key); |
| + |
| + void OnTimer(); |
| + |
| + private: |
| + CpuProfiler(); |
| + ~CpuProfiler(); |
| + |
| + void SetParams(const std::map<std::string, std::string>& params); |
| + |
| + void GetThreadIds(); |
| + |
| +#if defined(OS_WIN) |
| + struct StackTraceEntry { |
| + DWORD64 rsp; |
| + DWORD64 rip; |
| + HMODULE module; |
| + }; |
| + |
| + int SampleThread(DWORD thread, int max_stack_size, StackTraceEntry* stack); |
| + |
| + static int StackTrace64(_CONTEXT* context, int stack_depth, |
| + StackTraceEntry* stack_trace); |
| + |
| + static void GetNames(StackTraceEntry* stack_trace, int stack_depth); |
| + |
| + void ResolveModules(); |
| + |
| + void ProcessStack(StackTraceEntry* stack, int stack_depth); |
| + |
| + DWORD ui_thread_; |
| + DWORD io_thread_; |
|
cpu_(ooo_6.6-7.5)
2015/02/03 02:40:53
are these two dwords the thread id? seems kind of
Mike Wittman
2015/02/04 01:37:09
Changed to use a handle.
|
| + |
| + int ui_thread_stack_depth_; |
| + StackTraceEntry ui_thread_stack_[64]; |
| + |
| + int io_thread_stack_depth_; |
| + StackTraceEntry io_thread_stack_[64]; |
| + |
| + std::map<HMODULE, base::string16> modules_; |
| +#endif |
| + |
| + static CpuProfiler* g_instance_; |
| + |
| + typedef std::map<std::string, std::string> Map; |
| + Map params_; |
|
cpu_(ooo_6.6-7.5)
2015/02/03 02:40:53
you can use auto, which should eliminate most need
Mike Wittman
2015/02/04 01:37:09
Done.
|
| + |
| + scoped_ptr<SamplingThread> sampling_thread_; |
| + PlatformThreadHandle sampling_thread_handle_; |
| +}; |
| + |
| +} |
| + |
| + |
| +#endif // BASE_PROFILER_CPU_PROFILER_H_ |