Commit a8eea879 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[tools] Port more tools to ES6 classes

Convert Profile, CodeMap and their helpers to ES6 classes.
Code cleanup will happen in a separate step.

Bug: v8:10667
Change-Id: Icfb28f6d9ef7f00efba93b347fdf210a9af36a49
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2509591
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70969}
parent 73ed5430
...@@ -25,12 +25,7 @@ ...@@ -25,12 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import { CodeMap } from "../../../tools/codemap.mjs"; import { CodeMap, CodeEntry } from "../../../tools/codemap.mjs";
function newCodeEntry(size, name) {
return new CodeMap.CodeEntry(size, name);
};
function assertEntry(codeMap, expected_name, addr) { function assertEntry(codeMap, expected_name, addr) {
var entry = codeMap.findEntry(addr); var entry = codeMap.findEntry(addr);
...@@ -46,9 +41,9 @@ function assertNoEntry(codeMap, addr) { ...@@ -46,9 +41,9 @@ function assertNoEntry(codeMap, addr) {
(function testLibrariesAndStaticCode() { (function testLibrariesAndStaticCode() {
var codeMap = new CodeMap(); var codeMap = new CodeMap();
codeMap.addLibrary(0x1500, newCodeEntry(0x3000, 'lib1')); codeMap.addLibrary(0x1500, new CodeEntry(0x3000, 'lib1'));
codeMap.addLibrary(0x15500, newCodeEntry(0x5000, 'lib2')); codeMap.addLibrary(0x15500, new CodeEntry(0x5000, 'lib2'));
codeMap.addLibrary(0x155500, newCodeEntry(0x10000, 'lib3')); codeMap.addLibrary(0x155500, new CodeEntry(0x10000, 'lib3'));
assertNoEntry(codeMap, 0); assertNoEntry(codeMap, 0);
assertNoEntry(codeMap, 0x1500 - 1); assertNoEntry(codeMap, 0x1500 - 1);
assertEntry(codeMap, 'lib1', 0x1500); assertEntry(codeMap, 'lib1', 0x1500);
...@@ -70,9 +65,9 @@ function assertNoEntry(codeMap, addr) { ...@@ -70,9 +65,9 @@ function assertNoEntry(codeMap, addr) {
assertNoEntry(codeMap, 0x155500 + 0x10000); assertNoEntry(codeMap, 0x155500 + 0x10000);
assertNoEntry(codeMap, 0xFFFFFFFF); assertNoEntry(codeMap, 0xFFFFFFFF);
codeMap.addStaticCode(0x1510, newCodeEntry(0x30, 'lib1-f1')); codeMap.addStaticCode(0x1510, new CodeEntry(0x30, 'lib1-f1'));
codeMap.addStaticCode(0x1600, newCodeEntry(0x50, 'lib1-f2')); codeMap.addStaticCode(0x1600, new CodeEntry(0x50, 'lib1-f2'));
codeMap.addStaticCode(0x15520, newCodeEntry(0x100, 'lib2-f1')); codeMap.addStaticCode(0x15520, new CodeEntry(0x100, 'lib2-f1'));
assertEntry(codeMap, 'lib1', 0x1500); assertEntry(codeMap, 'lib1', 0x1500);
assertEntry(codeMap, 'lib1', 0x1510 - 1); assertEntry(codeMap, 'lib1', 0x1510 - 1);
assertEntry(codeMap, 'lib1-f1', 0x1510); assertEntry(codeMap, 'lib1-f1', 0x1510);
...@@ -96,10 +91,10 @@ function assertNoEntry(codeMap, addr) { ...@@ -96,10 +91,10 @@ function assertNoEntry(codeMap, addr) {
(function testDynamicCode() { (function testDynamicCode() {
var codeMap = new CodeMap(); var codeMap = new CodeMap();
codeMap.addCode(0x1500, newCodeEntry(0x200, 'code1')); codeMap.addCode(0x1500, new CodeEntry(0x200, 'code1'));
codeMap.addCode(0x1700, newCodeEntry(0x100, 'code2')); codeMap.addCode(0x1700, new CodeEntry(0x100, 'code2'));
codeMap.addCode(0x1900, newCodeEntry(0x50, 'code3')); codeMap.addCode(0x1900, new CodeEntry(0x50, 'code3'));
codeMap.addCode(0x1950, newCodeEntry(0x10, 'code4')); codeMap.addCode(0x1950, new CodeEntry(0x10, 'code4'));
assertNoEntry(codeMap, 0); assertNoEntry(codeMap, 0);
assertNoEntry(codeMap, 0x1500 - 1); assertNoEntry(codeMap, 0x1500 - 1);
assertEntry(codeMap, 'code1', 0x1500); assertEntry(codeMap, 'code1', 0x1500);
...@@ -122,8 +117,8 @@ function assertNoEntry(codeMap, addr) { ...@@ -122,8 +117,8 @@ function assertNoEntry(codeMap, addr) {
(function testCodeMovesAndDeletions() { (function testCodeMovesAndDeletions() {
var codeMap = new CodeMap(); var codeMap = new CodeMap();
codeMap.addCode(0x1500, newCodeEntry(0x200, 'code1')); codeMap.addCode(0x1500, new CodeEntry(0x200, 'code1'));
codeMap.addCode(0x1700, newCodeEntry(0x100, 'code2')); codeMap.addCode(0x1700, new CodeEntry(0x100, 'code2'));
assertEntry(codeMap, 'code1', 0x1500); assertEntry(codeMap, 'code1', 0x1500);
assertEntry(codeMap, 'code2', 0x1700); assertEntry(codeMap, 'code2', 0x1700);
codeMap.moveCode(0x1500, 0x1800); codeMap.moveCode(0x1500, 0x1800);
...@@ -139,8 +134,8 @@ function assertNoEntry(codeMap, addr) { ...@@ -139,8 +134,8 @@ function assertNoEntry(codeMap, addr) {
(function testDynamicNamesDuplicates() { (function testDynamicNamesDuplicates() {
var codeMap = new CodeMap(); var codeMap = new CodeMap();
// Code entries with same names but different addresses. // Code entries with same names but different addresses.
codeMap.addCode(0x1500, newCodeEntry(0x200, 'code')); codeMap.addCode(0x1500, new CodeEntry(0x200, 'code'));
codeMap.addCode(0x1700, newCodeEntry(0x100, 'code')); codeMap.addCode(0x1700, new CodeEntry(0x100, 'code'));
assertEntry(codeMap, 'code', 0x1500); assertEntry(codeMap, 'code', 0x1500);
assertEntry(codeMap, 'code {1}', 0x1700); assertEntry(codeMap, 'code {1}', 0x1700);
// Test name stability. // Test name stability.
...@@ -151,9 +146,9 @@ function assertNoEntry(codeMap, addr) { ...@@ -151,9 +146,9 @@ function assertNoEntry(codeMap, addr) {
(function testStaticEntriesExport() { (function testStaticEntriesExport() {
var codeMap = new CodeMap(); var codeMap = new CodeMap();
codeMap.addStaticCode(0x1500, newCodeEntry(0x3000, 'lib1')); codeMap.addStaticCode(0x1500, new CodeEntry(0x3000, 'lib1'));
codeMap.addStaticCode(0x15500, newCodeEntry(0x5000, 'lib2')); codeMap.addStaticCode(0x15500, new CodeEntry(0x5000, 'lib2'));
codeMap.addStaticCode(0x155500, newCodeEntry(0x10000, 'lib3')); codeMap.addStaticCode(0x155500, new CodeEntry(0x10000, 'lib3'));
var allStatics = codeMap.getAllStaticEntries(); var allStatics = codeMap.getAllStaticEntries();
allStatics = allStatics.map(String); allStatics = allStatics.map(String);
allStatics.sort(); allStatics.sort();
...@@ -163,9 +158,9 @@ function assertNoEntry(codeMap, addr) { ...@@ -163,9 +158,9 @@ function assertNoEntry(codeMap, addr) {
(function testDynamicEntriesExport() { (function testDynamicEntriesExport() {
var codeMap = new CodeMap(); var codeMap = new CodeMap();
codeMap.addCode(0x1500, newCodeEntry(0x200, 'code1')); codeMap.addCode(0x1500, new CodeEntry(0x200, 'code1'));
codeMap.addCode(0x1700, newCodeEntry(0x100, 'code2')); codeMap.addCode(0x1700, new CodeEntry(0x100, 'code2'));
codeMap.addCode(0x1900, newCodeEntry(0x50, 'code3')); codeMap.addCode(0x1900, new CodeEntry(0x50, 'code3'));
var allDynamics = codeMap.getAllDynamicEntries(); var allDynamics = codeMap.getAllDynamicEntries();
allDynamics = allDynamics.map(String); allDynamics = allDynamics.map(String);
allDynamics.sort(); allDynamics.sort();
......
This diff is collapsed.
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import { LogReader, parseString } from "./logreader.mjs"; import { LogReader, parseString } from "./logreader.mjs";
import { CodeMap } from "./codemap.mjs"; import { CodeMap, CodeEntry } from "./codemap.mjs";
export { export {
ArgumentsProcessor, UnixCppEntriesProvider, ArgumentsProcessor, UnixCppEntriesProvider,
WindowsCppEntriesProvider, MacCppEntriesProvider, WindowsCppEntriesProvider, MacCppEntriesProvider,
...@@ -11,57 +11,58 @@ export { ...@@ -11,57 +11,58 @@ export {
import { inherits } from "./tickprocessor.mjs"; import { inherits } from "./tickprocessor.mjs";
export function CppProcessor(cppEntriesProvider, timedRange, pairwiseTimedRange) { export class CppProcessor extends LogReader {
LogReader.call(this, { constructor(cppEntriesProvider, timedRange, pairwiseTimedRange) {
'shared-library': { parsers: [parseString, parseInt, parseInt, parseInt], super({}, timedRange, pairwiseTimedRange);
this.dispatchTable_ = {
'shared-library': {
parsers: [parseString, parseInt, parseInt, parseInt],
processor: this.processSharedLibrary } processor: this.processSharedLibrary }
}, timedRange, pairwiseTimedRange); };
this.cppEntriesProvider_ = cppEntriesProvider;
this.codeMap_ = new CodeMap();
this.lastLogFileName_ = null;
}
this.cppEntriesProvider_ = cppEntriesProvider; /**
this.codeMap_ = new CodeMap(); * @override
this.lastLogFileName_ = null; */
} printError(str) {
inherits(CppProcessor, LogReader); print(str);
};
/** processLogFile(fileName) {
* @override this.lastLogFileName_ = fileName;
*/ var line;
CppProcessor.prototype.printError = function(str) { while (line = readline()) {
print(str); this.processLogLine(line);
}; }
};
CppProcessor.prototype.processLogFile = function(fileName) { processLogFileInTest(fileName) {
this.lastLogFileName_ = fileName; // Hack file name to avoid dealing with platform specifics.
var line; this.lastLogFileName_ = 'v8.log';
while (line = readline()) { var contents = readFile(fileName);
this.processLogLine(line); this.processLogChunk(contents);
} };
};
CppProcessor.prototype.processLogFileInTest = function(fileName) { processSharedLibrary(name, startAddr, endAddr, aslrSlide) {
// Hack file name to avoid dealing with platform specifics. var self = this;
this.lastLogFileName_ = 'v8.log'; var libFuncs = this.cppEntriesProvider_.parseVmSymbols(
var contents = readFile(fileName); name, startAddr, endAddr, aslrSlide, function(fName, fStart, fEnd) {
this.processLogChunk(contents); var entry = new CodeEntry(fEnd - fStart, fName, 'CPP');
}; self.codeMap_.addStaticCode(fStart, entry);
});
};
CppProcessor.prototype.processSharedLibrary = function( dumpCppSymbols() {
name, startAddr, endAddr, aslrSlide) { var staticEntries = this.codeMap_.getAllStaticEntriesWithAddresses();
var self = this; var total = staticEntries.length;
var libFuncs = this.cppEntriesProvider_.parseVmSymbols( for (var i = 0; i < total; ++i) {
name, startAddr, endAddr, aslrSlide, function(fName, fStart, fEnd) { var entry = staticEntries[i];
var entry = new CodeMap.CodeEntry(fEnd - fStart, fName, 'CPP'); var printValues = ['cpp', '0x' + entry[0].toString(16), entry[1].size,
self.codeMap_.addStaticCode(fStart, entry); '"' + entry[1].name + '"'];
}); print(printValues.join(','));
}; }
CppProcessor.prototype.dumpCppSymbols = function() {
var staticEntries = this.codeMap_.getAllStaticEntriesWithAddresses();
var total = staticEntries.length;
for (var i = 0; i < total; ++i) {
var entry = staticEntries[i];
var printValues = ['cpp', '0x' + entry[0].toString(16), entry[1].size,
'"' + entry[1].name + '"'];
print(printValues.join(','));
} }
}; }
...@@ -34,4 +34,4 @@ fi ...@@ -34,4 +34,4 @@ fi
# nm spits out 'no symbols found' messages to stderr. # nm spits out 'no symbols found' messages to stderr.
cat $log_file | $d8_exec --enable-os-system \ cat $log_file | $d8_exec --enable-os-system \
--module $tools_path/tickprocessor-driver.mjs -- $@ 2>/dev/null --module $tools_path/tickprocessor-driver.mjs -- $@
This diff is collapsed.
...@@ -36,31 +36,30 @@ export function inherits(childCtor, parentCtor) { ...@@ -36,31 +36,30 @@ export function inherits(childCtor, parentCtor) {
}; };
function V8Profile(separateIc, separateBytecodes, separateBuiltins, class V8Profile extends Profile {
separateStubs) { static IC_RE =
Profile.call(this); /^(LoadGlobalIC: )|(Handler: )|(?:CallIC|LoadIC|StoreIC)|(?:Builtin: (?:Keyed)?(?:Load|Store)IC_)/;
var regexps = []; static BYTECODES_RE = /^(BytecodeHandler: )/;
if (!separateIc) regexps.push(V8Profile.IC_RE); static BUILTINS_RE = /^(Builtin: )/;
if (!separateBytecodes) regexps.push(V8Profile.BYTECODES_RE); static STUBS_RE = /^(Stub: )/;
if (!separateBuiltins) regexps.push(V8Profile.BUILTINS_RE);
if (!separateStubs) regexps.push(V8Profile.STUBS_RE); constructor(separateIc, separateBytecodes, separateBuiltins, separateStubs) {
if (regexps.length > 0) { super();
this.skipThisFunction = function(name) { var regexps = [];
for (var i=0; i<regexps.length; i++) { if (!separateIc) regexps.push(V8Profile.IC_RE);
if (regexps[i].test(name)) return true; if (!separateBytecodes) regexps.push(V8Profile.BYTECODES_RE);
} if (!separateBuiltins) regexps.push(V8Profile.BUILTINS_RE);
return false; if (!separateStubs) regexps.push(V8Profile.STUBS_RE);
}; if (regexps.length > 0) {
this.skipThisFunction = function(name) {
for (var i=0; i<regexps.length; i++) {
if (regexps[i].test(name)) return true;
}
return false;
};
}
} }
}; }
inherits(V8Profile, Profile);
V8Profile.IC_RE =
/^(LoadGlobalIC: )|(Handler: )|(?:CallIC|LoadIC|StoreIC)|(?:Builtin: (?:Keyed)?(?:Load|Store)IC_)/;
V8Profile.BYTECODES_RE = /^(BytecodeHandler: )/
V8Profile.BUILTINS_RE = /^(Builtin: )/
V8Profile.STUBS_RE = /^(Stub: )/
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment