| 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..4be9892d68aca3ec8aa77ff823878fc2721c75c5
|
| --- /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
|
| +
|
| +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)
|
| + 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_;
|
| + PlatformThreadHandle sampling_thread_handle_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(CpuProfiler);
|
| +};
|
| +
|
| +} // namespace base
|
| +
|
| +#endif // BASE_PROFILER_CPU_PROFILER_H_
|
|
|