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

Unified Diff: content/renderer/v8_heap_statistics_monitor.h

Issue 196103006: Add V8 heap statistics in a time-line manner in tracing. (Closed) Base URL: /home/dmikurube/repos/chromium@work-sai-json
Patch Set: rebased Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
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_

Powered by Google App Engine
This is Rietveld 408576698