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 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import { CodeMap } from "../../../tools/codemap.mjs";
function newCodeEntry(size, name) {
return new CodeMap.CodeEntry(size, name);
};
import { CodeMap, CodeEntry } from "../../../tools/codemap.mjs";
function assertEntry(codeMap, expected_name, addr) {
var entry = codeMap.findEntry(addr);
......@@ -46,9 +41,9 @@ function assertNoEntry(codeMap, addr) {
(function testLibrariesAndStaticCode() {
var codeMap = new CodeMap();
codeMap.addLibrary(0x1500, newCodeEntry(0x3000, 'lib1'));
codeMap.addLibrary(0x15500, newCodeEntry(0x5000, 'lib2'));
codeMap.addLibrary(0x155500, newCodeEntry(0x10000, 'lib3'));
codeMap.addLibrary(0x1500, new CodeEntry(0x3000, 'lib1'));
codeMap.addLibrary(0x15500, new CodeEntry(0x5000, 'lib2'));
codeMap.addLibrary(0x155500, new CodeEntry(0x10000, 'lib3'));
assertNoEntry(codeMap, 0);
assertNoEntry(codeMap, 0x1500 - 1);
assertEntry(codeMap, 'lib1', 0x1500);
......@@ -70,9 +65,9 @@ function assertNoEntry(codeMap, addr) {
assertNoEntry(codeMap, 0x155500 + 0x10000);
assertNoEntry(codeMap, 0xFFFFFFFF);
codeMap.addStaticCode(0x1510, newCodeEntry(0x30, 'lib1-f1'));
codeMap.addStaticCode(0x1600, newCodeEntry(0x50, 'lib1-f2'));
codeMap.addStaticCode(0x15520, newCodeEntry(0x100, 'lib2-f1'));
codeMap.addStaticCode(0x1510, new CodeEntry(0x30, 'lib1-f1'));
codeMap.addStaticCode(0x1600, new CodeEntry(0x50, 'lib1-f2'));
codeMap.addStaticCode(0x15520, new CodeEntry(0x100, 'lib2-f1'));
assertEntry(codeMap, 'lib1', 0x1500);
assertEntry(codeMap, 'lib1', 0x1510 - 1);
assertEntry(codeMap, 'lib1-f1', 0x1510);
......@@ -96,10 +91,10 @@ function assertNoEntry(codeMap, addr) {
(function testDynamicCode() {
var codeMap = new CodeMap();
codeMap.addCode(0x1500, newCodeEntry(0x200, 'code1'));
codeMap.addCode(0x1700, newCodeEntry(0x100, 'code2'));
codeMap.addCode(0x1900, newCodeEntry(0x50, 'code3'));
codeMap.addCode(0x1950, newCodeEntry(0x10, 'code4'));
codeMap.addCode(0x1500, new CodeEntry(0x200, 'code1'));
codeMap.addCode(0x1700, new CodeEntry(0x100, 'code2'));
codeMap.addCode(0x1900, new CodeEntry(0x50, 'code3'));
codeMap.addCode(0x1950, new CodeEntry(0x10, 'code4'));
assertNoEntry(codeMap, 0);
assertNoEntry(codeMap, 0x1500 - 1);
assertEntry(codeMap, 'code1', 0x1500);
......@@ -122,8 +117,8 @@ function assertNoEntry(codeMap, addr) {
(function testCodeMovesAndDeletions() {
var codeMap = new CodeMap();
codeMap.addCode(0x1500, newCodeEntry(0x200, 'code1'));
codeMap.addCode(0x1700, newCodeEntry(0x100, 'code2'));
codeMap.addCode(0x1500, new CodeEntry(0x200, 'code1'));
codeMap.addCode(0x1700, new CodeEntry(0x100, 'code2'));
assertEntry(codeMap, 'code1', 0x1500);
assertEntry(codeMap, 'code2', 0x1700);
codeMap.moveCode(0x1500, 0x1800);
......@@ -139,8 +134,8 @@ function assertNoEntry(codeMap, addr) {
(function testDynamicNamesDuplicates() {
var codeMap = new CodeMap();
// Code entries with same names but different addresses.
codeMap.addCode(0x1500, newCodeEntry(0x200, 'code'));
codeMap.addCode(0x1700, newCodeEntry(0x100, 'code'));
codeMap.addCode(0x1500, new CodeEntry(0x200, 'code'));
codeMap.addCode(0x1700, new CodeEntry(0x100, 'code'));
assertEntry(codeMap, 'code', 0x1500);
assertEntry(codeMap, 'code {1}', 0x1700);
// Test name stability.
......@@ -151,9 +146,9 @@ function assertNoEntry(codeMap, addr) {
(function testStaticEntriesExport() {
var codeMap = new CodeMap();
codeMap.addStaticCode(0x1500, newCodeEntry(0x3000, 'lib1'));
codeMap.addStaticCode(0x15500, newCodeEntry(0x5000, 'lib2'));
codeMap.addStaticCode(0x155500, newCodeEntry(0x10000, 'lib3'));
codeMap.addStaticCode(0x1500, new CodeEntry(0x3000, 'lib1'));
codeMap.addStaticCode(0x15500, new CodeEntry(0x5000, 'lib2'));
codeMap.addStaticCode(0x155500, new CodeEntry(0x10000, 'lib3'));
var allStatics = codeMap.getAllStaticEntries();
allStatics = allStatics.map(String);
allStatics.sort();
......@@ -163,9 +158,9 @@ function assertNoEntry(codeMap, addr) {
(function testDynamicEntriesExport() {
var codeMap = new CodeMap();
codeMap.addCode(0x1500, newCodeEntry(0x200, 'code1'));
codeMap.addCode(0x1700, newCodeEntry(0x100, 'code2'));
codeMap.addCode(0x1900, newCodeEntry(0x50, 'code3'));
codeMap.addCode(0x1500, new CodeEntry(0x200, 'code1'));
codeMap.addCode(0x1700, new CodeEntry(0x100, 'code2'));
codeMap.addCode(0x1900, new CodeEntry(0x50, 'code3'));
var allDynamics = codeMap.getAllDynamicEntries();
allDynamics = allDynamics.map(String);
allDynamics.sort();
......
This diff is collapsed.
......@@ -3,7 +3,7 @@
// found in the LICENSE file.
import { LogReader, parseString } from "./logreader.mjs";
import { CodeMap } from "./codemap.mjs";
import { CodeMap, CodeEntry } from "./codemap.mjs";
export {
ArgumentsProcessor, UnixCppEntriesProvider,
WindowsCppEntriesProvider, MacCppEntriesProvider,
......@@ -11,57 +11,58 @@ export {
import { inherits } from "./tickprocessor.mjs";
export function CppProcessor(cppEntriesProvider, timedRange, pairwiseTimedRange) {
LogReader.call(this, {
'shared-library': { parsers: [parseString, parseInt, parseInt, parseInt],
export class CppProcessor extends LogReader {
constructor(cppEntriesProvider, timedRange, pairwiseTimedRange) {
super({}, timedRange, pairwiseTimedRange);
this.dispatchTable_ = {
'shared-library': {
parsers: [parseString, parseInt, parseInt, parseInt],
processor: this.processSharedLibrary }
}, timedRange, pairwiseTimedRange);
};
this.cppEntriesProvider_ = cppEntriesProvider;
this.codeMap_ = new CodeMap();
this.lastLogFileName_ = null;
}
this.cppEntriesProvider_ = cppEntriesProvider;
this.codeMap_ = new CodeMap();
this.lastLogFileName_ = null;
}
inherits(CppProcessor, LogReader);
/**
* @override
*/
printError(str) {
print(str);
};
/**
* @override
*/
CppProcessor.prototype.printError = function(str) {
print(str);
};
processLogFile(fileName) {
this.lastLogFileName_ = fileName;
var line;
while (line = readline()) {
this.processLogLine(line);
}
};
CppProcessor.prototype.processLogFile = function(fileName) {
this.lastLogFileName_ = fileName;
var line;
while (line = readline()) {
this.processLogLine(line);
}
};
processLogFileInTest(fileName) {
// Hack file name to avoid dealing with platform specifics.
this.lastLogFileName_ = 'v8.log';
var contents = readFile(fileName);
this.processLogChunk(contents);
};
CppProcessor.prototype.processLogFileInTest = function(fileName) {
// Hack file name to avoid dealing with platform specifics.
this.lastLogFileName_ = 'v8.log';
var contents = readFile(fileName);
this.processLogChunk(contents);
};
processSharedLibrary(name, startAddr, endAddr, aslrSlide) {
var self = this;
var libFuncs = this.cppEntriesProvider_.parseVmSymbols(
name, startAddr, endAddr, aslrSlide, function(fName, fStart, fEnd) {
var entry = new CodeEntry(fEnd - fStart, fName, 'CPP');
self.codeMap_.addStaticCode(fStart, entry);
});
};
CppProcessor.prototype.processSharedLibrary = function(
name, startAddr, endAddr, aslrSlide) {
var self = this;
var libFuncs = this.cppEntriesProvider_.parseVmSymbols(
name, startAddr, endAddr, aslrSlide, function(fName, fStart, fEnd) {
var entry = new CodeMap.CodeEntry(fEnd - fStart, fName, 'CPP');
self.codeMap_.addStaticCode(fStart, entry);
});
};
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(','));
dumpCppSymbols() {
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
# nm spits out 'no symbols found' messages to stderr.
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) {
};
function V8Profile(separateIc, separateBytecodes, separateBuiltins,
separateStubs) {
Profile.call(this);
var regexps = [];
if (!separateIc) regexps.push(V8Profile.IC_RE);
if (!separateBytecodes) regexps.push(V8Profile.BYTECODES_RE);
if (!separateBuiltins) regexps.push(V8Profile.BUILTINS_RE);
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;
};
class V8Profile extends Profile {
static IC_RE =
/^(LoadGlobalIC: )|(Handler: )|(?:CallIC|LoadIC|StoreIC)|(?:Builtin: (?:Keyed)?(?:Load|Store)IC_)/;
static BYTECODES_RE = /^(BytecodeHandler: )/;
static BUILTINS_RE = /^(Builtin: )/;
static STUBS_RE = /^(Stub: )/;
constructor(separateIc, separateBytecodes, separateBuiltins, separateStubs) {
super();
var regexps = [];
if (!separateIc) regexps.push(V8Profile.IC_RE);
if (!separateBytecodes) regexps.push(V8Profile.BYTECODES_RE);
if (!separateBuiltins) regexps.push(V8Profile.BUILTINS_RE);
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