Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1016)

Side by Side Diff: base/profiler/cpu_profiler.h

Issue 888923004: Temporary commit to evaluate perf impact of prototype CPU profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: address comments Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/base.gypi ('k') | base/profiler/cpu_profiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 namespace base {
17
18 #if defined(OS_WIN)
19 struct StackTraceEntry {
20 DWORD64 rsp;
21 DWORD64 rip;
22 HMODULE module;
23 };
24 #endif
25
26 // CpuProfiler is a prototype of a technique that periodically stops the main
27 // thread to samples its stack. It does not do anything useful with the
28 // collected information yet; this implementation is for the purposes of
29 // determining perf impact of the profiler itself.
30 //
31 // Currently, this is intended to sample the main thread. It should be allocated
32 // on that thread, then Initialize should be called to start the sampling, and
33 // Stop called to stop the sampling.
34 class BASE_EXPORT CpuProfiler {
35 public:
36 CpuProfiler();
37 ~CpuProfiler();
38
39 void Initialize(const std::map<std::string, std::string>* params);
40 void Stop();
41
42 std::string GetStringParam(const std::string& key) const;
43 int GetIntParam(const std::string& key) const;
44 int64 GetInt64Param(const std::string& key) const;
45
46 private:
47 class SamplingThread;
48 struct SamplingThreadDeleter {
49 void operator() (SamplingThread* thread) const;
50 };
51
52 static bool IsPlatformSupported();
53
54 void SetParams(const std::map<std::string, std::string>& params);
55
56 void OnTimer();
57
58 #if defined(OS_WIN)
59 void ProcessStack(StackTraceEntry* stack, int stack_depth);
60
61 HANDLE main_thread_;
62 int main_thread_stack_depth_;
63 StackTraceEntry main_thread_stack_[64];
64
65 std::map<HMODULE, base::string16> modules_;
66 #endif
67
68 std::map<std::string, std::string> params_;
69
70 scoped_ptr<SamplingThread, SamplingThreadDeleter> sampling_thread_;
71 PlatformThreadHandle sampling_thread_handle_;
72
73 DISALLOW_COPY_AND_ASSIGN(CpuProfiler);
74 };
75
76 } // namespace base
77
78 #endif // BASE_PROFILER_CPU_PROFILER_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/profiler/cpu_profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698