Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Unified Diff: tools/tickprocessor.js

Issue 155161: Add automatic tests for Tick Processor, take two. (Closed)
Patch Set: Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/test.py ('k') | tools/tickprocessor-driver.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/tickprocessor.js
diff --git a/tools/tickprocessor.js b/tools/tickprocessor.js
index 4afc69f613badbe4e8f219e05788571cbb797a95..c95a4e616edcfe7b3a39706fa4747014560abef7 100644
--- a/tools/tickprocessor.js
+++ b/tools/tickprocessor.js
@@ -288,7 +288,11 @@ TickProcessor.prototype.printStatistics = function() {
function padLeft(s, len) {
s = s.toString();
if (s.length < len) {
- s = (new Array(len - s.length + 1).join(' ')) + s;
+ var padLength = len - s.length;
+ if (!(padLength in padLeft)) {
+ padLeft[padLength] = new Array(padLength + 1).join(' ');
+ }
+ s = padLeft[padLength] + s;
}
return s;
};
@@ -511,25 +515,11 @@ WindowsCppEntriesProvider.prototype.unmangleName = function(name) {
};
-function padRight(s, len) {
- s = s.toString();
- if (s.length < len) {
- s = s + (new Array(len - s.length + 1).join(' '));
- }
- return s;
-};
-
+function ArgumentsProcessor(args) {
+ this.args_ = args;
+ this.result_ = ArgumentsProcessor.DEFAULTS;
-function processArguments(args) {
- var result = {
- logFileName: 'v8.log',
- platform: 'unix',
- stateFilter: null,
- ignoreUnknown: false,
- separateIc: false,
- nm: 'nm'
- };
- var argsDispatch = {
+ this.argsDispatch_ = {
'-j': ['stateFilter', TickProcessor.VmStates.JS,
'Show only ticks from JS VM state'],
'-g': ['stateFilter', TickProcessor.VmStates.GC,
@@ -551,63 +541,82 @@ function processArguments(args) {
'--nm': ['nm', 'nm',
'Specify the \'nm\' executable to use (e.g. --nm=/my_dir/nm)']
};
- argsDispatch['--js'] = argsDispatch['-j'];
- argsDispatch['--gc'] = argsDispatch['-g'];
- argsDispatch['--compiler'] = argsDispatch['-c'];
- argsDispatch['--other'] = argsDispatch['-o'];
- argsDispatch['--external'] = argsDispatch['-e'];
-
- function printUsageAndExit() {
- print('Cmdline args: [options] [log-file-name]\n' +
- 'Default log file name is "v8.log".\n');
- print('Options:');
- for (var arg in argsDispatch) {
- var synonims = [arg];
- var dispatch = argsDispatch[arg];
- for (var synArg in argsDispatch) {
- if (arg !== synArg && dispatch === argsDispatch[synArg]) {
- synonims.push(synArg);
- delete argsDispatch[synArg];
- }
- }
- print(' ' + padRight(synonims.join(', '), 20) + dispatch[2]);
- }
- quit(2);
- }
+ 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'];
+};
+
- while (args.length) {
- var arg = args[0];
+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];
if (arg.charAt(0) != '-') {
break;
}
- args.shift();
+ this.args_.shift();
var userValue = null;
var eqPos = arg.indexOf('=');
if (eqPos != -1) {
userValue = arg.substr(eqPos + 1);
arg = arg.substr(0, eqPos);
}
- if (arg in argsDispatch) {
- var dispatch = argsDispatch[arg];
- result[dispatch[0]] = userValue == null ? dispatch[1] : userValue;
+ if (arg in this.argsDispatch_) {
+ var dispatch = this.argsDispatch_[arg];
+ this.result_[dispatch[0]] = userValue == null ? dispatch[1] : userValue;
} else {
- printUsageAndExit();
+ return false;
}
}
- if (args.length >= 1) {
- result.logFileName = args.shift();
+ if (this.args_.length >= 1) {
+ this.result_.logFileName = this.args_.shift();
}
- return result;
+ return true;
};
-var params = processArguments(arguments);
-var tickProcessor = new TickProcessor(
- params.platform == 'unix' ? new UnixCppEntriesProvider(params.nm) :
- new WindowsCppEntriesProvider(),
- params.separateIc,
- params.ignoreUnknown,
- params.stateFilter);
-tickProcessor.processLogFile(params.logFileName);
-tickProcessor.printStatistics();
+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);
+};
+
« no previous file with comments | « tools/test.py ('k') | tools/tickprocessor-driver.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698