Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / tools / site_compare / commands / measure.py
blob2bd71f560344dc06c58d0551a79540c3157a5bd1
1 # Copyright (c) 2011 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.
5 """Command for measuring how long pages take to load in a browser.
7 Prerequisites:
8 1. The command_line package from tools/site_compare
9 2. Either the IE BHO or Firefox extension (or both)
11 Installation:
12 1. Build the IE BHO, or call regsvr32 on a prebuilt binary
13 2. Add a file called "measurepageloadtimeextension@google.com" to
14 the default Firefox profile directory under extensions, containing
15 the path to the Firefox extension root
17 Invoke with the command line arguments as documented within
18 the command line.
19 """
21 import command_line
22 import win32process
24 from drivers import windowing
25 from utils import browser_iterate
27 def CreateCommand(cmdline):
28 """Inserts the command and arguments into a command line for parsing."""
29 cmd = cmdline.AddCommand(
30 ["measure"],
31 "Measures how long a series of URLs takes to load in one or more browsers.",
32 None,
33 ExecuteMeasure)
35 browser_iterate.SetupIterationCommandLine(cmd)
36 cmd.AddArgument(
37 ["-log", "--logfile"], "File to write output", type="string", required=True)
40 def ExecuteMeasure(command):
41 """Executes the Measure command."""
43 def LogResult(url, proc, wnd, result):
44 """Write the result of the browse to the log file."""
45 log_file.write(result)
47 log_file = open(command["--logfile"], "w")
49 browser_iterate.Iterate(command, LogResult)
51 # Close the log file and return. We're done.
52 log_file.close()