OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <html> | |
3 <head> | |
4 <script src="../../../bower_components/platform/platform.js"></script> | |
5 <link rel="import" href="../../../bower_components/polymer/polymer.html"> | |
6 <link rel="import" href="../../ct-commit-log-mock.html"> | |
7 <link rel="import" href="../../ct-failures.html"> | |
8 </head> | |
9 <body> | |
10 <label><input type="checkbox" id="collect" checked> Collect timing</label> (this
checkbox takes a long time to register clicks.) | |
11 <p>Times in ms: | |
12 <ul> | |
13 <template id="report" repeat="{{results}}"> | |
14 <li>{{time}}</li> | |
15 </template> | |
16 </ul> | |
17 <script> | |
18 (function() { | |
19 'use strict'; | |
20 | |
21 var model = {results: []}; | |
22 document.querySelector('#report').model = model; | |
23 | |
24 var analyzer = new CTFailures(CTCommitLogMock()); | |
25 var big_alerts = net.json('big-alerts.json'); | |
26 net.json = function(url) { | |
27 if (url === 'https://sheriff-o-matic.appspot.com/alerts') { | |
28 return big_alerts.then(function(alerts) { | |
29 return Object.clone(alerts, /*deep=*/true); | |
30 }); | |
31 } else if (url === 'https://trooper-o-matic.appspot.com/alerts') { | |
32 return Promise.resolve({}); | |
33 } else { | |
34 return Promise.reject(new Error('Unexpected URL: ' + url)); | |
35 } | |
36 }; | |
37 | |
38 function requestAnimationFramePromise() { | |
39 return new Promise(function(resolve, reject) { | |
40 requestAnimationFrame(resolve); | |
41 }); | |
42 } | |
43 | |
44 function waitForCollecting() { | |
45 var checkbox = document.querySelector('#collect'); | |
46 if (checkbox.checked) { | |
47 return Promise.resolve(); | |
48 } else { | |
49 return new Promise(function(resolve, reject) { | |
50 function resumeCollecting(e) { | |
51 if (checkbox.checked) { | |
52 checkbox.removeEventListener(resumeCollecting); | |
53 resolve(); | |
54 } | |
55 } | |
56 checkbox.addEventListener('change', resumeCollecting); | |
57 }); | |
58 } | |
59 } | |
60 | |
61 // A Promise version of "while(true) iteration()". | |
62 function forever(iteration) { | |
63 function loop() { | |
64 iteration().then(loop, function(e) { console.error(e, e.stack); }); | |
65 } | |
66 loop(); | |
67 } | |
68 | |
69 big_alerts.then(function() { | |
70 forever(function() { | |
71 var start = window.performance.now(); | |
72 return analyzer.update().then(function() { | |
73 var end = window.performance.now(); | |
74 model.results.push({time: end - start}); | |
75 // Let the browser paint the result, and stop timing when the tab is hidd
en | |
76 // or the checkbox is unchecked. | |
77 return waitForCollecting().then(requestAnimationFramePromise); | |
78 }) | |
79 }); | |
80 }); | |
81 | |
82 })(); | |
83 </script> | |
84 </body> | |
85 </html> | |
OLD | NEW |