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 | |
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.
| |
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_; | |
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.
| |
39 }; | |
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_; | |
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.
| |
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 | |
91 | |
92 static CpuProfiler* g_instance_; | |
93 | |
94 typedef std::map<std::string, std::string> Map; | |
95 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.
| |
96 | |
97 scoped_ptr<SamplingThread> sampling_thread_; | |
98 PlatformThreadHandle sampling_thread_handle_; | |
99 }; | |
100 | |
101 } | |
102 | |
103 | |
104 #endif // BASE_PROFILER_CPU_PROFILER_H_ | |
OLD | NEW |