Commit 5dbd342b authored by Camillo Bruni's avatar Camillo Bruni Committed by V8 LUCI CQ

[tools] Cleanup Arguments processing in tools

- Move readFile helper to LogReader.readFile
- Add static BaseArgumentsProcessor.process helper
- Move SourceMap handling to the TickProcessor
- Always skip example file mjsunit/tools/tickprocessor-test-large.js
- Run tickprocessor and dumpcpp tests only in release mode

Change-Id: I635fb2d2839233219b058faf9710fd0f19880fd2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2929117Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74873}
parent 59a60aed
...@@ -17,6 +17,7 @@ group("v8_mjsunit") { ...@@ -17,6 +17,7 @@ group("v8_mjsunit") {
"../../tools/clusterfuzz/v8_mock_archs.js", "../../tools/clusterfuzz/v8_mock_archs.js",
"../../tools/clusterfuzz/v8_mock_webassembly.js", "../../tools/clusterfuzz/v8_mock_webassembly.js",
"../../tools/codemap.mjs", "../../tools/codemap.mjs",
"../../tools/sourcemap.mjs",
"../../tools/consarray.mjs", "../../tools/consarray.mjs",
"../../tools/csvparser.mjs", "../../tools/csvparser.mjs",
"../../tools/dumpcpp.mjs", "../../tools/dumpcpp.mjs",
......
...@@ -83,8 +83,10 @@ ...@@ -83,8 +83,10 @@
'regress/regress-crbug-491062': [PASS, NO_VARIANTS], 'regress/regress-crbug-491062': [PASS, NO_VARIANTS],
'third_party/regexp-pcre/regexp-pcre': [PASS, NO_VARIANTS], 'third_party/regexp-pcre/regexp-pcre': [PASS, NO_VARIANTS],
'tools/compiler-trace-flags': [PASS, NO_VARIANTS], 'tools/compiler-trace-flags': [PASS, NO_VARIANTS],
'tools/dumpcpp': [PASS, NO_VARIANTS], 'tools/dumpcpp': [PASS, NO_VARIANTS, ['mode != release', SKIP]],
'tools/tickprocessor': [PASS, NO_VARIANTS], 'tools/tickprocessor': [PASS, NO_VARIANTS, ['mode != release', SKIP]],
# Also skip example file which is not a test.
'tools/tickprocessor-test-large': [SKIP],
# Issue 488: this test sometimes times out. # Issue 488: this test sometimes times out.
# TODO(arm): This seems to flush out a bug on arm with simulator. # TODO(arm): This seems to flush out a bug on arm with simulator.
...@@ -147,7 +149,6 @@ ...@@ -147,7 +149,6 @@
'wasm/atomics64-stress': [PASS, SLOW, NO_VARIANTS, ['mode != release or dcheck_always_on', SKIP], ['tsan', SKIP]], 'wasm/atomics64-stress': [PASS, SLOW, NO_VARIANTS, ['mode != release or dcheck_always_on', SKIP], ['tsan', SKIP]],
'wasm/compare-exchange-stress': [PASS, SLOW, NO_VARIANTS], 'wasm/compare-exchange-stress': [PASS, SLOW, NO_VARIANTS],
'wasm/compare-exchange64-stress': [PASS, SLOW, NO_VARIANTS], 'wasm/compare-exchange64-stress': [PASS, SLOW, NO_VARIANTS],
'tools/tickprocessor-test-large': [PASS, SLOW, NO_VARIANTS, ['mode != release or arch != x64', SKIP]],
# Very slow on ARM and MIPS, contains no architecture dependent code. # Very slow on ARM and MIPS, contains no architecture dependent code.
'unicode-case-overoptimization0': [PASS, NO_VARIANTS, ['arch in (arm, arm64, mipsel, mips64el, mips64, mips, riscv64)', SKIP]], 'unicode-case-overoptimization0': [PASS, NO_VARIANTS, ['arch in (arm, arm64, mipsel, mips64el, mips64, mips, riscv64)', SKIP]],
......
...@@ -44,9 +44,18 @@ ...@@ -44,9 +44,18 @@
import { import {
TickProcessor, ArgumentsProcessor, UnixCppEntriesProvider, TickProcessor, ArgumentsProcessor, UnixCppEntriesProvider,
MacCppEntriesProvider, WindowsCppEntriesProvider, readFile MacCppEntriesProvider, WindowsCppEntriesProvider
} from "../../../tools/tickprocessor.mjs"; } from "../../../tools/tickprocessor.mjs";
// TODO(cbruni): Remove after refactoring
export function readFile(fileName) {
try {
return read(fileName);
} catch (e) {
console.log(fileName + ': ' + (e.message || e));
throw e;
}
}
(function testArgumentsProcessor() { (function testArgumentsProcessor() {
var p_default = new ArgumentsProcessor([]); var p_default = new ArgumentsProcessor([]);
......
...@@ -22,6 +22,16 @@ export class BaseArgumentsProcessor { ...@@ -22,6 +22,16 @@ export class BaseArgumentsProcessor {
result() { return this.result_ } result() { return this.result_ }
static process(args) {
const processor = new this(args);
if (processor.parse()) {
return processor.result();
} else {
processor.printUsageAndExit();
return false;
}
}
printUsageAndExit() { printUsageAndExit() {
console.log('Cmdline args: [options] [log-file-name]\n' + console.log('Cmdline args: [options] [log-file-name]\n' +
'Default log file name is "' + 'Default log file name is "' +
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import { WebInspector } from "./sourcemap.mjs";
import { import {
CppProcessor, ArgumentsProcessor, UnixCppEntriesProvider, CppProcessor, ArgumentsProcessor, UnixCppEntriesProvider,
WindowsCppEntriesProvider, MacCppEntriesProvider WindowsCppEntriesProvider, MacCppEntriesProvider
...@@ -10,40 +9,13 @@ import { ...@@ -10,40 +9,13 @@ import {
// Dump C++ symbols of shared library if possible // Dump C++ symbols of shared library if possible
function processArguments(args) {
const processor = new ArgumentsProcessor(args);
if (processor.parse()) {
return processor.result();
} else {
processor.printUsageAndExit();
}
}
function initSourceMapSupport() {
// Pull dev tools source maps into our name space.
SourceMap = WebInspector.SourceMap;
// Overwrite the load function to load scripts synchronously.
SourceMap.load = function(sourceMapURL) {
const content = readFile(sourceMapURL);
const sourceMapObject = (JSON.parse(content));
return new SourceMap(sourceMapURL, sourceMapObject);
};
}
const entriesProviders = { const entriesProviders = {
'unix': UnixCppEntriesProvider, 'unix': UnixCppEntriesProvider,
'windows': WindowsCppEntriesProvider, 'windows': WindowsCppEntriesProvider,
'mac': MacCppEntriesProvider 'mac': MacCppEntriesProvider
}; };
const params = processArguments(arguments); const params = ArgumentsProcessor.process(arguments);
let sourceMap = null;
if (params.sourceMap) {
initSourceMapSupport();
sourceMap = SourceMap.load(params.sourceMap);
}
const cppProcessor = new CppProcessor( const cppProcessor = new CppProcessor(
new (entriesProviders[params.platform])(params.nm, params.targetRootFS, new (entriesProviders[params.platform])(params.nm, params.targetRootFS,
params.apkEmbeddedLibrary), params.apkEmbeddedLibrary),
......
...@@ -41,7 +41,7 @@ export class CppProcessor extends LogReader { ...@@ -41,7 +41,7 @@ export class CppProcessor extends LogReader {
processLogFileInTest(fileName) { processLogFileInTest(fileName) {
// Hack file name to avoid dealing with platform specifics. // Hack file name to avoid dealing with platform specifics.
this.lastLogFileName_ = 'v8.log'; this.lastLogFileName_ = 'v8.log';
const contents = readFile(fileName); const contents = this.readFile(fileName);
this.processLogChunk(contents); this.processLogChunk(contents);
} }
......
...@@ -3,49 +3,13 @@ ...@@ -3,49 +3,13 @@
// found in the LICENSE file. // found in the LICENSE file.
import { Processor } from "./system-analyzer/processor.mjs"; import { Processor } from "./system-analyzer/processor.mjs";
import { WebInspector } from "./sourcemap.mjs"; import { BaseArgumentsProcessor} from "./arguments.mjs";
import { BaseArgumentsProcessor } from "./arguments.mjs";
function processArguments(args) {
const processor = new ArgumentsProcessor(args);
if (processor.parse()) {
return processor.result();
} else {
processor.printUsageAndExit();
}
}
/**
* A thin wrapper around shell's 'read' function showing a file name on error.
*/
export function readFile(fileName) {
try {
return read(fileName);
} catch (e) {
console.log(fileName + ': ' + (e.message || e));
throw e;
}
}
function initSourceMapSupport() {
// Pull dev tools source maps into our name space.
SourceMap = WebInspector.SourceMap;
// Overwrite the load function to load scripts synchronously.
SourceMap.load = function(sourceMapURL) {
const content = readFile(sourceMapURL);
const sourceMapObject = (JSON.parse(content));
return new SourceMap(sourceMapURL, sourceMapObject);
};
}
class ArgumentsProcessor extends BaseArgumentsProcessor { class ArgumentsProcessor extends BaseArgumentsProcessor {
getArgsDispatch() { getArgsDispatch() {
return { return {
'--range': ['range', 'auto,auto', '--range': ['range', 'auto,auto',
'Specify the range limit as [start],[end]'], 'Specify the range limit as [start],[end]'],
'--source-map': ['sourceMap', null,
'Specify the source map that should be used for output']
}; };
} }
getDefaultResults() { getDefaultResults() {
...@@ -56,26 +20,21 @@ class ArgumentsProcessor extends BaseArgumentsProcessor { ...@@ -56,26 +20,21 @@ class ArgumentsProcessor extends BaseArgumentsProcessor {
} }
} }
const params = processArguments(arguments); const params = ArgumentsProcessor.process(arguments);
let sourceMap = null;
if (params.sourceMap) {
initSourceMapSupport();
sourceMap = SourceMap.load(params.sourceMap);
}
const processor = new Processor(); const processor = new Processor();
processor.processLogFile(params.logFileName); processor.processLogFile(params.logFileName);
const typeAccumulator = new Map(); const typeAccumulator = new Map();
const accumulator = { const accumulator = {
__proto__: null, __proto__: null,
LoadGlobalIC: 0, LoadGlobalIC: 0,
StoreGlobalIC: 0, StoreGlobalIC: 0,
LoadIC: 0, LoadIC: 0,
StoreIC: 0, StoreIC: 0,
KeyedLoadIC: 0, KeyedLoadIC: 0,
KeyedStoreIC: 0, KeyedStoreIC: 0,
StoreInArrayLiteralIC: 0, StoreInArrayLiteralIC: 0,
} }
for (const ic of processor.icTimeline.all) { for (const ic of processor.icTimeline.all) {
console.log(Object.values(ic)); console.log(Object.values(ic));
...@@ -86,5 +45,3 @@ console.log("========================================"); ...@@ -86,5 +45,3 @@ console.log("========================================");
for (const key of Object.keys(accumulator)) { for (const key of Object.keys(accumulator)) {
console.log(key + ": " + accumulator[key]); console.log(key + ": " + accumulator[key]);
} }
...@@ -90,6 +90,19 @@ export class LogReader { ...@@ -90,6 +90,19 @@ export class LogReader {
this.logLinesSinceLastTimerMarker_ = []; this.logLinesSinceLastTimerMarker_ = [];
} }
/**
* A thin wrapper around shell's 'read' function showing a file name on error.
*/
readFile(fileName) {
try {
return read(fileName);
} catch (e) {
printErr(`file="${fileName}": ${e.message || e}`);
throw e;
}
}
/** /**
* Used for printing error messages. * Used for printing error messages.
* *
......
...@@ -2,37 +2,8 @@ ...@@ -2,37 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import { WebInspector } from "./sourcemap.mjs"; import { ParseProcessor, ArgumentsProcessor } from "./parse-processor.mjs";
import {
ParseProcessor, ArgumentsProcessor, readFile,
} from "./parse-processor.mjs";
function processArguments(args) { const params = ArgumentsProcessor.process(arguments);
const processor = new ArgumentsProcessor(args);
if (processor.parse()) {
return processor.result();
} else {
processor.printUsageAndExit();
}
}
function initSourceMapSupport() {
// Pull dev tools source maps into our name space.
SourceMap = WebInspector.SourceMap;
// Overwrite the load function to load scripts synchronously.
SourceMap.load = function(sourceMapURL) {
const content = readFile(sourceMapURL);
const sourceMapObject = (JSON.parse(content));
return new SourceMap(sourceMapURL, sourceMapObject);
};
}
const params = processArguments(arguments);
let sourceMap = null;
if (params.sourceMap) {
initSourceMapSupport();
sourceMap = SourceMap.load(params.sourceMap);
}
const parseProcessor = new ParseProcessor(); const parseProcessor = new ParseProcessor();
parseProcessor.processLogFile(params.logFileName); parseProcessor.processLogFile(params.logFileName);
...@@ -4,18 +4,6 @@ ...@@ -4,18 +4,6 @@
import { LogReader, parseString } from "./logreader.mjs"; import { LogReader, parseString } from "./logreader.mjs";
import { BaseArgumentsProcessor } from "./arguments.mjs"; import { BaseArgumentsProcessor } from "./arguments.mjs";
/**
* A thin wrapper around shell's 'read' function showing a file name on error.
*/
export function readFile(fileName) {
try {
return read(fileName);
} catch (e) {
console.log(fileName + ': ' + (e.message || e));
throw e;
}
}
// =========================================================================== // ===========================================================================
// This is the only true formatting, why? For an international audience the // This is the only true formatting, why? For an international audience the
......
...@@ -25,47 +25,20 @@ ...@@ -25,47 +25,20 @@
// (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 { WebInspector} from "./sourcemap.mjs";
import { import {
ArgumentsProcessor, TickProcessor, UnixCppEntriesProvider, ArgumentsProcessor, TickProcessor, UnixCppEntriesProvider,
WindowsCppEntriesProvider, MacCppEntriesProvider, readFile, WindowsCppEntriesProvider, MacCppEntriesProvider
} from "./tickprocessor.mjs"; } from "./tickprocessor.mjs";
// Tick Processor's code flow. // Tick Processor's code flow.
function processArguments(args) {
const processor = new ArgumentsProcessor(args);
if (processor.parse()) {
return processor.result();
} else {
processor.printUsageAndExit();
}
}
function initSourceMapSupport() {
// Pull dev tools source maps into our name space.
SourceMap = WebInspector.SourceMap;
// Overwrite the load function to load scripts synchronously.
SourceMap.load = function(sourceMapURL) {
const content = readFile(sourceMapURL);
const sourceMapObject = (JSON.parse(content));
return new SourceMap(sourceMapURL, sourceMapObject);
};
}
const entriesProviders = { const entriesProviders = {
'unix': UnixCppEntriesProvider, 'unix': UnixCppEntriesProvider,
'windows': WindowsCppEntriesProvider, 'windows': WindowsCppEntriesProvider,
'mac': MacCppEntriesProvider 'mac': MacCppEntriesProvider
}; };
const params = processArguments(arguments); const params = ArgumentsProcessor.process(arguments);
let sourceMap = null;
if (params.sourceMap) {
initSourceMapSupport();
sourceMap = SourceMap.load(params.sourceMap);
}
const tickProcessor = new TickProcessor( const tickProcessor = new TickProcessor(
new (entriesProviders[params.platform])(params.nm, params.objdump, params.targetRootFS, new (entriesProviders[params.platform])(params.nm, params.objdump, params.targetRootFS,
params.apkEmbeddedLibrary), params.apkEmbeddedLibrary),
...@@ -79,7 +52,7 @@ const tickProcessor = new TickProcessor( ...@@ -79,7 +52,7 @@ const tickProcessor = new TickProcessor(
params.stateFilter, params.stateFilter,
params.distortion, params.distortion,
params.range, params.range,
sourceMap, params.sourceMap,
params.timedRange, params.timedRange,
params.pairwiseTimedRange, params.pairwiseTimedRange,
params.onlySummary, params.onlySummary,
......
...@@ -29,6 +29,7 @@ import { LogReader, parseString, parseVarArgs } from "./logreader.mjs"; ...@@ -29,6 +29,7 @@ import { LogReader, parseString, parseVarArgs } from "./logreader.mjs";
import { BaseArgumentsProcessor, parseBool } from "./arguments.mjs"; import { BaseArgumentsProcessor, parseBool } from "./arguments.mjs";
import { Profile, JsonProfile } from "./profile.mjs"; import { Profile, JsonProfile } from "./profile.mjs";
import { ViewBuilder } from "./profile_view.mjs"; import { ViewBuilder } from "./profile_view.mjs";
import { WebInspector} from "./sourcemap.mjs";
class V8Profile extends Profile { class V8Profile extends Profile {
...@@ -59,19 +60,6 @@ class V8Profile extends Profile { ...@@ -59,19 +60,6 @@ class V8Profile extends Profile {
} }
/**
* A thin wrapper around shell's 'read' function showing a file name on error.
*/
export function readFile(fileName) {
try {
return read(fileName);
} catch (e) {
printErr(`file="${fileName}": ${e.message || e}`);
throw e;
}
}
export class TickProcessor extends LogReader { export class TickProcessor extends LogReader {
constructor( constructor(
cppEntriesProvider, cppEntriesProvider,
...@@ -174,7 +162,7 @@ export class TickProcessor extends LogReader { ...@@ -174,7 +162,7 @@ export class TickProcessor extends LogReader {
this.ignoreUnknown_ = ignoreUnknown; this.ignoreUnknown_ = ignoreUnknown;
this.stateFilter_ = stateFilter; this.stateFilter_ = stateFilter;
this.runtimeTimerFilter_ = runtimeTimerFilter; this.runtimeTimerFilter_ = runtimeTimerFilter;
this.sourceMap = sourceMap; this.sourceMap = this.loadSourceMap(sourceMap);
const ticks = this.ticks_ = const ticks = this.ticks_ =
{ total: 0, unaccounted: 0, excluded: 0, gc: 0 }; { total: 0, unaccounted: 0, excluded: 0, gc: 0 };
...@@ -226,6 +214,17 @@ export class TickProcessor extends LogReader { ...@@ -226,6 +214,17 @@ export class TickProcessor extends LogReader {
this.onlySummary_ = onlySummary; this.onlySummary_ = onlySummary;
} }
loadSourceMap(sourceMap) {
if (!sourceMap) return null;
// Overwrite the load function to load scripts synchronously.
WebInspector.SourceMap.load = (sourceMapURL) => {
const content = this.readFile(sourceMapURL);
const sourceMapObject = JSON.parse(content);
return new SourceMap(sourceMapURL, sourceMapObject);
};
return WebInspector.SourceMap.load(sourceMap);
}
static VmStates = { static VmStates = {
JS: 0, JS: 0,
GC: 1, GC: 1,
...@@ -282,7 +281,7 @@ export class TickProcessor extends LogReader { ...@@ -282,7 +281,7 @@ export class TickProcessor extends LogReader {
processLogFileInTest(fileName) { processLogFileInTest(fileName) {
// Hack file name to avoid dealing with platform specifics. // Hack file name to avoid dealing with platform specifics.
this.lastLogFileName_ = 'v8.log'; this.lastLogFileName_ = 'v8.log';
const contents = readFile(fileName); const contents = this.readFile(fileName);
this.processLogChunk(contents); this.processLogChunk(contents);
} }
...@@ -835,6 +834,7 @@ export class WindowsCppEntriesProvider extends CppEntriesProvider { ...@@ -835,6 +834,7 @@ export class WindowsCppEntriesProvider extends CppEntriesProvider {
export class ArgumentsProcessor extends BaseArgumentsProcessor { export class ArgumentsProcessor extends BaseArgumentsProcessor {
getArgsDispatch() { getArgsDispatch() {
let dispatch = { let dispatch = {
__proto__:null,
'-j': ['stateFilter', TickProcessor.VmStates.JS, '-j': ['stateFilter', TickProcessor.VmStates.JS,
'Show only ticks from JS VM state'], 'Show only ticks from JS VM state'],
'-g': ['stateFilter', TickProcessor.VmStates.GC, '-g': ['stateFilter', TickProcessor.VmStates.GC,
...@@ -918,6 +918,7 @@ export class ArgumentsProcessor extends BaseArgumentsProcessor { ...@@ -918,6 +918,7 @@ export class ArgumentsProcessor extends BaseArgumentsProcessor {
separateStubs: true, separateStubs: true,
separateBaselineHandlers: false, separateBaselineHandlers: false,
preprocessJson: null, preprocessJson: null,
sourceMap: null,
targetRootFS: '', targetRootFS: '',
nm: 'nm', nm: 'nm',
objdump: 'objdump', objdump: 'objdump',
......
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