| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import collections | 5 import collections |
| 6 import unittest | 6 import unittest |
| 7 | 7 |
| 8 from telemetry.internal.results import page_test_results | 8 from telemetry.internal.results import page_test_results |
| 9 from telemetry.page import page | 9 from telemetry.page import page |
| 10 import mock | 10 import mock |
| 11 from telemetry.timeline import memory_dump_event | 11 from telemetry.timeline import memory_dump_event |
| 12 from telemetry.web_perf.metrics import memory_timeline | 12 from telemetry.web_perf.metrics import memory_timeline |
| 13 from telemetry.web_perf import timeline_interaction_record | 13 from telemetry.web_perf import timeline_interaction_record |
| 14 | 14 |
| 15 | 15 |
| 16 def MockProcessDumpEvent(dump_id, name, start, memory_usage): | 16 def MockProcessDumpEvent(dump_id, name, start, memory_usage): |
| 17 process_dump = mock.Mock() | 17 process_dump = mock.Mock() |
| 18 process_dump.dump_id = dump_id | 18 process_dump.dump_id = dump_id |
| 19 process_dump.process_name = name | 19 process_dump.process_name = name |
| 20 process_dump.start = start | 20 process_dump.start = start |
| 21 process_dump.end = start |
| 21 if memory_usage is None: | 22 if memory_usage is None: |
| 22 memory_usage = {} | 23 memory_usage = {} |
| 23 elif not isinstance(memory_usage, dict): | 24 elif not isinstance(memory_usage, dict): |
| 24 memory_usage = dict.fromkeys(memory_timeline.DEFAULT_METRICS, memory_usage) | 25 memory_usage = dict.fromkeys(memory_timeline.DEFAULT_METRICS, memory_usage) |
| 25 process_dump.has_mmaps = any(metric in memory_usage for metric | 26 process_dump.has_mmaps = any(metric in memory_usage for metric |
| 26 in memory_timeline.DEFAULT_METRICS) | 27 in memory_timeline.DEFAULT_METRICS) |
| 27 process_dump.GetMemoryUsage = mock.Mock(return_value=memory_usage) | 28 process_dump.GetMemoryUsage = mock.Mock(return_value=memory_usage) |
| 28 return process_dump | 29 return process_dump |
| 29 | 30 |
| 30 | 31 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 for metric, value in stats1.iteritems()) | 138 for metric, value in stats1.iteritems()) |
| 138 expected.update(('%s_gpu_process' % metric, [value]) | 139 expected.update(('%s_gpu_process' % metric, [value]) |
| 139 for metric, value in stats2.iteritems()) | 140 for metric, value in stats2.iteritems()) |
| 140 expected.update(('%s_total' % metric, [total]) for metric in metrics) | 141 expected.update(('%s_total' % metric, [total]) for metric in metrics) |
| 141 | 142 |
| 142 model = MockTimelineModel([ | 143 model = MockTimelineModel([ |
| 143 MockProcessDumpEvent('dump1', 'browser', 2, stats1), | 144 MockProcessDumpEvent('dump1', 'browser', 2, stats1), |
| 144 MockProcessDumpEvent('dump1', 'GPU Process', 5, stats2)]) | 145 MockProcessDumpEvent('dump1', 'GPU Process', 5, stats2)]) |
| 145 interactions = [TestInteraction(1, 10)] | 146 interactions = [TestInteraction(1, 10)] |
| 146 self.assertEquals(expected, self.getResultsDict(model, interactions)) | 147 self.assertEquals(expected, self.getResultsDict(model, interactions)) |
| OLD | NEW |