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 #ifndef BASE_PROFILER_CPU_PROFILER_H_ | |
6 #define BASE_PROFILER_CPU_PROFILER_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/base_export.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/strings/string16.h" | |
13 #include "base/synchronization/waitable_event.h" | |
14 #include "base/timer/timer.h" | |
15 | |
16 #if defined(OS_WIN) | |
17 struct _CONTEXT; | |
18 #endif | |
19 | |
20 namespace base { | |
21 | |
22 class SamplingThread : public PlatformThread::Delegate { | |
23 public: | |
24 SamplingThread(); | |
25 ~SamplingThread() override; | |
26 | |
27 // Implementation of PlatformThread::Delegate: | |
28 void ThreadMain() override; | |
29 | |
30 void Stop(); | |
31 | |
32 void GetSamples(); | |
33 | |
34 private: | |
35 bool thread_running_; | |
36 | |
37 base::WaitableEvent waitable_event_; | |
38 | |
39 DISALLOW_COPY_AND_ASSIGN(SamplingThread); | |
40 }; | |
41 | |
42 #if defined(OS_WIN) | |
43 struct StackTraceEntry { | |
44 DWORD64 rsp; | |
45 DWORD64 rip; | |
46 HMODULE module; | |
47 }; | |
48 #endif | |
49 | |
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.
| |
50 class BASE_EXPORT CpuProfiler { | |
51 public: | |
52 static void Initialize(const std::map<std::string, std::string>* params); | |
53 static CpuProfiler* GetInstance(); | |
54 static bool IsPlatformSupported(); | |
55 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
| |
56 | |
57 std::string GetStringParam(const std::string& key); | |
58 int GetIntParam(const std::string& key); | |
59 int64 GetInt64Param(const std::string& key); | |
60 | |
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.
| |
61 void OnTimer(); | |
62 | |
63 private: | |
64 CpuProfiler(); | |
65 ~CpuProfiler(); | |
66 | |
67 void SetParams(const std::map<std::string, std::string>& params); | |
68 | |
69 void GetThreadIds(); | |
70 | |
71 #if defined(OS_WIN) | |
72 void ProcessStack(StackTraceEntry* stack, int stack_depth); | |
73 | |
74 HANDLE main_thread_; | |
75 int main_thread_stack_depth_; | |
76 StackTraceEntry main_thread_stack_[64]; | |
77 | |
78 std::map<HMODULE, base::string16> modules_; | |
79 #endif | |
80 | |
81 static CpuProfiler* g_instance_; | |
82 | |
83 std::map<std::string, std::string> params_; | |
84 | |
85 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.
| |
86 PlatformThreadHandle sampling_thread_handle_; | |
87 | |
88 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); | |
89 }; | |
90 | |
91 } // namespace base | |
92 | |
93 #endif // BASE_PROFILER_CPU_PROFILER_H_ | |
OLD | NEW |