Chromium Code Reviews| Index: base/debug/trace_event_system_stats_monitor.h |
| diff --git a/base/debug/trace_event_system_stats_monitor.h b/base/debug/trace_event_system_stats_monitor.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a30e9391c3210913b135df7ed54bfe84aa91dcbb |
| --- /dev/null |
| +++ b/base/debug/trace_event_system_stats_monitor.h |
| @@ -0,0 +1,77 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BASE_DEBUG_TRACE_EVENT_SYSTEM_STATS_MONITOR_H_ |
| +#define BASE_DEBUG_TRACE_EVENT_SYSTEM_STATS_MONITOR_H_ |
| + |
| +#include "base/base_export.h" |
| +#include "base/debug/trace_event_impl.h" |
| +#include "base/gtest_prod_util.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/process/process_metrics.h" |
| +#include "base/timer/timer.h" |
| + |
| +namespace base { |
| + |
| +class MessageLoopProxy; |
| + |
| +namespace debug { |
| + |
| +// Watches for chrome://tracing to be enabled or disabled. When tracing is |
| +// enabled, also enables system events profiling. This class is the preferred |
| +// way to turn system tracing on and off. |
| +class BASE_EXPORT TraceEventSystemStatsMonitor |
| + : public TraceLog::EnabledStateObserver { |
| + public: |
| + // Length of time interval between stat profiles. |
| + 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.
|
| + |
| + // |message_loop_proxy| must be a proxy to the primary thread for the client |
| + // process, e.g. the UI thread in a browser. |
| + explicit TraceEventSystemStatsMonitor( |
| + scoped_refptr<MessageLoopProxy> message_loop_proxy); |
| + |
| + virtual ~TraceEventSystemStatsMonitor(); |
| + |
| + // base::debug::TraceLog::EnabledStateChangedObserver overrides: |
| + virtual void OnTraceLogEnabled() OVERRIDE; |
| + virtual void OnTraceLogDisabled() OVERRIDE; |
| + |
| + // Starts system profiling. |
| + 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.
|
| + |
| + // Retrieves system profiling. |
| + void DumpSystemStats(); |
| + |
| + // Ends system profiling. |
| + void StopProfiling(); |
| + |
| + private: |
| + FRIEND_TEST_ALL_PREFIXES(TraceSystemStatsMonitorTest, |
| + TraceEventSystemStatsMonitor); |
| + |
| + bool IsTimerRunningForTest() const; |
| + |
| + // Ensures the observer starts and stops tracing on the primary thread. |
| + scoped_refptr<MessageLoopProxy> message_loop_proxy_; |
| + |
| + // Timer to schedule system profile dumps. |
| + RepeatingTimer<TraceEventSystemStatsMonitor> dump_timer_; |
| + |
| + WeakPtrFactory<TraceEventSystemStatsMonitor> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TraceEventSystemStatsMonitor); |
| +}; |
| + |
| +// Converts system memory profiling stats in |input| to |
| +// trace event compatible JSON and appends to |output|. Visible for testing. |
| +BASE_EXPORT void AppendSystemProfileAsTraceFormat(const SystemMetrics& |
| + system_stats, |
| + std::string* output); |
| + |
| +} // namespace debug |
| +} // namespace base |
| + |
| +#endif // BASE_DEBUG_TRACE_EVENT_SYSTEM_STATS_MONITOR_H_ |