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 from metrics import Metric |
| 6 from metrics import stats_table_util |
| 7 |
| 8 |
| 9 class V8ObjectStatsMetric(Metric): |
| 10 """V8ObjectStatsMetric gathers statistics on the size of types in the V8 heap. |
| 11 |
| 12 It does this by enabling the --track_gc_object_stats flag on V8 and reading |
| 13 these statistics from the StatsTableMetric. |
| 14 """ |
| 15 |
| 16 def __init__(self): |
| 17 super(V8ObjectStatsMetric, self).__init__() |
| 18 self._stats_table = None |
| 19 self._stats_table = None |
| 20 |
| 21 @classmethod |
| 22 def CustomizeBrowserOptions(cls, options): |
| 23 options.AppendExtraBrowserArg('--enable-stats-table') |
| 24 options.AppendExtraBrowserArg( |
| 25 '--js-flags=--track_gc_object_stats --expose_gc') |
| 26 |
| 27 def Start(self, page, tab): |
| 28 """Do Nothing.""" |
| 29 |
| 30 def Stop(self, page, tab): |
| 31 """Get the values in the stats table after the page is loaded.""" |
| 32 # Trigger GC to ensure stats are checkpointed. |
| 33 tab.EvaluateJavaScript('window.gc()') |
| 34 self._stats_table = stats_table_util.GetStatsTable(tab) |
| 35 |
| 36 def AddResults(self, tab, results): |
| 37 """Add results for this page to the results object.""" |
| 38 assert self._stats_table, 'Must call Stop() first' |
| 39 for stat_name in self._stats_table: |
| 40 if ("V8:OsMemoryAllocated" in stat_name or |
| 41 "V8:SizeOf_" in stat_name or |
| 42 "V8:Memory" in stat_name): |
| 43 results.Add(stat_name, 'kb', self._stats_table[stat_name] / 1024.0) |
OLD | NEW |