Index: tools/perf/metrics/v8_object_stats.py |
diff --git a/tools/perf/metrics/v8_object_stats.py b/tools/perf/metrics/v8_object_stats.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..db22257ced6f42593b5d56d54ee96dcdf8bf82f2 |
--- /dev/null |
+++ b/tools/perf/metrics/v8_object_stats.py |
@@ -0,0 +1,43 @@ |
+# 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. |
+ |
+from metrics import Metric |
+from metrics import stats_table_util |
+ |
+ |
+class V8ObjectStatsMetric(Metric): |
+ """V8ObjectStatsMetric gathers statistics on the size of types in the V8 heap. |
+ |
+ It does this by enabling the --track_gc_object_stats flag on V8 and reading |
+ these statistics from the StatsTableMetric. |
+ """ |
+ |
+ def __init__(self): |
+ super(V8ObjectStatsMetric, self).__init__() |
+ self._stats_table = None |
+ self._stats_table = None |
+ |
+ @classmethod |
+ def CustomizeBrowserOptions(cls, options): |
+ options.AppendExtraBrowserArg('--enable-stats-table') |
+ options.AppendExtraBrowserArg( |
+ '--js-flags=--track_gc_object_stats --expose_gc') |
+ |
+ def Start(self, page, tab): |
+ """Do Nothing.""" |
+ |
+ def Stop(self, page, tab): |
+ """Get the values in the stats table after the page is loaded.""" |
+ # Trigger GC to ensure stats are checkpointed. |
+ tab.EvaluateJavaScript('window.gc()') |
+ self._stats_table = stats_table_util.GetStatsTable(tab) |
+ |
+ def AddResults(self, tab, results): |
+ """Add results for this page to the results object.""" |
+ assert self._stats_table, 'Must call Stop() first' |
+ for stat_name in self._stats_table: |
+ if ("V8:OsMemoryAllocated" in stat_name or |
+ "V8:SizeOf_" in stat_name or |
+ "V8:Memory" in stat_name): |
+ results.Add(stat_name, 'kb', self._stats_table[stat_name] / 1024.0) |