Index: tools/perf/measurements/blink_partition_alloc.py |
diff --git a/tools/perf/measurements/blink_partition_alloc.py b/tools/perf/measurements/blink_partition_alloc.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..68701a5bf1d912d0a27feb6eb985db143fdb5a6d |
--- /dev/null |
+++ b/tools/perf/measurements/blink_partition_alloc.py |
@@ -0,0 +1,90 @@ |
+# Copyright 2015 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. |
+ |
+# TODO(bashi): DO-NOT-FOR-COMMIT. Just for local measurements. |
+ |
+import collections |
+import logging |
+ |
+from telemetry.page import action_runner |
+from telemetry.page import page_test |
+from telemetry.timeline import tracing_category_filter |
+from telemetry.timeline import tracing_options |
+from telemetry.timeline.model import TimelineModel |
+from telemetry.value import scalar |
+ |
+ |
+class BlinkPartitionAlloc(page_test.PageTest): |
+ def __init__(self): |
+ super(BlinkPartitionAlloc, self).__init__() |
+ |
+ def WillNavigateToPage(self, page, tab): |
+ category_filter = tracing_category_filter.TracingCategoryFilter( |
+ 'disabled-by-default-memory-infra') |
+ options = tracing_options.TracingOptions() |
+ options.enable_chrome_trace = True |
+ tab.browser.platform.tracing_controller.Start(options, category_filter, |
+ 10) |
+ def CustomizeBrowserOptions(self, options): |
+ options.AppendExtraBrowserArgs(['--no-sandbox']) |
+ |
+ def DidNavigateToPage(self, page, tab): |
+ runner = action_runner.ActionRunner(tab) |
+ runner.Wait(10) |
+ |
+ def ValidateAndMeasurePage(self, page, tab, results): |
+ timeline_data = tab.browser.platform.tracing_controller.Stop() |
+ timeline_model = TimelineModel(timeline_data) |
+ renderer_process = timeline_model.GetRendererProcessFromTabId(tab.id) |
+ stats = self._GetPerPartitionStats(timeline_model, renderer_process.pid) |
+ self._AddResults(stats, results) |
+ |
+ def CleanUpAfterPage(self, page, tab): |
+ if tab.browser.platform.tracing_controller.is_tracing_running: |
+ tab.browser.platform.tracing_controller.Stop() |
+ |
+ def _FindLatestRendererDump(self, timeline_model, pid): |
+ """Returns the latest ProcessMemoryDumpEvent which is associated with |
+ the renderer process and its |has_mmaps| is true. |
+ """ |
+ latest = None |
+ for memory_event in timeline_model.IterGlobalMemoryDumps(): |
+ renderer_events = filter(lambda event: event.process.pid == pid, |
+ memory_event._process_dumps) |
+ if len(renderer_events) == 0: |
+ continue |
+ assert(len(renderer_events) == 1) |
+ current = renderer_events[0] |
+ if current.has_mmaps and (not latest or latest.start < current.start): |
+ latest = current |
+ assert(latest != None) |
+ return latest |
+ |
+ def _GetPerPartitionStats(self, timeline_model, pid): |
+ latest = self._FindLatestRendererDump(timeline_model, pid) |
+ stats = collections.defaultdict(int) |
+ allocators = latest._event['args']['dumps']['allocators'] |
+ for allocator_name, value in allocators.iteritems(): |
+ name_parts = allocator_name.split('/') |
+ if name_parts[0] == 'partition_alloc': |
+ if name_parts[-1] != 'allocated_objects': |
+ # We don't count 'allocated_objects' since the outer includes the |
+ # value. |
+ continue |
+ partition = name_parts[2] |
+ stats[partition] += int(value['attrs']['size']['value'], 16) |
+ return stats |
+ |
+ def _AddResults(self, stats, results): |
+ total = 0.0 |
+ for category, value in stats.iteritems(): |
+ total += value |
+ results.AddValue(scalar.ScalarValue( |
+ results.current_page, category, 'MiB', |
+ float(value) / 1024**2, |
+ description=category)) |
+ results.AddValue(scalar.ScalarValue( |
+ results.current_page, 'total', 'MiB', |
+ float(total) / 1024**2, |
+ description='total')) |