2 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
3 <html><head><title>Python: module telemetry.page.page_measurement</title>
4 </head><body bgcolor="#f0f0f8">
6 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
8 <td valign=bottom> <br>
9 <font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="telemetry.html"><font color="#ffffff">telemetry</font></a>.<a href="telemetry.page.html"><font color="#ffffff">page</font></a>.page_measurement</strong></big></big></font></td
10 ><td align=right valign=bottom
11 ><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="../telemetry/page/page_measurement.py">telemetry/page/page_measurement.py</a></font></td></tr></table>
12 <p><tt># Copyright (c) 2012 The Chromium Authors. All rights reserved.<br>
13 # Use of this source code is governed by a BSD-style license that can be<br>
14 # found in the LICENSE file.</tt></p>
16 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
17 <tr bgcolor="#aa55cc">
18 <td colspan=3 valign=bottom> <br>
19 <font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
21 <tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
22 <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="telemetry.page.block_page_measurement_results.html">telemetry.page.block_page_measurement_results</a><br>
23 <a href="telemetry.page.buildbot_page_measurement_results.html">telemetry.page.buildbot_page_measurement_results</a><br>
24 </td><td width="25%" valign=top><a href="telemetry.page.csv_page_measurement_results.html">telemetry.page.csv_page_measurement_results</a><br>
25 <a href="os.html">os</a><br>
26 </td><td width="25%" valign=top><a href="telemetry.page.page_measurement_results.html">telemetry.page.page_measurement_results</a><br>
27 <a href="telemetry.page.page_test.html">telemetry.page.page_test</a><br>
28 </td><td width="25%" valign=top><a href="sys.html">sys</a><br>
29 </td></tr></table></td></tr></table><p>
30 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
31 <tr bgcolor="#ee77aa">
32 <td colspan=3 valign=bottom> <br>
33 <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
35 <tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
37 <dt><font face="helvetica, arial"><a href="telemetry.page.page_test.html#Failure">telemetry.page.page_test.Failure</a>(<a href="exceptions.html#Exception">exceptions.Exception</a>)
40 <dt><font face="helvetica, arial"><a href="telemetry.page.page_measurement.html#MeasurementFailure">MeasurementFailure</a>
43 <dt><font face="helvetica, arial"><a href="telemetry.page.page_test.html#PageTest">telemetry.page.page_test.PageTest</a>(<a href="__builtin__.html#object">__builtin__.object</a>)
46 <dt><font face="helvetica, arial"><a href="telemetry.page.page_measurement.html#PageMeasurement">PageMeasurement</a>
51 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
52 <tr bgcolor="#ffc8d8">
53 <td colspan=3 valign=bottom> <br>
54 <font color="#000000" face="helvetica, arial"><a name="MeasurementFailure">class <strong>MeasurementFailure</strong></a>(<a href="telemetry.page.page_test.html#Failure">telemetry.page.page_test.Failure</a>)</font></td></tr>
56 <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
57 <td colspan=2><tt>Exception that can be thrown from MeasurePage to indicate an undesired but<br>
58 designed-for problem.<br> </tt></td></tr>
60 <td width="100%"><dl><dt>Method resolution order:</dt>
61 <dd><a href="telemetry.page.page_measurement.html#MeasurementFailure">MeasurementFailure</a></dd>
62 <dd><a href="telemetry.page.page_test.html#Failure">telemetry.page.page_test.Failure</a></dd>
63 <dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd>
64 <dd><a href="exceptions.html#BaseException">exceptions.BaseException</a></dd>
65 <dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
68 Data descriptors inherited from <a href="telemetry.page.page_test.html#Failure">telemetry.page.page_test.Failure</a>:<br>
69 <dl><dt><strong>__weakref__</strong></dt>
70 <dd><tt>list of weak references to the object (if defined)</tt></dd>
73 Methods inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
74 <dl><dt><a name="MeasurementFailure-__init__"><strong>__init__</strong></a>(...)</dt><dd><tt>x.<a href="#MeasurementFailure-__init__">__init__</a>(...) initializes x; see help(type(x)) for signature</tt></dd></dl>
77 Data and other attributes inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
78 <dl><dt><strong>__new__</strong> = <built-in method __new__ of type object><dd><tt>T.<a href="#MeasurementFailure-__new__">__new__</a>(S, ...) -> a new object with type S, a subtype of T</tt></dl>
81 Methods inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
82 <dl><dt><a name="MeasurementFailure-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#MeasurementFailure-__delattr__">__delattr__</a>('name') <==> del x.name</tt></dd></dl>
84 <dl><dt><a name="MeasurementFailure-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#MeasurementFailure-__getattribute__">__getattribute__</a>('name') <==> x.name</tt></dd></dl>
86 <dl><dt><a name="MeasurementFailure-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#MeasurementFailure-__getitem__">__getitem__</a>(y) <==> x[y]</tt></dd></dl>
88 <dl><dt><a name="MeasurementFailure-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#MeasurementFailure-__getslice__">__getslice__</a>(i, j) <==> x[i:j]<br>
90 Use of negative indices is not supported.</tt></dd></dl>
92 <dl><dt><a name="MeasurementFailure-__reduce__"><strong>__reduce__</strong></a>(...)</dt></dl>
94 <dl><dt><a name="MeasurementFailure-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#MeasurementFailure-__repr__">__repr__</a>() <==> repr(x)</tt></dd></dl>
96 <dl><dt><a name="MeasurementFailure-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#MeasurementFailure-__setattr__">__setattr__</a>('name', value) <==> x.name = value</tt></dd></dl>
98 <dl><dt><a name="MeasurementFailure-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl>
100 <dl><dt><a name="MeasurementFailure-__str__"><strong>__str__</strong></a>(...)</dt><dd><tt>x.<a href="#MeasurementFailure-__str__">__str__</a>() <==> str(x)</tt></dd></dl>
102 <dl><dt><a name="MeasurementFailure-__unicode__"><strong>__unicode__</strong></a>(...)</dt></dl>
105 Data descriptors inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
106 <dl><dt><strong>__dict__</strong></dt>
108 <dl><dt><strong>args</strong></dt>
110 <dl><dt><strong>message</strong></dt>
112 </td></tr></table> <p>
113 <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
114 <tr bgcolor="#ffc8d8">
115 <td colspan=3 valign=bottom> <br>
116 <font color="#000000" face="helvetica, arial"><a name="PageMeasurement">class <strong>PageMeasurement</strong></a>(<a href="telemetry.page.page_test.html#PageTest">telemetry.page.page_test.PageTest</a>)</font></td></tr>
118 <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
119 <td colspan=2><tt>Glue code for running a measurement across a set of pages.<br>
121 To use this, subclass from the measurement and override MeasurePage. For<br>
124 class BodyChildElementMeasurement(<a href="#PageMeasurement">PageMeasurement</a>):<br>
125 def <a href="#PageMeasurement-MeasurePage">MeasurePage</a>(self, page, tab, results):<br>
126 body_child_count = tab.EvaluateJavaScript(<br>
127 'document.body.children.length')<br>
128 results.Add('body_children', 'count', body_child_count)<br>
130 if __name__ == '__main__':<br>
131 page_measurement.Main(BodyChildElementMeasurement())<br>
133 To add test-specific options:<br>
135 class BodyChildElementMeasurement(<a href="#PageMeasurement">PageMeasurement</a>):<br>
136 def <a href="#PageMeasurement-AddCommandLineOptions">AddCommandLineOptions</a>(parser):<br>
137 parser.add_option('--element', action='store', default='body')<br>
139 def <a href="#PageMeasurement-MeasurePage">MeasurePage</a>(self, page, tab, results):<br>
140 body_child_count = tab.EvaluateJavaScript(<br>
141 'document.querySelector('%s').children.length')<br>
142 results.Add('children', 'count', child_count)<br> </tt></td></tr>
144 <td width="100%"><dl><dt>Method resolution order:</dt>
145 <dd><a href="telemetry.page.page_measurement.html#PageMeasurement">PageMeasurement</a></dd>
146 <dd><a href="telemetry.page.page_test.html#PageTest">telemetry.page.page_test.PageTest</a></dd>
147 <dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
150 Methods defined here:<br>
151 <dl><dt><a name="PageMeasurement-AddOutputOptions"><strong>AddOutputOptions</strong></a>(self, parser)</dt></dl>
153 <dl><dt><a name="PageMeasurement-MeasurePage"><strong>MeasurePage</strong></a>(self, page, tab, results)</dt><dd><tt>Override to actually measure the page's performance.<br>
155 page is a page_set.Page<br>
156 tab is an instance of telemetry.core.Tab<br>
158 Should call results.Add(name, units, value) for each result, or raise an<br>
159 exception on failure. The name and units of each Add() call must be<br>
160 the same across all iterations. The name 'url' must not be used.<br>
162 Prefer field names that are in accordance with python variable style. E.g.<br>
165 Put together:<br>
167 def <a href="#PageMeasurement-MeasurePage">MeasurePage</a>(self, page, tab, results):<br>
168 res = tab.EvaluateJavaScript('2+2')<br>
169 if res != 4:<br>
170 raise Exception('Oh, wow.')<br>
171 results.Add('two_plus_two', 'count', res)</tt></dd></dl>
173 <dl><dt><a name="PageMeasurement-PrepareResults"><strong>PrepareResults</strong></a>(self, options)</dt></dl>
175 <dl><dt><a name="PageMeasurement-__init__"><strong>__init__</strong></a>(self, action_name_to_run<font color="#909090">=''</font>, needs_browser_restart_after_each_run<font color="#909090">=False</font>, discard_first_result<font color="#909090">=False</font>, clear_cache_before_each_run<font color="#909090">=False</font>)</dt></dl>
178 Data descriptors defined here:<br>
179 <dl><dt><strong>output_format_choices</strong></dt>
181 <dl><dt><strong>results_are_the_same_on_every_page</strong></dt>
182 <dd><tt>By default, measurements are assumed to output the same values for every<br>
183 page. This allows incremental output, for example in CSV. If, however, the<br>
184 measurement discovers what values it can report as it goes, and those values<br>
185 may vary from page to page, you need to override this function and return<br>
186 False. Output will not appear in this mode until the entire pageset has<br>
190 Methods inherited from <a href="telemetry.page.page_test.html#PageTest">telemetry.page.page_test.PageTest</a>:<br>
191 <dl><dt><a name="PageMeasurement-AddCommandLineOptions"><strong>AddCommandLineOptions</strong></a>(self, parser)</dt><dd><tt>Override to expose command-line options for this test.<br>
193 The provided parser is an optparse.OptionParser instance and accepts all<br>
194 normal results. The parsed options are available in Run as<br>
195 self.<strong>options</strong>.</tt></dd></dl>
197 <dl><dt><a name="PageMeasurement-CanRunForPage"><strong>CanRunForPage</strong></a>(self, page)</dt><dd><tt>Override to customize if the test can be ran for the given page.</tt></dd></dl>
199 <dl><dt><a name="PageMeasurement-CreatePageSet"><strong>CreatePageSet</strong></a>(self, args, options)</dt><dd><tt>Override to make this test generate its own page set instead of<br>
200 allowing arbitrary page sets entered from the command-line.</tt></dd></dl>
202 <dl><dt><a name="PageMeasurement-CustomizeBrowserOptions"><strong>CustomizeBrowserOptions</strong></a>(self, options)</dt><dd><tt>Override to add test-specific options to the BrowserOptions object</tt></dd></dl>
204 <dl><dt><a name="PageMeasurement-CustomizeBrowserOptionsForPage"><strong>CustomizeBrowserOptionsForPage</strong></a>(self, page, options)</dt><dd><tt>Add options specific to the test and the given page.</tt></dd></dl>
206 <dl><dt><a name="PageMeasurement-DidNavigateToPage"><strong>DidNavigateToPage</strong></a>(self, page, tab)</dt><dd><tt>Override to do operations right after the page is navigated, but before<br>
207 any waiting for completion has occurred.</tt></dd></dl>
209 <dl><dt><a name="PageMeasurement-DidRunAction"><strong>DidRunAction</strong></a>(self, page, tab, action)</dt><dd><tt>Override to do operations after running the action on the page.</tt></dd></dl>
211 <dl><dt><a name="PageMeasurement-DidRunPageSet"><strong>DidRunPageSet</strong></a>(self, tab, results)</dt><dd><tt>Override to do operations after page set is completed, but before browser<br>
212 is torn down.</tt></dd></dl>
214 <dl><dt><a name="PageMeasurement-DidStartHTTPServer"><strong>DidStartHTTPServer</strong></a>(self, tab)</dt><dd><tt>Override to do operations after the HTTP server is started.</tt></dd></dl>
216 <dl><dt><a name="PageMeasurement-NeedsBrowserRestartAfterEachRun"><strong>NeedsBrowserRestartAfterEachRun</strong></a>(self, tab)</dt><dd><tt>Override to specify browser restart after each run.</tt></dd></dl>
218 <dl><dt><a name="PageMeasurement-Run"><strong>Run</strong></a>(self, options, page, tab, results)</dt></dl>
220 <dl><dt><a name="PageMeasurement-SetUpBrowser"><strong>SetUpBrowser</strong></a>(self, browser)</dt><dd><tt>Override to customize the browser right after it has launched.</tt></dd></dl>
222 <dl><dt><a name="PageMeasurement-WillNavigateToPage"><strong>WillNavigateToPage</strong></a>(self, page, tab)</dt><dd><tt>Override to do operations before the page is navigated.</tt></dd></dl>
224 <dl><dt><a name="PageMeasurement-WillRunAction"><strong>WillRunAction</strong></a>(self, page, tab, action)</dt><dd><tt>Override to do operations before running the action on the page.</tt></dd></dl>
226 <dl><dt><a name="PageMeasurement-WillRunPageSet"><strong>WillRunPageSet</strong></a>(self, tab)</dt><dd><tt>Override to do operations before the page set is navigated.</tt></dd></dl>
229 Data descriptors inherited from <a href="telemetry.page.page_test.html#PageTest">telemetry.page.page_test.PageTest</a>:<br>
230 <dl><dt><strong>__dict__</strong></dt>
231 <dd><tt>dictionary for instance variables (if defined)</tt></dd>
233 <dl><dt><strong>__weakref__</strong></dt>
234 <dd><tt>list of weak references to the object (if defined)</tt></dd>
236 <dl><dt><strong>action_name_to_run</strong></dt>
238 <dl><dt><strong>clear_cache_before_each_run</strong></dt>
239 <dd><tt>When set to True, the browser's disk and memory cache will be cleared<br>
240 before each run.</tt></dd>
242 <dl><dt><strong>discard_first_result</strong></dt>
243 <dd><tt>When set to True, the first run of the test is discarded. This is<br>
244 useful for cases where it's desirable to have some test resource cached so<br>
245 the first run of the test can warm things up.</tt></dd>
247 </td></tr></table></td></tr></table>