Commit e34ed88c authored by Zhenyao Mo's avatar Zhenyao Mo Committed by Commit Bot

A few minor improvement for power measurement script

1) Need to change the way python launched Edge. This is the only way an URL
can be passed to Edge that contains "&".

2) Add an option to pass command line switches in a file

BUG=867155
R=sunnyps@chromium.org
TEST=manual

Change-Id: If5457a82661414c2a3453bff094d6a2ffadeeab0
Reviewed-on: https://chromium-review.googlesource.com/c/1332930
Commit-Queue: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: default avatarSunny Sachanandani <sunnyps@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609054}
parent 8fd29f1e
...@@ -72,18 +72,15 @@ def LocateBrowser(options_browser): ...@@ -72,18 +72,15 @@ def LocateBrowser(options_browser):
def LaunchBrowser(browser, user_data_dir, url, extra_browser_args): def LaunchBrowser(browser, user_data_dir, url, extra_browser_args):
args = [] browser_proc = None
shell = False
if browser == 'edge': if browser == 'edge':
args.append('start') cmd = 'start microsoft-edge:'
edge_cmd = 'microsoft-edge:'
if url: if url:
edge_cmd = edge_cmd + url cmd = cmd + '\"' + url + '\"'
args.append(edge_cmd) logging.debug(cmd)
# Without |shell| sets to true, launching Edge won't work. browser_proc = subprocess.Popen(cmd, shell=True)
shell = True
else: else:
args.append(browser) args = [browser]
if url: if url:
args.append(url) args.append(url)
if browser.endswith("chrome.exe"): if browser.endswith("chrome.exe"):
...@@ -91,10 +88,11 @@ def LaunchBrowser(browser, user_data_dir, url, extra_browser_args): ...@@ -91,10 +88,11 @@ def LaunchBrowser(browser, user_data_dir, url, extra_browser_args):
args.append('--no-first-run') args.append('--no-first-run')
args.append('--no-default-browser-check') args.append('--no-default-browser-check')
args.append('--autoplay-policy=no-user-gesture-required') args.append('--autoplay-policy=no-user-gesture-required')
if extra_browser_args: args.append('--start-maximized')
args.extend(extra_browser_args.split(' ')) if len(extra_browser_args) > 0:
args.extend(extra_browser_args)
logging.debug(" ".join(args)) logging.debug(" ".join(args))
browser_proc = subprocess.Popen(args, shell=shell) browser_proc = subprocess.Popen(args)
return browser_proc return browser_proc
...@@ -105,9 +103,6 @@ def MeasurePowerOnce(browser, logfile, duration, delay, resolution, url, ...@@ -105,9 +103,6 @@ def MeasurePowerOnce(browser, logfile, duration, delay, resolution, url,
browser_proc = LaunchBrowser(browser, user_data_dir, url, extra_browser_args) browser_proc = LaunchBrowser(browser, user_data_dir, url, extra_browser_args)
ipg_utils.RunIPG(duration + delay, resolution, logfile) ipg_utils.RunIPG(duration + delay, resolution, logfile)
if browser == 'edge': if browser == 'edge':
# Because Edge is launched with |shell| set to true, browser_proc isn't
# the Edge process, so the following is used to kill all Edge processes
# in the system, including ones not launched through this script.
subprocess.call("taskkill /F /IM MicrosoftEdge.exe /T") subprocess.call("taskkill /F /IM MicrosoftEdge.exe /T")
else: else:
browser_proc.kill() browser_proc.kill()
...@@ -159,6 +154,10 @@ def main(argv): ...@@ -159,6 +154,10 @@ def main(argv):
parser.add_option("--extra-browser-args", dest="extra_browser_args", parser.add_option("--extra-browser-args", dest="extra_browser_args",
help="specify extra command line switches for the browser " help="specify extra command line switches for the browser "
"that are separated by spaces (quoted).") "that are separated by spaces (quoted).")
parser.add_option("--extra-browser-args-filename",
dest="extra_browser_args_filename", metavar="FILE",
help="specify extra command line switches for the browser "
"in a text file that are separated by whitespace.")
# TODO(zmo): add an option --start-fullscreen # TODO(zmo): add an option --start-fullscreen
(options, _) = parser.parse_args(args=argv) (options, _) = parser.parse_args(args=argv)
if options.verbose: if options.verbose:
...@@ -175,13 +174,25 @@ def main(argv): ...@@ -175,13 +174,25 @@ def main(argv):
all_results = [] all_results = []
extra_brower_args = []
if options.extra_browser_args:
extra_browser_args = options.extra_browser_args.split()
if options.extra_browser_args_filename:
if not os.path.isfile(options.extra_browser_args_filename):
logging.error("Can't locate file at %s",
options.extra_browser_args_filename)
else:
with open(options.extra_browser_args_filename, 'r') as file:
extra_browser_args.extend(file.read().split())
file.close()
for run in range(1, options.repeat + 1): for run in range(1, options.repeat + 1):
logfile = ipg_utils.GenerateIPGLogFilename( logfile = ipg_utils.GenerateIPGLogFilename(
log_prefix, options.logdir, run, options.repeat, True) log_prefix, options.logdir, run, options.repeat, True)
print "Iteration #%d out of %d" % (run, options.repeat) print "Iteration #%d out of %d" % (run, options.repeat)
results = MeasurePowerOnce(browser, logfile, options.duration, results = MeasurePowerOnce(browser, logfile, options.duration,
options.delay, options.resolution, options.url, options.delay, options.resolution, options.url,
options.extra_browser_args) extra_browser_args)
print results print results
all_results.append(results) all_results.append(results)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment