diff options
author | 2017-09-01 11:57:47 +0800 | |
---|---|---|
committer | 2017-09-01 11:57:58 +0800 | |
commit | 57dbba269d19bc59fad89160200bb2dbcccb9003 (patch) | |
tree | d466041ceffa2161124ca79a48b3e077777c74b8 /usecaseui-common/src/main/webapp/static/fusion/raptor/dy3/js/phantom-perf.js | |
parent | 4ff32341a0af1972b44a7410e76e9b231131e7ab (diff) |
Upload Monitor function code
Change-Id: I33ad76221b4cb771a298ff240245fc24be664efb
Issue-Id: USECASEUI-6
Signed-off-by: shentao <shentao@chinamobile.com>
Diffstat (limited to 'usecaseui-common/src/main/webapp/static/fusion/raptor/dy3/js/phantom-perf.js')
-rw-r--r-- | usecaseui-common/src/main/webapp/static/fusion/raptor/dy3/js/phantom-perf.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/usecaseui-common/src/main/webapp/static/fusion/raptor/dy3/js/phantom-perf.js b/usecaseui-common/src/main/webapp/static/fusion/raptor/dy3/js/phantom-perf.js new file mode 100644 index 00000000..b98c3f03 --- /dev/null +++ b/usecaseui-common/src/main/webapp/static/fusion/raptor/dy3/js/phantom-perf.js @@ -0,0 +1,94 @@ +// dygraphs command-line performance benchmark. +// +// Invoke as: +// +// phantomjs phantom-perf.js 1000 100 5 +// +// If the test succeeds, it will print out something like: +// +// 1000/100/5: 1309.4+/-43.4 ms (1284, 1245, 1336, 1346, 1336) +// +// This is mean +/- standard deviation, followed by a list of the individual +// times for each repetition, in milliseconds. + +var system = require('system'), + fs = require('fs'); + +var tmpfile = "tmp-dygraph-test-params.js"; +var url = 'tests/dygraph-many-points-benchmark.html'; + +function fail(msg){ + console.warn(msg); + phantom.exit(1); +} + +function assert(condition, msg){ + if (condition) return; + fail(msg); +} + +var config_file_template = + "document.getElementById('points').value = (points);\n" + + "document.getElementById('series').value = (series);\n" + + "document.getElementById('repetitions').value = (repetitions);\n"; + +var RunBenchmark = function(points, series, repetitions, done_callback) { + var page = require('webpage').create(); + + // page.evalute() is seriously locked down. + // This was the only way I could find to pass the parameters to the page. + fs.write(tmpfile, + config_file_template + .replace("(points)", points) + .replace("(series)", series) + .replace("(repetitions)", repetitions), + "w"); + + page.open(url, function(status) { + if (status !== 'success') { + console.warn('Page status: ' + status); + console.log(page); + phantom.exit(); + } + + assert(page.injectJs(tmpfile), "Unable to inject JS."); + fs.remove(tmpfile); + + var start = new Date().getTime(); + var rep_times = page.evaluate(function() { + var rep_times = updatePlot(); + return rep_times; + }); + var end = new Date().getTime(); + var elapsed = (end - start) / 1000; + done_callback(rep_times); + }); +}; + + +var points, series, repetitions; +if (4 != system.args.length) { + console.warn('Usage: phantomjs phantom-driver.js (points) (series) (repititions)'); + phantom.exit(); +} + +points = parseInt(system.args[1]); +series = parseInt(system.args[2]); +repetitions = parseInt(system.args[3]); +assert(points != null, "Couldn't parse " + system.args[1]); +assert(series != null, "Couldn't parse " + system.args[2]); +assert(repetitions != null, "Couldn't parse " + system.args[3]); + + +RunBenchmark(points, series, repetitions, function(rep_times) { + var mean = 0.0, std = 0.0; + rep_times.forEach(function(x) { mean += x; } ); + mean /= rep_times.length; + rep_times.forEach(function(x) { std += Math.pow(x - mean, 2); }); + std = Math.sqrt(std / (rep_times.length - 1)); + + console.log(points + '/' + series + '/' + repetitions + ': ' + + mean.toFixed(1) + '+/-' + std.toFixed(1) + ' ms (' + + rep_times.join(', ') + ')'); + phantom.exit(); +}); |