- add sources.
[platform/framework/web/crosswalk.git] / src / tools / site_compare / commands / measure.py
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.
4
5 """Command for measuring how long pages take to load in a browser.
6
7 Prerequisites:
8   1. The command_line package from tools/site_compare
9   2. Either the IE BHO or Firefox extension (or both)
10
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
16
17 Invoke with the command line arguments as documented within
18 the command line.
19 """
20
21 import command_line
22 import win32process
23
24 from drivers import windowing
25 from utils import browser_iterate
26
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)
34
35   browser_iterate.SetupIterationCommandLine(cmd)
36   cmd.AddArgument(
37     ["-log", "--logfile"], "File to write output", type="string", required=True)
38
39
40 def ExecuteMeasure(command):
41   """Executes the Measure command."""
42
43   def LogResult(url, proc, wnd, result):
44     """Write the result of the browse to the log file."""
45     log_file.write(result)
46
47   log_file = open(command["--logfile"], "w")
48
49   browser_iterate.Iterate(command, LogResult)
50
51   # Close the log file and return. We're done.
52   log_file.close()