| 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 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_ | |
| OLD | NEW |