 Chromium Code Reviews
 Chromium Code Reviews Issue 888923004:
  Temporary commit to evaluate perf impact of prototype CPU profiler  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
    
  
    Issue 888923004:
  Temporary commit to evaluate perf impact of prototype CPU profiler  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr| 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. | 
| + | 
| + | 
| 
Ilya Sherman
2015/02/03 22:12:10
nit: Spurious newline.
 
Mike Wittman
2015/02/04 01:37:10
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_; | 
| +}; | 
| 
Ilya Sherman
2015/02/03 22:12:10
Please move this class into a separate header + im
 
Mike Wittman
2015/02/04 01:37:10
Can we keep this as-is for purposes of this commit
 
Ilya Sherman
2015/02/04 23:09:57
Ah, right, I recall now that you mentioned this wa
 | 
| + | 
| +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_; | 
| + | 
| + 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 | 
| 
Ilya Sherman
2015/02/03 22:12:10
I'd really prefer that you find a way to keep the
 
Mike Wittman
2015/02/04 01:37:10
Again, can we keep this as-is for purposes of this
 | 
| + | 
| + static CpuProfiler* g_instance_; | 
| + | 
| + typedef std::map<std::string, std::string> Map; | 
| 
Ilya Sherman
2015/02/03 22:12:10
nit: I'm really not fond of this typedef -- especi
 
Mike Wittman
2015/02/04 01:37:10
Done.
 | 
| + Map params_; | 
| + | 
| + scoped_ptr<SamplingThread> sampling_thread_; | 
| + PlatformThreadHandle sampling_thread_handle_; | 
| +}; | 
| + | 
| +} | 
| 
Ilya Sherman
2015/02/03 22:12:10
nit: This line should be "}  // namespace base".
 
Mike Wittman
2015/02/04 01:37:10
Done.
 | 
| + | 
| + | 
| 
Ilya Sherman
2015/02/03 22:12:09
nit: Spurious newline.
 
Mike Wittman
2015/02/04 01:37:10
Done.
 | 
| +#endif // BASE_PROFILER_CPU_PROFILER_H_ |