1 // Copyright (c) 2012 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.
15 * Returns the value of the given property stored in the cookie.
16 * @param {string} name The property name.
17 * @return {string} The value of the given property, or empty string
18 * if the property was not found.
20 function __get_cookie(name) {
21 var cookies = document.cookie.split('; ');
22 for (var i = 0; i < cookies.length; ++i) {
23 var t = cookies[i].split('=');
24 if ((t[0] == name) && t[1])
30 function __get_timings() {
31 if (sessionStorage == null)
32 return __get_cookie("__pc_timings");
34 if (sessionStorage.getItem("__pc_timings") == null)
37 return sessionStorage["__pc_timings"];
40 function __set_timings(timings) {
41 if (sessionStorage == null)
42 document.cookie = "__pc_timings=" + timings + "; path=/";
44 sessionStorage["__pc_timings"]=timings;
48 * Starts the next test cycle or redirects the browser to the results page.
50 function nextCycleOrResults() {
51 // Call GC twice to cleanup JS heap before starting a new test.
57 var timings = elapsedTime;
58 var oldTimings = __get_timings();
60 timings = oldTimings + ',' + timings;
61 __set_timings(timings);
63 var tLag = Date.now() - endTime - TIMEOUT;
68 if (cycle == iterations) {
69 document.cookie = '__pc_done=1; path=/';
70 doc = '../../common/report.html';
72 console.log("Pages: [" + __get_cookie('__pc_pages') + "]");
73 console.log("times: [" + __get_timings() + "]");
79 var url = doc + '?n=' + iterations + '&i=' + cycle +
80 '&td=' + totalTime + '&tf=' + fudgeTime;
81 document.location.href = url;
85 * Computes various running times and updates the stats reported at the end.
86 * @param {!number} cycleTime The running time of the test cycle.
88 function testComplete(cycleTime) {
93 var cycleEndTime = Date.now();
94 var cycleFudgeTime = 0;
96 var s = document.location.search;
98 var params = s.substring(1).split('&');
99 for (var i = 0; i < params.length; i++) {
100 var f = params[i].split('=');
103 return; // No calculation, just viewing
108 cycle = f[1] - 0 + 1;
111 oldTotalTime = f[1] - 0;
114 cycleFudgeTime = f[1] - 0;
119 elapsedTime = cycleTime;
120 totalTime = oldTotalTime + elapsedTime;
121 endTime = cycleEndTime;
122 fudgeTime = cycleFudgeTime;
124 setTimeout(nextCycleOrResults, TIMEOUT);