Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tools/android/loading/sandwich_metrics_unittest.py

Issue 1925803003: sandwich: Make speed-index and memory measurement optional from run-all (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses Egor's nit Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/android/loading/sandwich_metrics.py ('k') | tools/android/loading/sandwich_runner.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 sandwich_runner
17 import request_track 17 import request_track
18 import tracing 18 import tracing
19 19
20 20
21 _BLINK_CAT = 'blink.user_timing' 21 _BLINK_CAT = 'blink.user_timing'
22 _MEM_CAT = 'disabled-by-default-memory-infra' 22 _MEM_CAT = sandwich_runner.MEMORY_DUMP_CATEGORY
23 _START='requestStart' 23 _START='requestStart'
24 _LOADS='loadEventStart' 24 _LOADS='loadEventStart'
25 _LOADE='loadEventEnd' 25 _LOADE='loadEventEnd'
26 _UNLOAD='unloadEventEnd' 26 _UNLOAD='unloadEventEnd'
27 27
28 _MINIMALIST_TRACE_EVENTS = [ 28 _MINIMALIST_TRACE_EVENTS = [
29 {'ph': 'R', 'cat': _BLINK_CAT, 'name': _UNLOAD, 'ts': 10000, 29 {'ph': 'R', 'cat': _BLINK_CAT, 'name': _UNLOAD, 'ts': 10000,
30 'args': {'frame': '0'}}, 30 'args': {'frame': '0'}},
31 {'ph': 'R', 'cat': _BLINK_CAT, 'name': _START, 'ts': 20000, 31 {'ph': 'R', 'cat': _BLINK_CAT, 'name': _START, 'ts': 20000,
32 'args': {}}, 32 'args': {}},
33 {'cat': _MEM_CAT, 'name': 'periodic_interval', 'pid': 1, 'ph': 'v', 33 {'cat': _MEM_CAT, 'name': 'periodic_interval', 'pid': 1, 'ph': 'v',
34 'ts': 1, 'args': {'dumps': {'allocators': {'malloc': {'attrs': {'size':{ 34 'ts': 1, 'args': {'dumps': {'allocators': {'malloc': {'attrs': {'size':{
35 'units': 'bytes', 'value': '1af2', }}}}}}}, 35 'units': 'bytes', 'value': '1af2', }}}}}}},
36 {'ph': 'R', 'cat': _BLINK_CAT, 'name': _LOADS, 'ts': 35000, 36 {'ph': 'R', 'cat': _BLINK_CAT, 'name': _LOADS, 'ts': 35000,
37 'args': {'frame': '0'}}, 37 'args': {'frame': '0'}},
38 {'ph': 'R', 'cat': _BLINK_CAT, 'name': _LOADE, 'ts': 40000, 38 {'ph': 'R', 'cat': _BLINK_CAT, 'name': _LOADE, 'ts': 40000,
39 'args': {'frame': '0'}}, 39 'args': {'frame': '0'}},
40 {'cat': _MEM_CAT, 'name': 'periodic_interval', 'pid': 1, 'ph': 'v', 40 {'cat': _MEM_CAT, 'name': 'periodic_interval', 'pid': 1, 'ph': 'v',
41 'ts': 1, 'args': {'dumps': {'allocators': {'malloc': {'attrs': {'size':{ 41 'ts': 1, 'args': {'dumps': {'allocators': {'malloc': {'attrs': {'size':{
42 'units': 'bytes', 'value': 'd704', }}}}}}}, 42 'units': 'bytes', 'value': 'd704', }}}}}}},
43 {'ph': 'M', 'cat': '__metadata', 'pid': 1, 'name': 'process_name', 'ts': 1, 43 {'ph': 'M', 'cat': '__metadata', 'pid': 1, 'name': 'process_name', 'ts': 1,
44 'args': {'name': 'Browser'}}] 44 'args': {'name': 'Browser'}}]
45 45
46 46
47 def TracingTrack(events): 47 def TracingTrack(events):
48 return tracing.TracingTrack.FromJsonDict({ 48 return tracing.TracingTrack.FromJsonDict({
49 'events': events, 49 'events': events,
50 'categories': (tracing.INITIAL_CATEGORIES + 50 'categories': (tracing.INITIAL_CATEGORIES +
51 sandwich_runner.ADDITIONAL_CATEGORIES)}) 51 (sandwich_runner.MEMORY_DUMP_CATEGORY,))})
52 52
53 53
54 def LoadingTrace(events): 54 def LoadingTrace(events):
55 return loading_trace.LoadingTrace('http://a.com/', {}, 55 return loading_trace.LoadingTrace('http://a.com/', {},
56 page_track.PageTrack(None), 56 page_track.PageTrack(None),
57 request_track.RequestTrack(None), 57 request_track.RequestTrack(None),
58 TracingTrack(events)) 58 TracingTrack(events))
59 59
60 60
61 class PageTrackTest(unittest.TestCase): 61 class PageTrackTest(unittest.TestCase):
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 {'pid': 123, 'ts': 4000, 'cat': _MEM_CAT, 'ph': 'v', 'name': 'foo'}, 100 {'pid': 123, 'ts': 4000, 'cat': _MEM_CAT, 'ph': 'v', 'name': 'foo'},
101 {'pid': 123, 'ts': 5000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME}, 101 {'pid': 123, 'ts': 5000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME},
102 {'pid': 123, 'ts': 6000, 'cat': _MEM_CAT, 'ph': 'V'}, 102 {'pid': 123, 'ts': 6000, 'cat': _MEM_CAT, 'ph': 'V'},
103 {'pid': 672, 'ts': 7000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME}, 103 {'pid': 672, 'ts': 7000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME},
104 {'pid': 354, 'ts': 8000, 'cat': _MEM_CAT, 'ph': 'v', 'name': 'foo'}, 104 {'pid': 354, 'ts': 8000, 'cat': _MEM_CAT, 'ph': 'v', 'name': 'foo'},
105 {'pid': 123, 'ts': 9000, 'cat': 'whatever1', 'ph': 'v', 'name': NAME}, 105 {'pid': 123, 'ts': 9000, 'cat': 'whatever1', 'ph': 'v', 'name': NAME},
106 {'pid': 123, 'ts': 10000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME}, 106 {'pid': 123, 'ts': 10000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME},
107 {'pid': 354, 'ts': 11000, 'cat': 'whatever0', 'ph': 'R'}, 107 {'pid': 354, 'ts': 11000, 'cat': 'whatever0', 'ph': 'R'},
108 {'pid': 672, 'ts': 12000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME}] 108 {'pid': 672, 'ts': 12000, 'cat': _MEM_CAT, 'ph': 'v', 'name': NAME}]
109 109
110 self.assertTrue(_MEM_CAT in sandwich_runner.ADDITIONAL_CATEGORIES)
111
112 bump_events = RunHelper(TRACE_EVENTS, 123) 110 bump_events = RunHelper(TRACE_EVENTS, 123)
113 self.assertEquals(2, len(bump_events)) 111 self.assertEquals(2, len(bump_events))
114 self.assertEquals(5, bump_events[0].start_msec) 112 self.assertEquals(5, bump_events[0].start_msec)
115 self.assertEquals(10, bump_events[1].start_msec) 113 self.assertEquals(10, bump_events[1].start_msec)
116 114
117 bump_events = RunHelper(TRACE_EVENTS, 354) 115 bump_events = RunHelper(TRACE_EVENTS, 354)
118 self.assertEquals(1, len(bump_events)) 116 self.assertEquals(1, len(bump_events))
119 self.assertEquals(1, bump_events[0].start_msec) 117 self.assertEquals(1, bump_events[0].start_msec)
120 118
121 bump_events = RunHelper(TRACE_EVENTS, 672) 119 bump_events = RunHelper(TRACE_EVENTS, 672)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 {'ph': 'R', 'ts': 24000, 'args': {'frame': '0'}, 'cat': _BLINK_CAT, 178 {'ph': 'R', 'ts': 24000, 'args': {'frame': '0'}, 'cat': _BLINK_CAT,
181 'name': _LOADS}, 179 'name': _LOADS},
182 {'ph': 'R', 'ts': 25000, 'args': {'frame': '0'}, 'cat': _BLINK_CAT, 180 {'ph': 'R', 'ts': 25000, 'args': {'frame': '0'}, 'cat': _BLINK_CAT,
183 'name': _LOADE}])) 181 'name': _LOADE}]))
184 182
185 self.assertEquals(3, len(trace_events)) 183 self.assertEquals(3, len(trace_events))
186 self.assertEquals(14, trace_events['requestStart'].start_msec) 184 self.assertEquals(14, trace_events['requestStart'].start_msec)
187 self.assertEquals(17, trace_events['loadEventStart'].start_msec) 185 self.assertEquals(17, trace_events['loadEventStart'].start_msec)
188 self.assertEquals(19, trace_events['loadEventEnd'].start_msec) 186 self.assertEquals(19, trace_events['loadEventEnd'].start_msec)
189 187
190 def testPullMetricsFromLoadingTrace(self): 188 def testExtractDefaultMetrics(self):
191 metrics = puller._ExtractMetricsFromLoadingTrace(LoadingTrace( 189 metrics = puller._ExtractDefaultMetrics(LoadingTrace(
192 _MINIMALIST_TRACE_EVENTS)) 190 _MINIMALIST_TRACE_EVENTS))
193 self.assertEquals(4, len(metrics)) 191 self.assertEquals(2, len(metrics))
194 self.assertEquals(20, metrics['total_load']) 192 self.assertEquals(20, metrics['total_load'])
195 self.assertEquals(5, metrics['js_onload_event']) 193 self.assertEquals(5, metrics['js_onload_event'])
194
195 def testExtractMemoryMetrics(self):
196 metrics = puller._ExtractMemoryMetrics(LoadingTrace(
197 _MINIMALIST_TRACE_EVENTS))
198 self.assertEquals(2, len(metrics))
196 self.assertEquals(30971, metrics['browser_malloc_avg']) 199 self.assertEquals(30971, metrics['browser_malloc_avg'])
197 self.assertEquals(55044, metrics['browser_malloc_max']) 200 self.assertEquals(55044, metrics['browser_malloc_max'])
198 201
199 def testComputeSpeedIndex(self): 202 def testComputeSpeedIndex(self):
200 def point(time, frame_completeness): 203 def point(time, frame_completeness):
201 return puller.CompletenessPoint(time=time, 204 return puller.CompletenessPoint(time=time,
202 frame_completeness=frame_completeness) 205 frame_completeness=frame_completeness)
203 completness_record = [ 206 completness_record = [
204 point(0, 0.0), 207 point(0, 0.0),
205 point(120, 0.4), 208 point(120, 0.4),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 241
239 process = subprocess.Popen(['python', puller.__file__, tmp_dir]) 242 process = subprocess.Popen(['python', puller.__file__, tmp_dir])
240 process.wait() 243 process.wait()
241 shutil.rmtree(tmp_dir) 244 shutil.rmtree(tmp_dir)
242 245
243 self.assertEquals(0, process.returncode) 246 self.assertEquals(0, process.returncode)
244 247
245 248
246 if __name__ == '__main__': 249 if __name__ == '__main__':
247 unittest.main() 250 unittest.main()
OLDNEW
« no previous file with comments | « tools/android/loading/sandwich_metrics.py ('k') | tools/android/loading/sandwich_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698