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

Side by Side Diff: tools/perf/contrib/cros_benchmarks/cros_utils.py

Issue 2890333002: Tab Switching Benchmark for ChromeOS (Closed)
Patch Set: Tab Switching Benchmark for ChromeOS Created 3 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
OLDNEW
(Empty)
1 # Copyright 2017 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 import json
6 import logging
7 import os
8 import subprocess
9 import time
10
11 import py_utils
12
13 from telemetry.core import exceptions
14 from telemetry.value import histogram_util
15
16 def FindKeyboardDevice(dut_ip):
cywang 2017/05/22 09:04:04 Try to use an emulated keyboard instead(e.g. use e
vovoy 2017/05/23 02:26:10 Done. Using keyboard emulator to send key events.
17 """Find the device that supports events EV=120013.
18 Example /proc/bus/input/devices output for keyboard:
19 I: Bus=0011 Vendor=0001 Product=0001 Version=ab83
20 N: Name="AT Translated Set 2 keyboard"
21 P: Phys=isa0060/serio0/input0
22 S: Sysfs=/devices/platform/i8042/serio0/input/input3
23 U: Uniq=
24 H: Handlers=sysrq event3
25 B: PROP=0
26 B: EV=120013
27 B: KEY=402000000 3803078f800d001 feffffdfffefffff fffffffffffffffe
28 B: MSC=10
29 B: LED=7
30 """
31 cmd = ['ssh', 'root@' + dut_ip, 'cat', '/proc/bus/input/devices']
32 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
33 out = p.communicate()[0]
34
35 for line in out.splitlines():
36 handler_prefix = 'H: Handlers='
37 kbd_event = 'B: EV=120013'
38 if line.startswith(handler_prefix):
39 handlers = line[len(handler_prefix):].split()
40 elif line.startswith(kbd_event):
41 for handler in handlers:
42 if handler.startswith('event'):
43 return '/dev/input/' + handler
44 raise Exception('keyboard device not found')
45
46 def SetupKeyDispatch(dut_ip):
47 """Uploading the script to send key to switch tabs."""
48 cur_dir = os.path.dirname(os.path.abspath(__file__))
49 send_key_filename = cur_dir + '/data/send_key_tab_switch'
50 log_key_filename = cur_dir + '/data/log_key_tab_switch'
51
52 kbd_dev = FindKeyboardDevice(dut_ip)
53 send_key_content = '#!/bin/bash\n'
54 send_key_content += ('evemu-play --insert-slot0 ' + kbd_dev +
55 ' < /home/root/log_key_tab_switch')
56 with open(send_key_filename, 'w') as f:
57 f.write(send_key_content)
58 os.chmod(send_key_filename, 0774)
59
60 os.system('scp -q %s root@%s:/usr/local/tmp/' % (log_key_filename, dut_ip))
61 os.system('scp -q %s root@%s:/usr/local/tmp/' % (send_key_filename, dut_ip))
62
63 def GetTabSwitchHistogram(tab):
64 histogram_name = 'MPArch.RWH_TabSwitchPaintDuration'
65 histogram_type = histogram_util.BROWSER_HISTOGRAM
66 return histogram_util.GetHistogram(
67 histogram_type, histogram_name, tab)
68
69 def GetTabSwitchHistogramRetry(browser):
70 """Retry GetHistogram() as it may fail when a context was discarded."""
71 while True:
72 try:
73 # Any tab can be used to get the TabSwitchPaintDuration histogram.
74 # At each retry, try to get valid context again.
75 return GetTabSwitchHistogram(browser.tabs[-1])
76 except exceptions.DevtoolsTargetCrashException:
77 logging.info('GetHistogram: devtools context lost')
78 except KeyError:
79 logging.info('GetHistogram: devtools context lost')
80 except Exception as e:
81 logging.warning('GetHistogram: exception')
82 logging.warning(e)
83 time.sleep(0.5)
84
85 def SwitchTab(browser):
86 """Sending Ctrl-tab key to trigger tab switching. Checking the histogram
87 to wait for tab switching completion."""
88 # pylint: disable=protected-access
89 platform_backend = browser._platform_backend
90
91 prev_histogram = GetTabSwitchHistogramRetry(browser)
92
93 platform_backend.RunCommand('/usr/local/tmp/send_key_tab_switch')
94
95 def _IsDone():
96 cur_histogram = GetTabSwitchHistogramRetry(browser)
97
98 diff_histogram = histogram_util.SubtractHistogram(cur_histogram,
99 prev_histogram)
100 diff_histogram_count = json.loads(diff_histogram).get('count', 0)
101 return diff_histogram_count > 0
102
103 try:
104 py_utils.WaitFor(_IsDone, 10)
105 except py_utils.TimeoutException:
106 logging.warning('wait for histogram timed out')
107
108 def NoScreenOff(platform_backend):
109 """Set screen off and dim timer to 1 hour."""
110 platform_backend.RunCommand('set_power_policy --ac_screen_off_delay=3600')
111 platform_backend.RunCommand('set_power_policy --ac_screen_dim_delay=3600')
OLDNEW
« no previous file with comments | « tools/perf/contrib/cros_benchmarks/__init__.py ('k') | tools/perf/contrib/cros_benchmarks/data/log_key_tab_switch » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698