| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 copy | 5 import copy |
| 6 import json | 6 import json |
| 7 import os | 7 import os |
| 8 import shutil | 8 import shutil |
| 9 import subprocess | 9 import subprocess |
| 10 import tempfile | 10 import tempfile |
| 11 import unittest | 11 import unittest |
| 12 | 12 |
| 13 import loading_trace | 13 import loading_trace |
| 14 import page_track | 14 import page_track |
| 15 import sandwich_metrics as puller | 15 import sandwich_metrics as puller |
| 16 import sandwich_runner |
| 16 import request_track | 17 import request_track |
| 17 import tracing | 18 import tracing |
| 18 | 19 |
| 19 | 20 |
| 20 _BLINK_CAT = 'blink.user_timing' | 21 _BLINK_CAT = 'blink.user_timing' |
| 21 _MEM_CAT = 'disabled-by-default-memory-infra' | 22 _MEM_CAT = 'disabled-by-default-memory-infra' |
| 22 _START='requestStart' | 23 _START='requestStart' |
| 23 _LOADS='loadEventStart' | 24 _LOADS='loadEventStart' |
| 24 _LOADE='loadEventEnd' | 25 _LOADE='loadEventEnd' |
| 25 _UNLOAD='unloadEventEnd' | 26 _UNLOAD='unloadEventEnd' |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 {'pid': 123, 'ts': 4000, 'cat': _MEM_CAT, 'ph': 'v', 'name': 'foo'}, | 97 {'pid': 123, 'ts': 4000, 'cat': _MEM_CAT, 'ph': 'v', 'name': 'foo'}, |
| 97 {'pid': 123, 'ts': 5000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME}, | 98 {'pid': 123, 'ts': 5000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME}, |
| 98 {'pid': 123, 'ts': 6000, 'cat': _MEM_CAT, 'ph': 'V'}, | 99 {'pid': 123, 'ts': 6000, 'cat': _MEM_CAT, 'ph': 'V'}, |
| 99 {'pid': 672, 'ts': 7000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME}, | 100 {'pid': 672, 'ts': 7000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME}, |
| 100 {'pid': 354, 'ts': 8000, 'cat': _MEM_CAT, 'ph': 'v', 'name': 'foo'}, | 101 {'pid': 354, 'ts': 8000, 'cat': _MEM_CAT, 'ph': 'v', 'name': 'foo'}, |
| 101 {'pid': 123, 'ts': 9000, 'cat': 'whatever1', 'ph': 'v', 'name': NAME}, | 102 {'pid': 123, 'ts': 9000, 'cat': 'whatever1', 'ph': 'v', 'name': NAME}, |
| 102 {'pid': 123, 'ts': 10000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME}, | 103 {'pid': 123, 'ts': 10000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME}, |
| 103 {'pid': 354, 'ts': 11000, 'cat': 'whatever0', 'ph': 'R'}, | 104 {'pid': 354, 'ts': 11000, 'cat': 'whatever0', 'ph': 'R'}, |
| 104 {'pid': 672, 'ts': 12000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME}] | 105 {'pid': 672, 'ts': 12000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME}] |
| 105 | 106 |
| 106 self.assertTrue(_MEM_CAT in puller.CATEGORIES) | 107 self.assertTrue(_MEM_CAT in sandwich_runner.CATEGORIES) |
| 107 | 108 |
| 108 bump_events = RunHelper(TRACE_EVENTS, 123) | 109 bump_events = RunHelper(TRACE_EVENTS, 123) |
| 109 self.assertEquals(2, len(bump_events)) | 110 self.assertEquals(2, len(bump_events)) |
| 110 self.assertEquals(5, bump_events[0].start_msec) | 111 self.assertEquals(5, bump_events[0].start_msec) |
| 111 self.assertEquals(10, bump_events[1].start_msec) | 112 self.assertEquals(10, bump_events[1].start_msec) |
| 112 | 113 |
| 113 bump_events = RunHelper(TRACE_EVENTS, 354) | 114 bump_events = RunHelper(TRACE_EVENTS, 354) |
| 114 self.assertEquals(1, len(bump_events)) | 115 self.assertEquals(1, len(bump_events)) |
| 115 self.assertEquals(1, bump_events[0].start_msec) | 116 self.assertEquals(1, bump_events[0].start_msec) |
| 116 | 117 |
| 117 bump_events = RunHelper(TRACE_EVENTS, 672) | 118 bump_events = RunHelper(TRACE_EVENTS, 672) |
| 118 self.assertEquals(3, len(bump_events)) | 119 self.assertEquals(3, len(bump_events)) |
| 119 self.assertEquals(3, bump_events[0].start_msec) | 120 self.assertEquals(3, bump_events[0].start_msec) |
| 120 self.assertEquals(7, bump_events[1].start_msec) | 121 self.assertEquals(7, bump_events[1].start_msec) |
| 121 self.assertEquals(12, bump_events[2].start_msec) | 122 self.assertEquals(12, bump_events[2].start_msec) |
| 122 | 123 |
| 123 with self.assertRaises(ValueError): | 124 with self.assertRaises(ValueError): |
| 124 RunHelper(TRACE_EVENTS, 895) | 125 RunHelper(TRACE_EVENTS, 895) |
| 125 | 126 |
| 126 def testGetWebPageTrackedEvents(self): | 127 def testGetWebPageTrackedEvents(self): |
| 127 self.assertTrue(_BLINK_CAT in puller.CATEGORIES) | 128 self.assertTrue(_BLINK_CAT in sandwich_runner.CATEGORIES) |
| 128 | 129 |
| 129 trace_events = puller._GetWebPageTrackedEvents(TracingTrack([ | 130 trace_events = puller._GetWebPageTrackedEvents(TracingTrack([ |
| 130 {'ph': 'R', 'ts': 0000, 'args': {}, 'cat': 'whatever', | 131 {'ph': 'R', 'ts': 0000, 'args': {}, 'cat': 'whatever', |
| 131 'name': _START}, | 132 'name': _START}, |
| 132 {'ph': 'R', 'ts': 1000, 'args': {'frame': '0'}, 'cat': 'whatever', | 133 {'ph': 'R', 'ts': 1000, 'args': {'frame': '0'}, 'cat': 'whatever', |
| 133 'name': _LOADS}, | 134 'name': _LOADS}, |
| 134 {'ph': 'R', 'ts': 2000, 'args': {'frame': '0'}, 'cat': 'whatever', | 135 {'ph': 'R', 'ts': 2000, 'args': {'frame': '0'}, 'cat': 'whatever', |
| 135 'name': _LOADE}, | 136 'name': _LOADE}, |
| 136 {'ph': 'R', 'ts': 3000, 'args': {}, 'cat': _BLINK_CAT, | 137 {'ph': 'R', 'ts': 3000, 'args': {}, 'cat': _BLINK_CAT, |
| 137 'name': _START}, | 138 'name': _START}, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 point(230, 1.0), | 226 point(230, 1.0), |
| 226 ] | 227 ] |
| 227 with self.assertRaises(ValueError): | 228 with self.assertRaises(ValueError): |
| 228 puller.ComputeSpeedIndex(completness_record) | 229 puller.ComputeSpeedIndex(completness_record) |
| 229 | 230 |
| 230 def testCommandLine(self): | 231 def testCommandLine(self): |
| 231 tmp_dir = tempfile.mkdtemp() | 232 tmp_dir = tempfile.mkdtemp() |
| 232 for dirname in ['1', '2', 'whatever']: | 233 for dirname in ['1', '2', 'whatever']: |
| 233 os.mkdir(os.path.join(tmp_dir, dirname)) | 234 os.mkdir(os.path.join(tmp_dir, dirname)) |
| 234 LoadingTrace(_MINIMALIST_TRACE_EVENTS).ToJsonFile( | 235 LoadingTrace(_MINIMALIST_TRACE_EVENTS).ToJsonFile( |
| 235 os.path.join(tmp_dir, dirname, 'trace.json')) | 236 os.path.join(tmp_dir, dirname, sandwich_runner.TRACE_FILENAME)) |
| 236 | 237 |
| 237 process = subprocess.Popen(['python', puller.__file__, tmp_dir]) | 238 process = subprocess.Popen(['python', puller.__file__, tmp_dir]) |
| 238 process.wait() | 239 process.wait() |
| 239 shutil.rmtree(tmp_dir) | 240 shutil.rmtree(tmp_dir) |
| 240 | 241 |
| 241 self.assertEquals(0, process.returncode) | 242 self.assertEquals(0, process.returncode) |
| 242 | 243 |
| 243 | 244 |
| 244 if __name__ == '__main__': | 245 if __name__ == '__main__': |
| 245 unittest.main() | 246 unittest.main() |
| OLD | NEW |