summaryrefslogtreecommitdiffstats
path: root/third_party/webkit/PerformanceTests/Speedometer/resources/benchmark-report.js
blob: 972fbb0529c8da2ddb5d76f37d8806fc0d66bc42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// This file can be customized to report results as needed.

(function () {
    if ((!window.testRunner && location.search != '?webkit' && location.hash != '#webkit')
         && location.search != '?gecko' && location.search != '?raptor')
        return;

    if (window.testRunner)
        testRunner.waitUntilDone();

    var scriptElement = document.createElement('script');
    scriptElement.src = '../resources/runner.js';
    document.head.appendChild(scriptElement);

    var styleElement = document.createElement('style');
    styleElement.textContent = 'pre { padding-top: 600px; }';
    document.head.appendChild(styleElement);

    var createTest;
    var valuesByIteration = new Array;

    window.onload = function () {
        document.body.removeChild(document.querySelector('main'));
        startBenchmark();
    }

    window.benchmarkClient = {
        iterationCount: 5, // Use 4 different instances of DRT/WTR to run 5 iterations.
        willStartFirstIteration: function (iterationCount) {
            createTest = function (name, aggregator, isLastTest) {
                return {
                    customIterationCount: iterationCount,
                    doNotIgnoreInitialRun: true,
                    doNotMeasureMemoryUsage: true,
                    continueTesting: !isLastTest,
                    unit: 'ms',
                    name: name,
                    aggregator: aggregator};
            }
            if (window.PerfTestRunner) {
                PerfTestRunner.prepareToMeasureValuesAsync(createTest(null, 'Total'));
            }
        },
        didRunSuites: function (measuredValues) {
            if (window.PerfTestRunner)
                PerfTestRunner.measureValueAsync(measuredValues.total);
            valuesByIteration.push(measuredValues.tests);
        },
        didFinishLastIteration: function () {
            document.head.removeChild(document.querySelector('style'));

            var measuredValuesByFullName = {};
            function addToMeasuredValue(value, fullName, aggregator) {
                var values = measuredValuesByFullName[fullName] || new Array;
                measuredValuesByFullName[fullName] = values;
                values.push(value);
                values.aggregator = aggregator;
            }

            valuesByIteration.forEach(function (measuredValues) {
                for (var suiteName in measuredValues) {
                    var suite = measuredValues[suiteName];
                    for (var testName in suite.tests) {
                        var test = suite.tests[testName];
                        for (var subtestName in test.tests)
                            addToMeasuredValue(test.tests[subtestName], suiteName + '/' + testName + '/' + subtestName);
                        addToMeasuredValue(test.total, suiteName + '/' + testName, 'Total');
                    }
                    addToMeasuredValue(suite.total, suiteName, 'Total');
                }
            });

            var fullNames = new Array;
            for (var fullName in measuredValuesByFullName) {
                fullNames.push(fullName);
            }

            if (typeof tpRecordTime !== "undefined" || location.search == '?raptor') {
                var values = new Array;
                var allNames = new Array;
                for (var i = 0; i < fullNames.length; i++) {
                    vals = measuredValuesByFullName[fullNames[i]];
                    values.push(vals);
                    for (var count=0; count < vals.length; count ++) {
                        allNames.push(fullNames[i]);
                    }
                }

                if (location.search == '?raptor') {
                    _data = ['raptor-benchmark', 'speedometer', measuredValuesByFullName];
                    console.log('speedometer source about to post results to the raptor webext');
                    window.postMessage(_data, '*');
                    window.sessionStorage.setItem('benchmark_results',  JSON.stringify(_data));
                } else {
                    tpRecordTime(values.join(','), 0, allNames.join(','));
                }
            } else {
                for (var i = 0; i < fullNames.length; i++) {
                    var values = measuredValuesByFullName[fullNames[i]];
                    PerfTestRunner.reportValues(createTest(fullNames[i], values.aggregator, i + 1 == fullNames.length), values);
                }
            }
        }
    };
})();