2009-04-27 13:50:42 +00:00
|
|
|
// Copyright 2009 the V8 project authors. All rights reserved.
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
function Profile(separateIc) {
|
|
|
|
devtools.profiler.Profile.call(this);
|
|
|
|
if (!separateIc) {
|
|
|
|
this.skipThisFunction = function(name) { return Profile.IC_RE.test(name); };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Profile.prototype = devtools.profiler.Profile.prototype;
|
|
|
|
|
|
|
|
|
|
|
|
Profile.IC_RE =
|
|
|
|
/^(?:CallIC|LoadIC|StoreIC)|(?:Builtin: (?:Keyed)?(?:Call|Load|Store)IC_)/;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A thin wrapper around shell's 'read' function showing a file name on error.
|
|
|
|
*/
|
|
|
|
function readFile(fileName) {
|
|
|
|
try {
|
|
|
|
return read(fileName);
|
|
|
|
} catch (e) {
|
|
|
|
print(fileName + ': ' + (e.message || e));
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-18 07:59:13 +00:00
|
|
|
function inherits(childCtor, parentCtor) {
|
|
|
|
function tempCtor() {};
|
|
|
|
tempCtor.prototype = parentCtor.prototype;
|
|
|
|
childCtor.prototype = new tempCtor();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-04-27 13:50:42 +00:00
|
|
|
function TickProcessor(
|
|
|
|
cppEntriesProvider, separateIc, ignoreUnknown, stateFilter) {
|
2009-06-18 07:59:13 +00:00
|
|
|
devtools.profiler.LogReader.call(this, {
|
|
|
|
'shared-library': { parsers: [null, parseInt, parseInt],
|
|
|
|
processor: this.processSharedLibrary },
|
|
|
|
'code-creation': {
|
|
|
|
parsers: [null, this.createAddressParser('code'), parseInt, null],
|
|
|
|
processor: this.processCodeCreation, backrefs: true },
|
|
|
|
'code-move': { parsers: [this.createAddressParser('code'),
|
|
|
|
this.createAddressParser('code-move-to')],
|
|
|
|
processor: this.processCodeMove, backrefs: true },
|
|
|
|
'code-delete': { parsers: [this.createAddressParser('code')],
|
|
|
|
processor: this.processCodeDelete, backrefs: true },
|
|
|
|
'tick': { parsers: [this.createAddressParser('code'),
|
|
|
|
this.createAddressParser('stack'), parseInt, 'var-args'],
|
|
|
|
processor: this.processTick, backrefs: true },
|
|
|
|
'profiler': null,
|
|
|
|
// Obsolete row types.
|
|
|
|
'code-allocate': null,
|
|
|
|
'begin-code-region': null,
|
|
|
|
'end-code-region': null });
|
|
|
|
|
2009-04-27 13:50:42 +00:00
|
|
|
this.cppEntriesProvider_ = cppEntriesProvider;
|
|
|
|
this.ignoreUnknown_ = ignoreUnknown;
|
|
|
|
this.stateFilter_ = stateFilter;
|
|
|
|
var ticks = this.ticks_ =
|
|
|
|
{ total: 0, unaccounted: 0, excluded: 0, gc: 0 };
|
|
|
|
|
|
|
|
Profile.prototype.handleUnknownCode = function(
|
|
|
|
operation, addr, opt_stackPos) {
|
|
|
|
var op = devtools.profiler.Profile.Operation;
|
|
|
|
switch (operation) {
|
|
|
|
case op.MOVE:
|
|
|
|
print('Code move event for unknown code: 0x' + addr.toString(16));
|
|
|
|
break;
|
|
|
|
case op.DELETE:
|
|
|
|
print('Code delete event for unknown code: 0x' + addr.toString(16));
|
|
|
|
break;
|
|
|
|
case op.TICK:
|
|
|
|
// Only unknown PCs (the first frame) are reported as unaccounted,
|
|
|
|
// otherwise tick balance will be corrupted (this behavior is compatible
|
|
|
|
// with the original tickprocessor.py script.)
|
|
|
|
if (opt_stackPos == 0) {
|
|
|
|
ticks.unaccounted++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.profile_ = new Profile(separateIc);
|
|
|
|
this.codeTypes_ = {};
|
|
|
|
// Count each tick as a time unit.
|
|
|
|
this.viewBuilder_ = new devtools.profiler.ViewBuilder(1);
|
|
|
|
this.lastLogFileName_ = null;
|
|
|
|
};
|
2009-06-18 07:59:13 +00:00
|
|
|
inherits(TickProcessor, devtools.profiler.LogReader);
|
2009-04-27 13:50:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.VmStates = {
|
|
|
|
JS: 0,
|
|
|
|
GC: 1,
|
|
|
|
COMPILER: 2,
|
|
|
|
OTHER: 3,
|
|
|
|
EXTERNAL: 4
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.CodeTypes = {
|
2009-05-08 11:27:02 +00:00
|
|
|
CPP: 0,
|
|
|
|
SHARED_LIB: 1
|
2009-04-27 13:50:42 +00:00
|
|
|
};
|
2009-05-08 11:27:02 +00:00
|
|
|
// Otherwise, this is JS-related code. We are not adding it to
|
|
|
|
// codeTypes_ map because there can be zillions of them.
|
2009-04-27 13:50:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.CALL_PROFILE_CUTOFF_PCT = 2.0;
|
|
|
|
|
|
|
|
|
2009-06-18 07:59:13 +00:00
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
TickProcessor.prototype.printError = function(str) {
|
|
|
|
print(str);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-04-27 13:50:42 +00:00
|
|
|
TickProcessor.prototype.setCodeType = function(name, type) {
|
|
|
|
this.codeTypes_[name] = TickProcessor.CodeTypes[type];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.isSharedLibrary = function(name) {
|
|
|
|
return this.codeTypes_[name] == TickProcessor.CodeTypes.SHARED_LIB;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.isCppCode = function(name) {
|
|
|
|
return this.codeTypes_[name] == TickProcessor.CodeTypes.CPP;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.isJsCode = function(name) {
|
2009-05-08 11:27:02 +00:00
|
|
|
return !(name in this.codeTypes_);
|
2009-04-27 13:50:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.processLogFile = function(fileName) {
|
|
|
|
this.lastLogFileName_ = fileName;
|
|
|
|
var contents = readFile(fileName);
|
2009-06-18 07:59:13 +00:00
|
|
|
this.processLogChunk(contents);
|
2009-04-27 13:50:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.processSharedLibrary = function(
|
|
|
|
name, startAddr, endAddr) {
|
2009-07-14 09:47:44 +00:00
|
|
|
var entry = this.profile_.addLibrary(name, startAddr, endAddr);
|
2009-04-27 13:50:42 +00:00
|
|
|
this.setCodeType(entry.getName(), 'SHARED_LIB');
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var libFuncs = this.cppEntriesProvider_.parseVmSymbols(
|
|
|
|
name, startAddr, endAddr, function(fName, fStart, fEnd) {
|
|
|
|
self.profile_.addStaticCode(fName, fStart, fEnd);
|
|
|
|
self.setCodeType(fName, 'CPP');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.processCodeCreation = function(
|
|
|
|
type, start, size, name) {
|
2009-06-18 07:59:13 +00:00
|
|
|
var entry = this.profile_.addCode(
|
|
|
|
this.expandAlias(type), name, start, size);
|
2009-04-27 13:50:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.processCodeMove = function(from, to) {
|
|
|
|
this.profile_.moveCode(from, to);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.processCodeDelete = function(start) {
|
|
|
|
this.profile_.deleteCode(start);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.includeTick = function(vmState) {
|
|
|
|
return this.stateFilter_ == null || this.stateFilter_ == vmState;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.processTick = function(pc, sp, vmState, stack) {
|
|
|
|
this.ticks_.total++;
|
|
|
|
if (vmState == TickProcessor.VmStates.GC) this.ticks_.gc++;
|
|
|
|
if (!this.includeTick(vmState)) {
|
|
|
|
this.ticks_.excluded++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-18 07:59:13 +00:00
|
|
|
this.profile_.recordTick(this.processStack(pc, stack));
|
2009-04-27 13:50:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.printStatistics = function() {
|
|
|
|
print('Statistical profiling result from ' + this.lastLogFileName_ +
|
|
|
|
', (' + this.ticks_.total +
|
|
|
|
' ticks, ' + this.ticks_.unaccounted + ' unaccounted, ' +
|
|
|
|
this.ticks_.excluded + ' excluded).');
|
|
|
|
|
|
|
|
if (this.ticks_.total == 0) return;
|
|
|
|
|
|
|
|
// Print the unknown ticks percentage if they are not ignored.
|
|
|
|
if (!this.ignoreUnknown_ && this.ticks_.unaccounted > 0) {
|
|
|
|
this.printHeader('Unknown');
|
|
|
|
this.printCounter(this.ticks_.unaccounted, this.ticks_.total);
|
|
|
|
}
|
|
|
|
|
|
|
|
var flatProfile = this.profile_.getFlatProfile();
|
|
|
|
var flatView = this.viewBuilder_.buildView(flatProfile);
|
|
|
|
// Sort by self time, desc, then by name, desc.
|
|
|
|
flatView.sort(function(rec1, rec2) {
|
|
|
|
return rec2.selfTime - rec1.selfTime ||
|
|
|
|
(rec2.internalFuncName < rec1.internalFuncName ? -1 : 1); });
|
|
|
|
var totalTicks = this.ticks_.total;
|
|
|
|
if (this.ignoreUnknown_) {
|
|
|
|
totalTicks -= this.ticks_.unaccounted;
|
|
|
|
}
|
|
|
|
// Our total time contains all the ticks encountered,
|
|
|
|
// while profile only knows about the filtered ticks.
|
|
|
|
flatView.head.totalTime = totalTicks;
|
|
|
|
|
|
|
|
// Count library ticks
|
|
|
|
var flatViewNodes = flatView.head.children;
|
|
|
|
var self = this;
|
|
|
|
var libraryTicks = 0;
|
|
|
|
this.processProfile(flatViewNodes,
|
|
|
|
function(name) { return self.isSharedLibrary(name); },
|
|
|
|
function(rec) { libraryTicks += rec.selfTime; });
|
|
|
|
var nonLibraryTicks = totalTicks - libraryTicks;
|
|
|
|
|
|
|
|
this.printHeader('Shared libraries');
|
|
|
|
this.printEntries(flatViewNodes, null,
|
|
|
|
function(name) { return self.isSharedLibrary(name); });
|
|
|
|
|
|
|
|
this.printHeader('JavaScript');
|
|
|
|
this.printEntries(flatViewNodes, nonLibraryTicks,
|
|
|
|
function(name) { return self.isJsCode(name); });
|
|
|
|
|
|
|
|
this.printHeader('C++');
|
|
|
|
this.printEntries(flatViewNodes, nonLibraryTicks,
|
|
|
|
function(name) { return self.isCppCode(name); });
|
|
|
|
|
|
|
|
this.printHeader('GC');
|
|
|
|
this.printCounter(this.ticks_.gc, totalTicks);
|
|
|
|
|
|
|
|
this.printHeavyProfHeader();
|
|
|
|
var heavyProfile = this.profile_.getBottomUpProfile();
|
|
|
|
var heavyView = this.viewBuilder_.buildView(heavyProfile);
|
|
|
|
// To show the same percentages as in the flat profile.
|
|
|
|
heavyView.head.totalTime = totalTicks;
|
|
|
|
// Sort by total time, desc, then by name, desc.
|
|
|
|
heavyView.sort(function(rec1, rec2) {
|
|
|
|
return rec2.totalTime - rec1.totalTime ||
|
|
|
|
(rec2.internalFuncName < rec1.internalFuncName ? -1 : 1); });
|
|
|
|
this.printHeavyProfile(heavyView.head.children);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function padLeft(s, len) {
|
|
|
|
s = s.toString();
|
|
|
|
if (s.length < len) {
|
2009-07-09 06:39:38 +00:00
|
|
|
var padLength = len - s.length;
|
|
|
|
if (!(padLength in padLeft)) {
|
|
|
|
padLeft[padLength] = new Array(padLength + 1).join(' ');
|
|
|
|
}
|
|
|
|
s = padLeft[padLength] + s;
|
2009-04-27 13:50:42 +00:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.printHeader = function(headerTitle) {
|
|
|
|
print('\n [' + headerTitle + ']:');
|
|
|
|
print(' ticks total nonlib name');
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.printHeavyProfHeader = function() {
|
|
|
|
print('\n [Bottom up (heavy) profile]:');
|
|
|
|
print(' Note: percentage shows a share of a particular caller in the ' +
|
|
|
|
'total\n' +
|
|
|
|
' amount of its parent calls.');
|
|
|
|
print(' Callers occupying less than ' +
|
|
|
|
TickProcessor.CALL_PROFILE_CUTOFF_PCT.toFixed(1) +
|
|
|
|
'% are not shown.\n');
|
|
|
|
print(' ticks parent name');
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.printCounter = function(ticksCount, totalTicksCount) {
|
|
|
|
var pct = ticksCount * 100.0 / totalTicksCount;
|
|
|
|
print(' ' + padLeft(ticksCount, 5) + ' ' + padLeft(pct.toFixed(1), 5) + '%');
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.processProfile = function(
|
|
|
|
profile, filterP, func) {
|
|
|
|
for (var i = 0, n = profile.length; i < n; ++i) {
|
|
|
|
var rec = profile[i];
|
2009-04-30 08:10:27 +00:00
|
|
|
if (!filterP(rec.internalFuncName)) {
|
2009-04-27 13:50:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
func(rec);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.printEntries = function(
|
|
|
|
profile, nonLibTicks, filterP) {
|
|
|
|
this.processProfile(profile, filterP, function (rec) {
|
|
|
|
if (rec.selfTime == 0) return;
|
|
|
|
var nonLibPct = nonLibTicks != null ?
|
|
|
|
rec.selfTime * 100.0 / nonLibTicks : 0.0;
|
|
|
|
print(' ' + padLeft(rec.selfTime, 5) + ' ' +
|
|
|
|
padLeft(rec.selfPercent.toFixed(1), 5) + '% ' +
|
|
|
|
padLeft(nonLibPct.toFixed(1), 5) + '% ' +
|
|
|
|
rec.internalFuncName);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TickProcessor.prototype.printHeavyProfile = function(profile, opt_indent) {
|
|
|
|
var self = this;
|
|
|
|
var indent = opt_indent || 0;
|
|
|
|
var indentStr = padLeft('', indent);
|
|
|
|
this.processProfile(profile, function() { return true; }, function (rec) {
|
|
|
|
// Cut off too infrequent callers.
|
|
|
|
if (rec.parentTotalPercent < TickProcessor.CALL_PROFILE_CUTOFF_PCT) return;
|
|
|
|
print(' ' + padLeft(rec.totalTime, 5) + ' ' +
|
|
|
|
padLeft(rec.parentTotalPercent.toFixed(1), 5) + '% ' +
|
|
|
|
indentStr + rec.internalFuncName);
|
|
|
|
// Limit backtrace depth.
|
|
|
|
if (indent < 10) {
|
|
|
|
self.printHeavyProfile(rec.children, indent + 2);
|
|
|
|
}
|
|
|
|
// Delimit top-level functions.
|
|
|
|
if (indent == 0) {
|
|
|
|
print('');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function CppEntriesProvider() {
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CppEntriesProvider.prototype.parseVmSymbols = function(
|
|
|
|
libName, libStart, libEnd, processorFunc) {
|
2009-05-08 11:27:02 +00:00
|
|
|
this.loadSymbols(libName);
|
2009-04-27 13:50:42 +00:00
|
|
|
|
|
|
|
var prevEntry;
|
|
|
|
|
2009-07-14 09:47:44 +00:00
|
|
|
function addEntry(funcInfo) {
|
2009-04-27 13:50:42 +00:00
|
|
|
// Several functions can be mapped onto the same address. To avoid
|
|
|
|
// creating zero-sized entries, skip such duplicates.
|
2009-06-19 07:08:31 +00:00
|
|
|
// Also double-check that function belongs to the library address space.
|
2009-07-14 09:47:44 +00:00
|
|
|
if (prevEntry && !prevEntry.end &&
|
|
|
|
prevEntry.start < funcInfo.start &&
|
|
|
|
prevEntry.start >= libStart && funcInfo.start <= libEnd) {
|
|
|
|
processorFunc(prevEntry.name, prevEntry.start, funcInfo.start);
|
2009-04-27 13:50:42 +00:00
|
|
|
}
|
2009-07-14 09:47:44 +00:00
|
|
|
if (funcInfo.end &&
|
|
|
|
(!prevEntry || prevEntry.start != funcInfo.start) &&
|
|
|
|
funcInfo.start >= libStart && funcInfo.end <= libEnd) {
|
|
|
|
processorFunc(funcInfo.name, funcInfo.start, funcInfo.end);
|
|
|
|
}
|
|
|
|
prevEntry = funcInfo;
|
2009-04-27 13:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-05-08 11:27:02 +00:00
|
|
|
while (true) {
|
|
|
|
var funcInfo = this.parseNextLine();
|
|
|
|
if (funcInfo === null) {
|
2009-04-27 13:50:42 +00:00
|
|
|
continue;
|
2009-05-08 11:27:02 +00:00
|
|
|
} else if (funcInfo === false) {
|
|
|
|
break;
|
2009-04-27 13:50:42 +00:00
|
|
|
}
|
|
|
|
if (funcInfo.start < libStart && funcInfo.start < libEnd - libStart) {
|
|
|
|
funcInfo.start += libStart;
|
|
|
|
}
|
2009-07-14 09:47:44 +00:00
|
|
|
if (funcInfo.size) {
|
|
|
|
funcInfo.end = funcInfo.start + funcInfo.size;
|
|
|
|
}
|
|
|
|
addEntry(funcInfo);
|
2009-04-27 13:50:42 +00:00
|
|
|
}
|
2009-07-14 09:47:44 +00:00
|
|
|
addEntry({name: '', start: libEnd});
|
2009-04-27 13:50:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CppEntriesProvider.prototype.loadSymbols = function(libName) {
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-08 11:27:02 +00:00
|
|
|
CppEntriesProvider.prototype.parseNextLine = function() {
|
|
|
|
return false;
|
2009-04-27 13:50:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-06-20 12:54:02 +00:00
|
|
|
function UnixCppEntriesProvider(nmExec) {
|
2009-05-08 11:27:02 +00:00
|
|
|
this.symbols = [];
|
|
|
|
this.parsePos = 0;
|
2009-06-20 12:54:02 +00:00
|
|
|
this.nmExec = nmExec;
|
2009-07-28 15:37:05 +00:00
|
|
|
this.FUNC_RE = /^([0-9a-fA-F]{8,16}) ([0-9a-fA-F]{8,16} )?[tTwW] (.*)$/;
|
2009-04-27 13:50:42 +00:00
|
|
|
};
|
|
|
|
inherits(UnixCppEntriesProvider, CppEntriesProvider);
|
|
|
|
|
|
|
|
|
|
|
|
UnixCppEntriesProvider.prototype.loadSymbols = function(libName) {
|
2009-05-08 11:27:02 +00:00
|
|
|
this.parsePos = 0;
|
2009-06-16 13:44:48 +00:00
|
|
|
try {
|
|
|
|
this.symbols = [
|
2009-07-14 09:47:44 +00:00
|
|
|
os.system(this.nmExec, ['-C', '-n', '-S', libName], -1, -1),
|
|
|
|
os.system(this.nmExec, ['-C', '-n', '-S', '-D', libName], -1, -1)
|
2009-06-16 13:44:48 +00:00
|
|
|
];
|
|
|
|
} catch (e) {
|
|
|
|
// If the library cannot be found on this system let's not panic.
|
2009-06-18 07:59:13 +00:00
|
|
|
this.symbols = ['', ''];
|
2009-06-16 13:44:48 +00:00
|
|
|
}
|
2009-04-27 13:50:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-08 11:27:02 +00:00
|
|
|
UnixCppEntriesProvider.prototype.parseNextLine = function() {
|
|
|
|
if (this.symbols.length == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var lineEndPos = this.symbols[0].indexOf('\n', this.parsePos);
|
|
|
|
if (lineEndPos == -1) {
|
|
|
|
this.symbols.shift();
|
|
|
|
this.parsePos = 0;
|
|
|
|
return this.parseNextLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
var line = this.symbols[0].substring(this.parsePos, lineEndPos);
|
|
|
|
this.parsePos = lineEndPos + 1;
|
2009-07-14 05:01:06 +00:00
|
|
|
var fields = line.match(this.FUNC_RE);
|
2009-07-14 09:47:44 +00:00
|
|
|
var funcInfo = null;
|
|
|
|
if (fields) {
|
|
|
|
funcInfo = { name: fields[3], start: parseInt(fields[1], 16) };
|
|
|
|
if (fields[2]) {
|
|
|
|
funcInfo.size = parseInt(fields[2], 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return funcInfo;
|
2009-04-27 13:50:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-14 05:01:06 +00:00
|
|
|
function MacCppEntriesProvider(nmExec) {
|
|
|
|
UnixCppEntriesProvider.call(this, nmExec);
|
2009-07-14 09:47:44 +00:00
|
|
|
// Note an empty group. It is required, as UnixCppEntriesProvider expects 3 groups.
|
|
|
|
this.FUNC_RE = /^([0-9a-fA-F]{8}) ()[iItT] (.*)$/;
|
2009-07-14 05:01:06 +00:00
|
|
|
};
|
|
|
|
inherits(MacCppEntriesProvider, UnixCppEntriesProvider);
|
|
|
|
|
|
|
|
|
|
|
|
MacCppEntriesProvider.prototype.loadSymbols = function(libName) {
|
|
|
|
this.parsePos = 0;
|
|
|
|
try {
|
|
|
|
this.symbols = [os.system(this.nmExec, ['-n', '-f', libName], -1, -1), ''];
|
|
|
|
} catch (e) {
|
|
|
|
// If the library cannot be found on this system let's not panic.
|
|
|
|
this.symbols = '';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-04-27 13:50:42 +00:00
|
|
|
function WindowsCppEntriesProvider() {
|
2009-05-08 11:27:02 +00:00
|
|
|
this.symbols = '';
|
|
|
|
this.parsePos = 0;
|
2009-04-27 13:50:42 +00:00
|
|
|
};
|
|
|
|
inherits(WindowsCppEntriesProvider, CppEntriesProvider);
|
|
|
|
|
|
|
|
|
|
|
|
WindowsCppEntriesProvider.FILENAME_RE = /^(.*)\.exe$/;
|
|
|
|
|
|
|
|
|
|
|
|
WindowsCppEntriesProvider.FUNC_RE =
|
|
|
|
/^ 0001:[0-9a-fA-F]{8}\s+([_\?@$0-9a-zA-Z]+)\s+([0-9a-fA-F]{8}).*$/;
|
|
|
|
|
|
|
|
|
|
|
|
WindowsCppEntriesProvider.prototype.loadSymbols = function(libName) {
|
|
|
|
var fileNameFields = libName.match(WindowsCppEntriesProvider.FILENAME_RE);
|
|
|
|
// Only try to load symbols for the .exe file.
|
2009-05-08 11:27:02 +00:00
|
|
|
if (!fileNameFields) return;
|
2009-04-27 13:50:42 +00:00
|
|
|
var mapFileName = fileNameFields[1] + '.map';
|
2009-05-08 11:27:02 +00:00
|
|
|
this.symbols = readFile(mapFileName);
|
2009-04-27 13:50:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-08 11:27:02 +00:00
|
|
|
WindowsCppEntriesProvider.prototype.parseNextLine = function() {
|
|
|
|
var lineEndPos = this.symbols.indexOf('\r\n', this.parsePos);
|
|
|
|
if (lineEndPos == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var line = this.symbols.substring(this.parsePos, lineEndPos);
|
|
|
|
this.parsePos = lineEndPos + 2;
|
2009-04-27 13:50:42 +00:00
|
|
|
var fields = line.match(WindowsCppEntriesProvider.FUNC_RE);
|
|
|
|
return fields ?
|
|
|
|
{ name: this.unmangleName(fields[1]), start: parseInt(fields[2], 16) } :
|
|
|
|
null;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs very simple unmangling of C++ names.
|
|
|
|
*
|
|
|
|
* Does not handle arguments and template arguments. The mangled names have
|
|
|
|
* the form:
|
|
|
|
*
|
|
|
|
* ?LookupInDescriptor@JSObject@internal@v8@@...arguments info...
|
|
|
|
*/
|
|
|
|
WindowsCppEntriesProvider.prototype.unmangleName = function(name) {
|
|
|
|
// Empty or non-mangled name.
|
|
|
|
if (name.length < 1 || name.charAt(0) != '?') return name;
|
|
|
|
var nameEndPos = name.indexOf('@@');
|
|
|
|
var components = name.substring(1, nameEndPos).split('@');
|
|
|
|
components.reverse();
|
|
|
|
return components.join('::');
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-09 06:39:38 +00:00
|
|
|
function ArgumentsProcessor(args) {
|
|
|
|
this.args_ = args;
|
|
|
|
this.result_ = ArgumentsProcessor.DEFAULTS;
|
2009-04-27 13:50:42 +00:00
|
|
|
|
2009-07-09 06:39:38 +00:00
|
|
|
this.argsDispatch_ = {
|
2009-04-27 13:50:42 +00:00
|
|
|
'-j': ['stateFilter', TickProcessor.VmStates.JS,
|
|
|
|
'Show only ticks from JS VM state'],
|
|
|
|
'-g': ['stateFilter', TickProcessor.VmStates.GC,
|
|
|
|
'Show only ticks from GC VM state'],
|
|
|
|
'-c': ['stateFilter', TickProcessor.VmStates.COMPILER,
|
|
|
|
'Show only ticks from COMPILER VM state'],
|
|
|
|
'-o': ['stateFilter', TickProcessor.VmStates.OTHER,
|
|
|
|
'Show only ticks from OTHER VM state'],
|
|
|
|
'-e': ['stateFilter', TickProcessor.VmStates.EXTERNAL,
|
|
|
|
'Show only ticks from EXTERNAL VM state'],
|
|
|
|
'--ignore-unknown': ['ignoreUnknown', true,
|
|
|
|
'Exclude ticks of unknown code entries from processing'],
|
|
|
|
'--separate-ic': ['separateIc', true,
|
|
|
|
'Separate IC entries'],
|
|
|
|
'--unix': ['platform', 'unix',
|
|
|
|
'Specify that we are running on *nix platform'],
|
|
|
|
'--windows': ['platform', 'windows',
|
2009-06-20 12:54:02 +00:00
|
|
|
'Specify that we are running on Windows platform'],
|
2009-07-14 05:01:06 +00:00
|
|
|
'--mac': ['platform', 'mac',
|
|
|
|
'Specify that we are running on Mac OS X platform'],
|
2009-06-20 12:54:02 +00:00
|
|
|
'--nm': ['nm', 'nm',
|
|
|
|
'Specify the \'nm\' executable to use (e.g. --nm=/my_dir/nm)']
|
2009-04-27 13:50:42 +00:00
|
|
|
};
|
2009-07-09 06:39:38 +00:00
|
|
|
this.argsDispatch_['--js'] = this.argsDispatch_['-j'];
|
|
|
|
this.argsDispatch_['--gc'] = this.argsDispatch_['-g'];
|
|
|
|
this.argsDispatch_['--compiler'] = this.argsDispatch_['-c'];
|
|
|
|
this.argsDispatch_['--other'] = this.argsDispatch_['-o'];
|
|
|
|
this.argsDispatch_['--external'] = this.argsDispatch_['-e'];
|
|
|
|
};
|
|
|
|
|
2009-07-07 12:11:12 +00:00
|
|
|
|
2009-07-09 06:39:38 +00:00
|
|
|
ArgumentsProcessor.DEFAULTS = {
|
|
|
|
logFileName: 'v8.log',
|
|
|
|
platform: 'unix',
|
|
|
|
stateFilter: null,
|
|
|
|
ignoreUnknown: false,
|
|
|
|
separateIc: false,
|
|
|
|
nm: 'nm'
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ArgumentsProcessor.prototype.parse = function() {
|
|
|
|
while (this.args_.length) {
|
|
|
|
var arg = this.args_[0];
|
2009-04-27 13:50:42 +00:00
|
|
|
if (arg.charAt(0) != '-') {
|
|
|
|
break;
|
|
|
|
}
|
2009-07-09 06:39:38 +00:00
|
|
|
this.args_.shift();
|
2009-06-20 12:54:02 +00:00
|
|
|
var userValue = null;
|
|
|
|
var eqPos = arg.indexOf('=');
|
|
|
|
if (eqPos != -1) {
|
|
|
|
userValue = arg.substr(eqPos + 1);
|
|
|
|
arg = arg.substr(0, eqPos);
|
|
|
|
}
|
2009-07-09 06:39:38 +00:00
|
|
|
if (arg in this.argsDispatch_) {
|
|
|
|
var dispatch = this.argsDispatch_[arg];
|
|
|
|
this.result_[dispatch[0]] = userValue == null ? dispatch[1] : userValue;
|
2009-04-27 13:50:42 +00:00
|
|
|
} else {
|
2009-07-09 06:39:38 +00:00
|
|
|
return false;
|
2009-04-27 13:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-09 06:39:38 +00:00
|
|
|
if (this.args_.length >= 1) {
|
|
|
|
this.result_.logFileName = this.args_.shift();
|
2009-04-27 13:50:42 +00:00
|
|
|
}
|
2009-07-09 06:39:38 +00:00
|
|
|
return true;
|
2009-04-27 13:50:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-09 06:39:38 +00:00
|
|
|
ArgumentsProcessor.prototype.result = function() {
|
|
|
|
return this.result_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ArgumentsProcessor.prototype.printUsageAndExit = function() {
|
|
|
|
|
|
|
|
function padRight(s, len) {
|
|
|
|
s = s.toString();
|
|
|
|
if (s.length < len) {
|
|
|
|
s = s + (new Array(len - s.length + 1).join(' '));
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
print('Cmdline args: [options] [log-file-name]\n' +
|
|
|
|
'Default log file name is "' +
|
|
|
|
ArgumentsProcessor.DEFAULTS.logFileName + '".\n');
|
|
|
|
print('Options:');
|
|
|
|
for (var arg in this.argsDispatch_) {
|
|
|
|
var synonims = [arg];
|
|
|
|
var dispatch = this.argsDispatch_[arg];
|
|
|
|
for (var synArg in this.argsDispatch_) {
|
|
|
|
if (arg !== synArg && dispatch === this.argsDispatch_[synArg]) {
|
|
|
|
synonims.push(synArg);
|
|
|
|
delete this.argsDispatch_[synArg];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print(' ' + padRight(synonims.join(', '), 20) + dispatch[2]);
|
|
|
|
}
|
|
|
|
quit(2);
|
|
|
|
};
|
|
|
|
|