Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 | |
|
Ilya Sherman
2015/02/03 22:12:10
nit: Spurious newline.
Mike Wittman
2015/02/04 01:37:10
Done.
| |
| 6 #ifndef BASE_PROFILER_CPU_PROFILER_H_ | |
| 7 #define BASE_PROFILER_CPU_PROFILER_H_ | |
| 8 | |
| 9 #include <map> | |
| 10 | |
| 11 #include "base/base_export.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/strings/string16.h" | |
| 14 #include "base/synchronization/waitable_event.h" | |
| 15 #include "base/timer/timer.h" | |
| 16 | |
| 17 #if defined(OS_WIN) | |
| 18 struct _CONTEXT; | |
| 19 #endif | |
| 20 | |
| 21 namespace base { | |
| 22 | |
| 23 class SamplingThread : public PlatformThread::Delegate { | |
| 24 public: | |
| 25 SamplingThread(); | |
| 26 ~SamplingThread() override; | |
| 27 | |
| 28 // Implementation of PlatformThread::Delegate: | |
| 29 void ThreadMain() override; | |
| 30 | |
| 31 void Stop(); | |
| 32 | |
| 33 void GetSamples(); | |
| 34 | |
| 35 private: | |
| 36 bool thread_running_; | |
| 37 | |
| 38 base::WaitableEvent waitable_event_; | |
| 39 }; | |
|
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
| |
| 40 | |
| 41 class BASE_EXPORT CpuProfiler { | |
| 42 public: | |
| 43 static void Initialize(const std::map<std::string, std::string>& params); | |
| 44 static CpuProfiler* GetInstance(); | |
| 45 static bool IsPlatformSupported(); | |
| 46 static void Stop(); | |
| 47 | |
| 48 std::string GetStringParam(const std::string& key); | |
| 49 int GetIntParam(const std::string& key); | |
| 50 int64 GetInt64Param(const std::string& key); | |
| 51 | |
| 52 void OnTimer(); | |
| 53 | |
| 54 private: | |
| 55 CpuProfiler(); | |
| 56 ~CpuProfiler(); | |
| 57 | |
| 58 void SetParams(const std::map<std::string, std::string>& params); | |
| 59 | |
| 60 void GetThreadIds(); | |
| 61 | |
| 62 #if defined(OS_WIN) | |
| 63 struct StackTraceEntry { | |
| 64 DWORD64 rsp; | |
| 65 DWORD64 rip; | |
| 66 HMODULE module; | |
| 67 }; | |
| 68 | |
| 69 int SampleThread(DWORD thread, int max_stack_size, StackTraceEntry* stack); | |
| 70 | |
| 71 static int StackTrace64(_CONTEXT* context, int stack_depth, | |
| 72 StackTraceEntry* stack_trace); | |
| 73 | |
| 74 static void GetNames(StackTraceEntry* stack_trace, int stack_depth); | |
| 75 | |
| 76 void ResolveModules(); | |
| 77 | |
| 78 void ProcessStack(StackTraceEntry* stack, int stack_depth); | |
| 79 | |
| 80 DWORD ui_thread_; | |
| 81 DWORD io_thread_; | |
| 82 | |
| 83 int ui_thread_stack_depth_; | |
| 84 StackTraceEntry ui_thread_stack_[64]; | |
| 85 | |
| 86 int io_thread_stack_depth_; | |
| 87 StackTraceEntry io_thread_stack_[64]; | |
| 88 | |
| 89 std::map<HMODULE, base::string16> modules_; | |
| 90 #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
| |
| 91 | |
| 92 static CpuProfiler* g_instance_; | |
| 93 | |
| 94 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.
| |
| 95 Map params_; | |
| 96 | |
| 97 scoped_ptr<SamplingThread> sampling_thread_; | |
| 98 PlatformThreadHandle sampling_thread_handle_; | |
| 99 }; | |
| 100 | |
| 101 } | |
|
Ilya Sherman
2015/02/03 22:12:10
nit: This line should be "} // namespace base".
Mike Wittman
2015/02/04 01:37:10
Done.
| |
| 102 | |
| 103 | |
|
Ilya Sherman
2015/02/03 22:12:09
nit: Spurious newline.
Mike Wittman
2015/02/04 01:37:10
Done.
| |
| 104 #endif // BASE_PROFILER_CPU_PROFILER_H_ | |
| OLD | NEW |