Add memory measurement to balls.html and dromaeorunner.js
[WebKit-https.git] / PerformanceTests / Dromaeo / resources / dromaeorunner.js
1 (function(){
2      var DRT  = {
3          baseURL: "./resources/dromaeo/web/index.html",
4
5          computeScores: function (results) {
6              var mean = 0, min = 0, max = 0, stdev = 0, varsum = 0;
7
8              for (var i = 0; i < results.length; ++i) {
9                  var item = results[i];
10                  mean += item.mean;
11                  min += item.min;
12                  max += item.max;
13                  varsum += item.deviation * item.deviation;
14              }
15
16              return {
17                  median: 0,
18                  mean: mean,
19                  min: min,
20                  max: max,
21                  stdev: Math.sqrt(varsum),
22                  unit: "runs/s"
23              };
24          },
25
26          setup: function(testName) {
27              var iframe = document.createElement("iframe");
28              var url = DRT.baseURL + "?" + testName;
29              iframe.setAttribute("src", url);
30              document.body.appendChild(iframe);
31              iframe.addEventListener(
32                  "load", function() {
33                      DRT.targetDocument = iframe.contentDocument;
34                      DRT.targetWindow = iframe.contentDocument.defaultView;
35                  });
36
37              window.addEventListener(
38                  "message",
39                  function(event) {
40                      switch(event.data.name) {
41                      case "dromaeo:ready":
42                          DRT.start();
43                          break;
44                      case "dromaeo:progress":
45                          DRT.progress(event.data);
46                          break;
47                      case "dromaeo:alldone":
48                          DRT.teardown(event.data);
49                          break;
50                      }
51                  });
52          },
53
54          start: function() {
55              DRT.targetWindow.postMessage({ name: "dromaeo:start" } , "*");
56          },
57
58          progress: function(message) {
59              if (message.status.score)
60                  DRT.log(message.status.score.mean);
61          },
62
63          teardown: function(data) {
64              var scores = DRT.computeScores(data.result);
65              PerfTestRunner.printStatistics(scores, "Time:");
66              PerfTestRunner.getAndPrintMemoryStatistics();
67              window.setTimeout(function() {
68                  if (window.testRunner)
69                      testRunner.notifyDone();
70              }, 0);
71          },
72
73          targetDelegateOf: function(functionName) {
74              return function() {
75                  DRT.targetWindow[functionName].apply(null, arguments);
76              };
77          },
78
79          log: function(text) {
80              PerfTestRunner.log(text);
81          }
82      };
83
84      // These functions are referred from htmlrunner.js
85      this.startTest = DRT.targetDelegateOf("startTest");
86      this.test = DRT.targetDelegateOf("test");
87      this.endTest = DRT.targetDelegateOf("endTest");
88      this.prep = DRT.targetDelegateOf("prep");
89
90      window.DRT = DRT;
91  })();