Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 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_DEBUG_TRACE_EVENT_SYSTEM_STATS_MONITOR_H_ | |
| 6 #define BASE_DEBUG_TRACE_EVENT_SYSTEM_STATS_MONITOR_H_ | |
| 7 | |
| 8 #include "base/base_export.h" | |
| 9 #include "base/debug/trace_event_impl.h" | |
| 10 #include "base/gtest_prod_util.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/process/process_metrics.h" | |
| 14 #include "base/timer/timer.h" | |
| 15 | |
| 16 namespace base { | |
| 17 | |
| 18 class MessageLoopProxy; | |
| 19 | |
| 20 namespace debug { | |
| 21 | |
| 22 // Watches for chrome://tracing to be enabled or disabled. When tracing is | |
| 23 // enabled, also enables system events profiling. This class is the preferred | |
| 24 // way to turn system tracing on and off. | |
| 25 class BASE_EXPORT TraceEventSystemStatsMonitor | |
| 26 : public TraceLog::EnabledStateObserver { | |
| 27 public: | |
| 28 // Length of time interval between stat profiles. | |
| 29 static const int kSystemStatsMonitorIntervalSeconds = 2; | |
|
nduca
2013/09/07 07:19:20
I'd suggest making this unit in milliseconds, e.g.
jwmak
2013/09/08 09:26:05
Done.
| |
| 30 | |
| 31 // |message_loop_proxy| must be a proxy to the primary thread for the client | |
| 32 // process, e.g. the UI thread in a browser. | |
| 33 explicit TraceEventSystemStatsMonitor( | |
| 34 scoped_refptr<MessageLoopProxy> message_loop_proxy); | |
| 35 | |
| 36 virtual ~TraceEventSystemStatsMonitor(); | |
| 37 | |
| 38 // base::debug::TraceLog::EnabledStateChangedObserver overrides: | |
| 39 virtual void OnTraceLogEnabled() OVERRIDE; | |
| 40 virtual void OnTraceLogDisabled() OVERRIDE; | |
| 41 | |
| 42 // Starts system profiling. | |
| 43 void StartProfiling(); | |
|
nduca
2013/09/07 07:19:20
this doesn't have to be public --- start/stop and
jwmak
2013/09/08 09:26:05
Done.
| |
| 44 | |
| 45 // Retrieves system profiling. | |
| 46 void DumpSystemStats(); | |
| 47 | |
| 48 // Ends system profiling. | |
| 49 void StopProfiling(); | |
| 50 | |
| 51 private: | |
| 52 FRIEND_TEST_ALL_PREFIXES(TraceSystemStatsMonitorTest, | |
| 53 TraceEventSystemStatsMonitor); | |
| 54 | |
| 55 bool IsTimerRunningForTest() const; | |
| 56 | |
| 57 // Ensures the observer starts and stops tracing on the primary thread. | |
| 58 scoped_refptr<MessageLoopProxy> message_loop_proxy_; | |
| 59 | |
| 60 // Timer to schedule system profile dumps. | |
| 61 RepeatingTimer<TraceEventSystemStatsMonitor> dump_timer_; | |
| 62 | |
| 63 WeakPtrFactory<TraceEventSystemStatsMonitor> weak_factory_; | |
| 64 | |
| 65 DISALLOW_COPY_AND_ASSIGN(TraceEventSystemStatsMonitor); | |
| 66 }; | |
| 67 | |
| 68 // Converts system memory profiling stats in |input| to | |
| 69 // trace event compatible JSON and appends to |output|. Visible for testing. | |
| 70 BASE_EXPORT void AppendSystemProfileAsTraceFormat(const SystemMetrics& | |
| 71 system_stats, | |
| 72 std::string* output); | |
| 73 | |
| 74 } // namespace debug | |
| 75 } // namespace base | |
| 76 | |
| 77 #endif // BASE_DEBUG_TRACE_EVENT_SYSTEM_STATS_MONITOR_H_ | |
| OLD | NEW |