| Index: content/renderer/v8_heap_statistics_monitor.h
|
| diff --git a/content/renderer/v8_heap_statistics_monitor.h b/content/renderer/v8_heap_statistics_monitor.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..060298dd9857496dec5b591db2be396b6b3066de
|
| --- /dev/null
|
| +++ b/content/renderer/v8_heap_statistics_monitor.h
|
| @@ -0,0 +1,73 @@
|
| +// 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 CONTENT_RENDERER_V8_STATS_MONITOR_H_
|
| +#define CONTENT_RENDERER_V8_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/timer/timer.h"
|
| +#include "content/public/renderer/v8_heap_statistics_collector.h"
|
| +
|
| +namespace base {
|
| +class SingleThreadTaskRunner;
|
| +}
|
| +
|
| +namespace content {
|
| +
|
| +// 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 V8HeapStatisticsMonitor
|
| + : public base::debug::TraceLog::EnabledStateObserver {
|
| + public:
|
| + // Length of time interval between stat profiles.
|
| + static const int kSamplingIntervalMilliseconds = 2000;
|
| +
|
| + // |task_runner| must be the primary thread for the client
|
| + // process, e.g. the UI thread in a browser.
|
| + explicit V8HeapStatisticsMonitor(
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner);
|
| +
|
| + virtual ~V8HeapStatisticsMonitor();
|
| +
|
| + // base::debug::TraceLog::EnabledStateChangedObserver overrides:
|
| + virtual void OnTraceLogEnabled() OVERRIDE;
|
| + virtual void OnTraceLogDisabled() OVERRIDE;
|
| +
|
| +
|
| + bool IsMonitoring() const;
|
| + void BeginAnotherDump() { BeginDumpingHeapStats(); }
|
| +
|
| + private:
|
| + FRIEND_TEST_ALL_PREFIXES(TraceSystemHeapStatisticsMonitorTest,
|
| + V8HeapStatisticsMonitor);
|
| +
|
| + void StartProfiling();
|
| +
|
| + void StopProfiling();
|
| +
|
| + void BeginDumpingHeapStats();
|
| + void FinalizeDumpOfHeapStats(const V8HeapStatisticsCollector::Statistics&);
|
| +
|
| + bool dump_pending_;
|
| + V8HeapStatisticsCollector::Statistics last_dumped_stats_;
|
| +
|
| + // Ensures the observer starts and stops tracing on the primary thread.
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
|
| +
|
| + // Timer to schedule system profile dumps.
|
| + base::RepeatingTimer<V8HeapStatisticsMonitor> dump_timer_;
|
| +
|
| + base::WeakPtrFactory<V8HeapStatisticsMonitor> weak_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(V8HeapStatisticsMonitor);
|
| +};
|
| +
|
| +} // namespace content
|
| +
|
| +#endif // CONTENT_RENDERER_V8_STATS_MONITOR_H_
|
|
|