OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 var delegateList = { |
| 29 "load scripts" : load_scripts, |
| 30 "run" : run, |
| 31 } |
| 32 |
| 33 self.addEventListener("message", function(event) { |
| 34 var call = delegateList[event.data["call"]]; |
| 35 var result = call(event.data["args"]); |
| 36 }, false); |
| 37 |
| 38 |
| 39 function log(text) { |
| 40 self.postMessage({ "call" : "log", "args" : text }); |
| 41 } |
| 42 |
| 43 |
| 44 function display(content) { |
| 45 self.postMessage({ "call" : "display", "args" : content}); |
| 46 } |
| 47 |
| 48 |
| 49 function setRange(start, end) { |
| 50 self.postMessage({ "call" : "range", |
| 51 "args" : { "start" : start, "end" : end } }); |
| 52 } |
| 53 |
| 54 |
| 55 function time(name, fun) { |
| 56 log(name + "..."); |
| 57 var start = Date.now(); |
| 58 fun(); |
| 59 log(" took " + (Date.now() - start) / 1000 + "s.\n"); |
| 60 } |
| 61 |
| 62 |
| 63 function load_scripts(scripts) { |
| 64 time("Loading scripts", |
| 65 function() { for (var i in scripts) importScripts(scripts[i]); }); |
| 66 self.postMessage({ "call" : "script" }); |
| 67 } |
| 68 |
| 69 |
| 70 function run(args) { |
| 71 var file = args["file"]; |
| 72 var resx = args["resx"]; |
| 73 var resy = args["resy"]; |
| 74 var distortion = args["distortion"]; |
| 75 var range_start_override = args["range_start"]; |
| 76 var range_end_override = args["range_end"]; |
| 77 |
| 78 var reader = new FileReaderSync(); |
| 79 var content_lines; |
| 80 |
| 81 time("Reading log file (" + Math.round(file.size / 1024) + " kB)", |
| 82 function() { |
| 83 var content = reader.readAsText(file); |
| 84 content_lines = content.split("\n"); |
| 85 }); |
| 86 |
| 87 var input_file_name = "input_temp"; |
| 88 var output_file_name = "output.svg"; |
| 89 |
| 90 var psc = new PlotScriptComposer(resx, resy); |
| 91 var objects = 0; |
| 92 |
| 93 time("Analyzing data (" + content_lines.length + " entries)", |
| 94 function() { |
| 95 var line_cursor = 0; |
| 96 var input = function() { return content_lines[line_cursor++]; }; |
| 97 psc.collectData(input, distortion); |
| 98 psc.findPlotRange(range_start_override, |
| 99 range_end_override, |
| 100 setRange); |
| 101 }); |
| 102 |
| 103 time("Assembling plot script", |
| 104 function() { |
| 105 var plot_script = ""; |
| 106 var output = function(output) { plot_script += output + "\n"; }; |
| 107 output("set terminal svg size " + resx + "," + resy + |
| 108 " enhanced font \"Helvetica,10\""); |
| 109 output("set output \""+ output_file_name + "\""); |
| 110 objects = psc.assembleOutput(output); |
| 111 if (FS.findObject(input_file_name)) { |
| 112 FS.deleteFile(input_file_name); |
| 113 } |
| 114 var arrc = Module["intArrayFromString"](plot_script, true); |
| 115 FS.createDataFile("/", input_file_name, arrc); |
| 116 }); |
| 117 |
| 118 time("Running Gnuplot (" + objects + " objects)", |
| 119 function() { Module.run([input_file_name]); }); |
| 120 |
| 121 display(FS.findObject(output_file_name)); |
| 122 } |
| 123 |
| 124 |
| 125 var Module = { |
| 126 "noInitialRun": true, |
| 127 print: function(text) { |
| 128 self.postMessage({"call": "error", "args": text}); |
| 129 }, |
| 130 printErr: function(text) { |
| 131 self.postMessage({"call": "error", "args": text}); |
| 132 }, |
| 133 }; |
| 134 |
OLD | NEW |