d8b3825f2dacfacaf7bd3d316939377ff00c2c7d
[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     _iterationsSamplers: [],
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._iterationsSamplers = [];
27         this._resultsTable = new RecordTable(document.querySelectorAll(".results-table")[0]);
28         
29         this.progressBar = new ProgressBar(document.getElementById("progress-completed"), this.testsCount);
30         this.recordTable = new RecordTable(document.querySelectorAll(".record-table")[0]);
31     },
32     
33     didRunSuites: function (suitesSamplers)
34     {
35         this._iterationsSamplers.push(suitesSamplers);
36     },
37     
38     didFinishLastIteration: function ()
39     {
40         this.score = this._resultsTable.showIterations(this._iterationsSamplers, "");
41         showResults();
42     }
43 }
44
45 function showSection(sectionIdentifier, pushState)
46 {
47     var currentSectionElement = document.querySelector("section.selected");
48     console.assert(currentSectionElement);
49
50     var newSectionElement = document.getElementById(sectionIdentifier);
51     console.assert(newSectionElement);
52
53     currentSectionElement.classList.remove("selected");
54     newSectionElement.classList.add("selected");
55
56     if (pushState)
57         history.pushState({section: sectionIdentifier}, document.title);
58 }
59
60 function startBenchmark()
61 {
62     var enabledSuites = [];
63     var checkboxes = document.querySelectorAll("#suites input");
64     for (var i = 0; i < checkboxes.length; ++i) {
65         var checkbox = checkboxes[i];
66         if (checkbox.checked) {
67             enabledSuites.push(checkbox.suite);
68         }
69         localStorage.setItem(checkbox.suite.name, +checkbox.checked);
70         localStorage.setItem("test-interval", document.getElementById("test-interval").value);
71     }
72
73     var enabledSuites = Suites.filter(function (suite, index) { return !suite.disabled && checkboxes[index].checked; });
74     var testsCount = enabledSuites.reduce(function (testsCount, suite) { return testsCount + suite.tests.length; }, 0);
75     benchmarkRunnerClient.testsCount = benchmarkRunnerClient.iterationCount * testsCount;
76     benchmarkRunnerClient.options["testInterval"] = parseInt(document.getElementById("test-interval").value) * 1000;
77     benchmarkRunnerClient.options["frameRate"] = parseInt(document.getElementById("frame-rate").value);
78     benchmarkRunnerClient.options["estimatedFrameRate"] = document.getElementById("estimated-frame-rate").checked;    
79     benchmarkRunnerClient.options["fixTestComplexity"] = document.getElementById("fix-test-complexity").checked;
80     benchmarkRunnerClient.options["showRunningResults"] = document.getElementById("show-running-results").checked;
81     
82     if (!benchmarkRunnerClient.options["showRunningResults"])
83         document.getElementById("record").style.display = "none";
84
85     var runner = new BenchmarkRunner(enabledSuites, benchmarkRunnerClient);
86     runner.runMultipleIterations(benchmarkRunnerClient.iterationCount);
87 }
88
89 function startTest()
90 {
91     showSection("running");
92     startBenchmark();
93 }
94
95 function showResults(score)
96 {
97     var element = document.querySelector("#results > h1");
98     element.textContent = "Results:"
99     
100     var score = benchmarkRunnerClient.score.toFixed(2);
101     element.textContent += " [Score = " + score + "]";
102         
103     showSection("results", true);
104 }
105
106 function showGraph(testName, axes, samples, samplingTimeOffset)
107 {
108     var element = document.querySelector("#graph > h1");
109     element.textContent = "Graph:"
110
111     if (testName.length)
112         element.textContent += " [test = " + testName + "]";
113             
114     graph("#graphContainer", new Point(700, 400), new Insets(20, 50, 20, 50), axes, samples, samplingTimeOffset);
115     showSection("graph", true);    
116 }
117
118 function populateSettings() {
119     var suitesDiv = document.getElementById("suites");
120     Suites.forEach(function(suite) {
121         var suiteDiv = document.createDocumentFragment();
122
123         var label = document.createElement("label");
124         var checkbox = document.createElement("input");
125         checkbox.setAttribute("type", "checkbox");
126         checkbox.suite = suite;
127         if (+localStorage.getItem(suite.name)) {
128             checkbox.checked = true;
129         }
130         label.appendChild(checkbox);
131         label.appendChild(document.createTextNode(" " + suite.name));
132
133         suiteDiv.appendChild(label);
134         suiteDiv.appendChild(document.createElement("br"));
135         suitesDiv.appendChild(suiteDiv);
136     });
137
138     var interval = localStorage.getItem("test-interval");
139     if (interval) {
140         document.getElementById("test-interval").value = interval;
141     }
142 }
143 document.addEventListener("DOMContentLoaded", populateSettings);