summaryrefslogtreecommitdiff
path: root/tests/vnc_perf.html
blob: 021bc4ee450f3a3ea1d9b5fa8177b4baf2df96f1 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<html>
    <head>
        <title>VNC Performance Benchmark</title>
    </head>
    <body>

        Passes: <input id='passes' style='width:50' value=3>&nbsp;

        <input id='startButton' type='button' value='Start' style='width:100px'
            onclick="do_test();" disabled>&nbsp;

        <br><br>

        Results:<br>
        <textarea id="messages" style="font-size: 9;" cols=80 rows=15></textarea>

        <br><br>

        <div id="VNC_screen">
            <div id="VNC_status_bar" class="VNC_status_bar" style="margin-top: 0px;">
                <table border=0 width=100%><tr>
                    <td><div id="VNC_status">Loading</div></td>
                </tr></table>
            </div>
            <canvas id="VNC_canvas" width="640px" height="20px">
                Canvas not supported.
            </canvas>
        </div>

    </body>

    <!--
    <script type='text/javascript'
        src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
    -->

    <script type="text/javascript">
        var INCLUDE_URI= "../";
        // TODO: Data file should override
        var VNC_frame_encoding = "binary";
    </script>
    <script src="../core/util.js"></script>
    <script src="../app/webutil.js"></script>

    <script>
        var fname = WebUtil.getQueryVar('data', null);
        if (fname) {
            msg("Loading " + fname);

            // Load supporting scripts
            WebUtil.load_scripts({
                'core': ["base64.js", "websock.js", "des.js", "keysym.js",
                         "keysymdef.js", "xtscancodes.js", "keyboard.js",
                         "input.js", "display.js", "rfb.js", "inflator.js"],
                'tests': ["playback.js"],
                'recordings': [fname]});
        } else {
            msg("Must specifiy data=FOO.js in query string.");
        }

        var start_time, VNC_frame_data, pass, passes, encIdx,
            encOrder = ['raw', 'rre', 'hextile', 'tightpng', 'copyrect'],
            encTot = {}, encMin = {}, encMax = {},
            passCur, passTot, passMin, passMax;

        function msg(str) {
            console.log(str);
            var cell = document.getElementById('messages');
            cell.innerHTML += str + "\n";
            cell.scrollTop = cell.scrollHeight;
        }
        function dbgmsg(str) {
            if (Util.get_logging() === 'debug') {
                msg(str);
            }
        }

        updateState = function (rfb, state, oldstate, mesg) {
            switch (state) {
                case 'failed':
                case 'fatal':
                    msg("noVNC sent '" + state +
                        "' state during pass " + pass +
                        ", iteration " + iteration +
                        " frame " + frame_idx);
                    test_state = 'failed';
                    break;
                case 'loaded':
                    document.getElementById('startButton').disabled = false;
                    break;
            }
            if (typeof mesg !== 'undefined') {
                document.getElementById('VNC_status').innerHTML = mesg;
            }
        }

        function do_test() {
            document.getElementById('startButton').value = "Running";
            document.getElementById('startButton').disabled = true;

            mode = 'perftest'; // full-speed
            passes = document.getElementById('passes').value;
            pass = 1;
            encIdx = 0;

            // Render each encoding once for each pass
            iterations = 1;

            // Initialize stats counters
            for (i = 0; i < encOrder.length; i++) {
                enc = encOrder[i];
                encTot[i] = 0;
                encMin[i] = 2<<23; // Something sufficiently large
                encMax[i] = 0;
            }
            passCur = 0;
            passTot = 0;
            passMin = 2<<23;
            passMax = 0;

            // Fire away
            next_encoding();
        }

        function next_encoding() {
            var encName;

            if (encIdx >= encOrder.length) {
                // Accumulate pass stats
                if (passCur < passMin) {
                    passMin = passCur;
                }
                if (passCur > passMax) {
                    passMax = passCur;
                }
                msg("Pass " + pass + " took " + passCur + " ms");

                passCur = 0;
                encIdx = 0;
                pass += 1;
                if (pass > passes) {
                    // We are finished
                    // Shut-off event interception
                    rfb.get_mouse().ungrab();
                    rfb.get_keyboard().ungrab();
                    document.getElementById('startButton').disabled = false;
                    document.getElementById('startButton').value = "Start";
                    finish_passes();
                    return; // We are finished, terminate
                }
            }

            encName = encOrder[encIdx];
            dbgmsg("Rendering pass " + pass + " encoding '" + encName + "'");

            VNC_frame_data = VNC_frame_data_multi[encName];
            iteration = 0;
            start_time = (new Date()).getTime();

            next_iteration();
        }

        // Finished rendering current encoding
        function finish() {
            var total_time, end_time = (new Date()).getTime();
            total_time = end_time - start_time;

            dbgmsg("Encoding " + encOrder[encIdx] + " took " + total_time + "ms");

            passCur += total_time;
            passTot += total_time;

            // Accumulate stats
            encTot[encIdx] += total_time;
            if (total_time < encMin[encIdx]) {
                encMin[encIdx] = total_time;
            }
            if (total_time > encMax[encIdx]) {
                encMax[encIdx] = total_time;
            }

            encIdx += 1;
            next_encoding();
        }

        function finish_passes() {
            var i, enc, avg, passAvg;
            msg("STATS (for " + passes + " passes)");
            // Encoding stats
            for (i = 0; i < encOrder.length; i++) {
                enc = encOrder[i];
                avg = (encTot[i] / passes).toFixed(1);
                msg("  " + enc + ": " + encTot[i] + " ms, " +
                    encMin[i] + "/" + avg + "/" + encMax[i] +
                    " (min/avg/max)");

            }
            // Print pass stats
            passAvg = (passTot / passes).toFixed(1);
            msg("\n  All passes: " + passTot + " ms, " +
                passMin + "/" + passAvg + "/" + passMax +
                " (min/avg/max)");
        }

        window.onscriptsload = function() {
            var i, enc;
            dbgmsg("Frame lengths:");
            for (i = 0; i < encOrder.length; i++) {
                enc = encOrder[i];
                dbgmsg("  " + enc + ": " + VNC_frame_data_multi[enc].length);
            }
            document.getElementById('startButton').disabled = false;
        }
    </script>
</html>