Add an option to make the graphics benchmark runs a specific test
[WebKit-https.git] / PerformanceTests / Animometer / runner / resources / animometer.js
1 window.benchmarkRunnerClient = {
2     iterationCount: 1,
3     testsCount: null,
4     progressBar: null,
5     recordTable: null,
6     options: { testInterval: 30000, frameRate: 50, estimatedFrameRate: true, fixTestComplexity : false },
7     score: 0,
8     _resultsDashboard: null,
9     _resultsTable: null,
10     
11     willAddTestFrame: function (frame)
12     {
13         var main = document.querySelector("main");
14         var style = getComputedStyle(main);
15         frame.style.left = main.offsetLeft + parseInt(style.borderLeftWidth) + parseInt(style.paddingLeft) + "px";
16         frame.style.top = main.offsetTop + parseInt(style.borderTopWidth) + parseInt(style.paddingTop) + "px";
17     },
18     
19     didRunTest: function ()
20     {
21         this.progressBar.incRange();
22     },
23     
24     willStartFirstIteration: function ()
25     {
26         this._resultsDashboard = new ResultsDashboard();
27         this._resultsTable = new ResultsTable(document.querySelector(".results-table"), Headers);
28         
29         this.progressBar = new ProgressBar(document.getElementById("progress-completed"), this.testsCount);
30         this.recordTable = new ResultsTable(document.querySelector(".record-table"), Headers);
31     },
32     
33     didRunSuites: function (suitesSamplers)
34     {
35         this._resultsDashboard.push(suitesSamplers);
36     },
37     
38     didFinishLastIteration: function ()
39     {
40         var json = this._resultsDashboard.toJSON(true, true);
41         this._resultsTable.showIterations(json[Strings["JSON_RESULTS"][0]]);
42         
43         var element = document.querySelector("#json > textarea");
44         element.innerHTML = JSON.stringify(json[Strings["JSON_RESULTS"][0]][0], function(key, value) { 
45             if (typeof value == "number")
46                 return value.toFixed(2);
47             return value;
48         }, 4);
49         
50         this.score = json[Strings["JSON_SCORE"]];
51         showResults();
52     }
53 }
54
55 function showSection(sectionIdentifier, pushState)
56 {
57     var currentSectionElement = document.querySelector("section.selected");
58     console.assert(currentSectionElement);
59
60     var newSectionElement = document.getElementById(sectionIdentifier);
61     console.assert(newSectionElement);
62
63     currentSectionElement.classList.remove("selected");
64     newSectionElement.classList.add("selected");
65
66     if (pushState)
67         history.pushState({section: sectionIdentifier}, document.title);
68 }
69
70 function startBenchmark()
71 {
72     var enabledSuites = [];
73
74     localStorage.clear();
75     var suiteItems = document.querySelectorAll("#suites > ul > li");
76     for (var i = 0; i < suiteItems.length; ++i) {
77         var suiteItem = suiteItems[i];
78         var suiteCheckbox = suiteItem.querySelector("input");
79
80         if (!suiteCheckbox.checked)
81             continue;
82
83         var enabledTests = [];
84         var testCheckboxes = suiteItem.querySelector("ul").querySelectorAll("input");
85         for (var j = 0; j < testCheckboxes.length; ++j) {
86             var testCheckbox = testCheckboxes[j];
87             if (!testCheckbox.checked)
88                 continue;
89
90             enabledTests.push(testCheckbox.test);
91             localStorage.setItem(localStorageNameForTest(suiteCheckbox.suite, testCheckbox.test), +testCheckbox.checked);
92         }
93
94         enabledSuites.push(new Suite(suiteCheckbox.suite.name, enabledTests));
95     }
96
97     localStorage.setItem("test-interval", document.getElementById("test-interval").value);
98
99     var testsCount = enabledSuites.reduce(function (testsCount, suite) { return testsCount + suite.tests.length; }, 0);
100     benchmarkRunnerClient.testsCount = benchmarkRunnerClient.iterationCount * testsCount;
101     benchmarkRunnerClient.options["testInterval"] = parseInt(document.getElementById("test-interval").value) * 1000;
102     benchmarkRunnerClient.options["frameRate"] = parseInt(document.getElementById("frame-rate").value);
103     benchmarkRunnerClient.options["estimatedFrameRate"] = document.getElementById("estimated-frame-rate").checked;    
104     benchmarkRunnerClient.options["fixTestComplexity"] = document.getElementById("fix-test-complexity").checked;
105     benchmarkRunnerClient.options["showRunningResults"] = document.getElementById("show-running-results").checked;
106     
107     if (!benchmarkRunnerClient.options["showRunningResults"])
108         document.getElementById("record").style.display = "none";
109
110     var runner = new BenchmarkRunner(enabledSuites, benchmarkRunnerClient);
111     runner.runMultipleIterations(benchmarkRunnerClient.iterationCount);
112 }
113
114 function startTest()
115 {
116     showSection("running");
117     startBenchmark();
118 }
119
120 function showResults()
121 {
122     var element = document.querySelector("#results > h1");
123     element.textContent = Strings["TEXT_RESULTS"][0] + ":";
124     
125     var score = benchmarkRunnerClient.score.toFixed(2);
126     element.textContent += " [Score = " + score + "]";
127         
128     showSection("results", true);
129 }
130
131 function showJson()
132 {
133     var element = document.querySelector("#json > h1");
134     element.textContent = Strings["TEXT_RESULTS"][2] + ":";
135     
136     var score = benchmarkRunnerClient.score.toFixed(2);
137     element.textContent += " [Score = " + score + "]";
138
139     showSection("json", true);
140 }
141
142 function showTestGraph(testName, axes, samples, samplingTimeOffset)
143 {
144     var element = document.querySelector("#test-graph > h1");
145     element.textContent = Strings["TEXT_RESULTS"][1] + ":";
146
147     if (testName.length)
148         element.textContent += " [test = " + testName + "]";
149             
150     graph("#graphContainer", new Point(700, 400), new Insets(20, 50, 20, 50), axes, samples, samplingTimeOffset);
151     showSection("test-graph", true);    
152 }
153
154 function showTestJSON(testName, testResults)
155 {
156     var element = document.querySelector("#test-json > h1");
157     element.textContent = Strings["TEXT_RESULTS"][2] + ":";
158
159     if (testName.length)
160         element.textContent += " [test = " + testName + "]";
161             
162     var element = document.querySelector("#test-json > textarea");
163     element.innerHTML = JSON.stringify(testResults, function(key, value) { 
164         if (typeof value == "number")
165             return value.toFixed(2);
166         return value;
167     }, 4);
168
169     showSection("test-json", true);    
170 }
171
172 function initialize() {
173     populateSettings();
174
175     var toggleTestsCheckbox = document.getElementById("toggleTests");
176     toggleTestsCheckbox.onchange = function(event) {
177         if (event.target.checked)
178             document.getElementById("suites").classList.add("showTests");
179         else
180             document.getElementById("suites").classList.remove("showTests");
181     };
182 }
183
184 function updateSuiteSelection(event) {
185     var selected = event.target.checked;
186     var testCheckboxes = event.target.parentNode.parentNode.querySelector("ul").querySelectorAll("input");
187     for (var i = 0; i < testCheckboxes.length; ++i) {
188         testCheckboxes[i].checked = selected;
189     }
190 }
191
192 function updateTestSelection(event) {
193     var testsList = event.target.parentNode.parentNode.parentNode;
194     var suiteCheckbox = testsList.parentNode.querySelector("label > input");
195
196     updateSuiteCheckbox(testsList, suiteCheckbox);
197 }
198
199 function updateSuiteCheckbox(testsList, suiteCheckbox) {
200     var numberEnabledTests = 0;
201     var testCheckboxes = testsList.querySelectorAll("input");
202     var totalCheckboxes = testCheckboxes.length;
203     for (var i = 0; i < totalCheckboxes; ++i) {
204         if (testCheckboxes[i].checked)
205             ++numberEnabledTests;
206     }
207     suiteCheckbox.checked = numberEnabledTests > 0;
208     suiteCheckbox.indeterminate = numberEnabledTests > 0 && numberEnabledTests < totalCheckboxes;
209 }
210
211 function localStorageNameForTest(suite, test) {
212     return suite.name + "/" + test.name;
213 }
214
215 function populateSettings() {
216     var suitesDiv = document.getElementById("suites");
217
218     var suitesList = document.createElement("ul");
219     suitesDiv.appendChild(suitesList);
220
221     Suites.forEach(function(suite) {
222         var suiteItem = document.createElement("li");
223         suitesList.appendChild(suiteItem);
224
225         var suiteLabel = document.createElement("label");
226         suiteItem.appendChild(suiteLabel);
227
228         var suiteCheckbox = document.createElement("input");
229         suiteCheckbox.setAttribute("type", "checkbox");
230         suiteCheckbox.suite = suite;
231         suiteCheckbox.onchange = updateSuiteSelection;
232         suiteLabel.appendChild(suiteCheckbox);
233         suiteLabel.appendChild(document.createTextNode(" " + suite.name));
234
235         var testsList = document.createElement("ul");
236         suiteItem.appendChild(testsList);
237
238         suite.tests.forEach(function(test) {
239             var testItem = document.createElement("li");
240             testsList.appendChild(testItem);
241
242             var testLabel = document.createElement("label");
243             testItem.appendChild(testLabel);
244
245             var testCheckbox = document.createElement("input");
246             testCheckbox.setAttribute("type", "checkbox");
247             testCheckbox.test = test;
248             testCheckbox.onchange = updateTestSelection;
249             if (+localStorage.getItem(localStorageNameForTest(suite, test)))
250                 testCheckbox.checked = true;
251             testLabel.appendChild(testCheckbox);
252             testLabel.appendChild(document.createTextNode(" " + test.name));
253         });
254
255         updateSuiteCheckbox(testsList, suiteCheckbox);
256     });
257
258     var interval = localStorage.getItem("test-interval");
259     if (interval) {
260         document.getElementById("test-interval").value = interval;
261     }
262 }
263 document.addEventListener("DOMContentLoaded", initialize);