Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2011 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 // Load implementations from <project root>/tools. | |
| 29 // Files: tools/splaytree.js tools/codemap.js tools/csvparser.js | |
| 30 // Files: tools/consarray.js tools/profile.js tools/profile_view.js | |
| 31 // Files: tools/logreader.js | |
| 32 // Files: test/mjsunit/log-utils.js | |
| 33 // Flags: --allow_natives_syntax --log-runtime --prof | |
| 34 // Env: LOG_FILE_NAME | |
| 35 | |
|
Søren Thygesen Gjesse
2011/07/07 11:59:53
Please add a comment here to explain that first th
mnaganov (inactive)
2011/07/07 20:19:57
Done.
| |
| 36 %Log("test-start", []); | |
| 37 (function f(obj) { | |
| 38 obj.test = | |
| 39 (function a(j) { return function b() { return j; } })(100); | |
| 40 })(this); | |
| 41 %ProfilerPause(); | |
| 42 %CollectGarbage2(); | |
| 43 %Log("test-logging-done", []); | |
| 44 %LogCompiledFunctions(); | |
| 45 %Log("test-traversal-done", []); | |
| 46 %Log("test-stop", []); | |
| 47 | |
| 48 function parseState(s) { | |
| 49 switch (s) { | |
| 50 case "": return Profile.CodeState.COMPILED; | |
| 51 case "~": return Profile.CodeState.OPTIMIZABLE; | |
| 52 case "*": return Profile.CodeState.OPTIMIZED; | |
| 53 } | |
| 54 throw new Error("unknown code state: " + s); | |
| 55 } | |
| 56 | |
| 57 function LogProcessor() { | |
| 58 LogReader.call(this, { | |
| 59 'code-creation': { | |
| 60 parsers: [null, parseInt, parseInt, null, 'var-args'], | |
| 61 processor: this.processCodeCreation }, | |
| 62 'code-move': { parsers: [parseInt, parseInt], | |
| 63 processor: this.processCodeMove }, | |
| 64 'code-delete': { parsers: [parseInt], | |
| 65 processor: this.processCodeDelete }, | |
| 66 'sfi-move': { parsers: [parseInt, parseInt], | |
| 67 processor: this.processFunctionMove }, | |
| 68 'shared-library': null, | |
| 69 'profiler': null, | |
| 70 'tick': null }); | |
| 71 this.profile = new Profile(); | |
| 72 | |
| 73 } | |
| 74 LogProcessor.prototype.__proto__ = LogReader.prototype; | |
| 75 | |
| 76 LogProcessor.prototype.processCodeCreation = function( | |
| 77 type, start, size, name, maybe_func) { | |
| 78 if (type != "LazyCompile" && type != "Script" && type != "Function") return; | |
| 79 // Discard types to avoid discrepancies in "LazyCompile" vs. "Function". | |
| 80 type = ""; | |
| 81 if (maybe_func.length) { | |
| 82 var funcAddr = parseInt(maybe_func[0]); | |
| 83 var state = parseState(maybe_func[1]); | |
| 84 this.profile.addFuncCode(type, name, start, size, funcAddr, state); | |
| 85 } else { | |
| 86 this.profile.addCode(type, name, start, size); | |
| 87 } | |
| 88 }; | |
| 89 | |
| 90 LogProcessor.prototype.processCodeMove = function(from, to) { | |
| 91 this.profile.moveCode(from, to); | |
| 92 }; | |
| 93 | |
| 94 LogProcessor.prototype.processCodeDelete = function(start) { | |
| 95 this.profile.deleteCode(start); | |
| 96 }; | |
| 97 | |
| 98 LogProcessor.prototype.processFunctionMove = function(from, to) { | |
| 99 this.profile.moveFunc(from, to); | |
| 100 }; | |
| 101 | |
| 102 var log_reader = new SimpleLogReader(); | |
| 103 var line; | |
| 104 var logging_processor = new LogProcessor(); | |
| 105 while ((line = log_reader.nextLine()) !== "test-logging-done") { | |
| 106 logging_processor.processLogLine(line); | |
| 107 } | |
| 108 var traversal_processor = new LogProcessor(); | |
| 109 while ((line = log_reader.nextLine()) !== "test-traversal-done") { | |
| 110 traversal_processor.processLogLine(line); | |
| 111 } | |
| 112 | |
| 113 var logging_entries = | |
| 114 logging_processor.profile.codeMap_.getAllDynamicEntriesWithAddresses(); | |
| 115 assertTrue(!!logging_entries.length); | |
| 116 var traversal_entries = | |
| 117 traversal_processor.profile.codeMap_.getAllDynamicEntriesWithAddresses(); | |
| 118 assertTrue(!!traversal_entries.length); | |
| 119 | |
| 120 function addressComparator(entryA, entryB) { | |
| 121 return entryA[0] < entryB[0] ? -1 : (entryA[0] > entryB[0] ? 1 : 0); | |
| 122 } | |
| 123 | |
| 124 logging_entries.sort(addressComparator); | |
| 125 traversal_entries.sort(addressComparator); | |
| 126 | |
| 127 function entityNamesEqual(entityA, entityB) { | |
| 128 if ("getRawName" in entityB && | |
| 129 entityNamesEqual.builtins.indexOf(entityB.getRawName()) !== -1) { | |
| 130 return true; | |
| 131 } | |
| 132 if (entityNamesEqual.builtins.indexOf(entityB.getName()) !== -1) return true; | |
| 133 return entityA.getName() === entityB.getName(); | |
| 134 } | |
| 135 entityNamesEqual.builtins = | |
| 136 ["Boolean", "Function", "Number", "Object", | |
| 137 "Script", "String", "RegExp", "Date", "Error"]; | |
| 138 | |
| 139 function entitiesEqual(entityA, entityB) { | |
| 140 if (!entityA && entityB) return true; | |
|
Søren Thygesen Gjesse
2011/07/07 11:59:53
!entityA -> entityA == null?
mnaganov (inactive)
2011/07/07 20:19:57
Done.
| |
| 141 if (entityA && !entityB) return false; | |
|
Søren Thygesen Gjesse
2011/07/07 11:59:53
Ditto.
mnaganov (inactive)
2011/07/07 20:19:57
Done.
| |
| 142 return entityA.size === entityB.size && entityNamesEqual(entityA, entityB); | |
| 143 } | |
| 144 | |
| 145 var i = 0, j = 0, k = logging_entries.length, l = traversal_entries.length; | |
| 146 var comparison = []; | |
| 147 var equal = true; | |
|
Søren Thygesen Gjesse
2011/07/07 11:59:53
Please explain how this comparison works, and why
mnaganov (inactive)
2011/07/07 20:19:57
Done.
| |
| 148 while (i < k && j < l) { | |
| 149 var entryA = logging_entries[i], entryB = traversal_entries[j]; | |
| 150 var cmp = addressComparator(entryA, entryB); | |
| 151 var entityA = entryA[1], entityB = entryB[1]; | |
| 152 var address = entryA[0]; | |
| 153 if (cmp < 0) { | |
| 154 ++i; | |
| 155 entityB = null; | |
| 156 } else if (cmp > 0) { | |
| 157 ++j; | |
| 158 entityA = null; | |
| 159 address = entryB[0]; | |
| 160 } else { | |
| 161 ++i; | |
| 162 ++j; | |
| 163 } | |
| 164 var entities_equal = entitiesEqual(entityA, entityB); | |
| 165 if (!entities_equal) equal = false; | |
| 166 comparison.push([entities_equal, address, entityA, entityB]); | |
| 167 } | |
| 168 if (i < k) equal = false; | |
| 169 while (i < k) { | |
| 170 var entryA = logging_entries[i++]; | |
| 171 comparison.push([false, entryA[0], entryA[1], null]); | |
| 172 } | |
| 173 | |
| 174 if (!equal) { | |
| 175 for (var i = 0, l = comparison.length; i < l; ++i) { | |
| 176 var c = comparison[i]; | |
| 177 print((c[0] ? " " : "* ") + | |
| 178 c[1].toString(16) + " " + | |
| 179 (c[2] ? c[2] : "---") + " " + | |
| 180 (c[3] ? c[3] : "---")); | |
| 181 } | |
| 182 } | |
| 183 assertTrue(equal); | |
| OLD | NEW |