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

Unified Diff: tools/tickprocessor.js

Issue 149195: Add automatic tests for Tick Processor. (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
Index: tools/tickprocessor.js
diff --git a/tools/tickprocessor.js b/tools/tickprocessor.js
index 4afc69f613badbe4e8f219e05788571cbb797a95..f62d166afccf1d2587fcc4ff781eb819c1cb11af 100644
--- a/tools/tickprocessor.js
+++ b/tools/tickprocessor.js
@@ -511,25 +511,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'],
Erik Corry 2009/07/07 11:15:32 It would be better if this was an object with keys
Mikhail Naganov 2009/07/07 12:08:10 The downside of using a map here is that the defin
'-g': ['stateFilter', TickProcessor.VmStates.GC,
@@ -551,63 +537,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'];
+};
+
+
+ArgumentsProcessor.DEFAULTS = {
+ logFileName: 'v8.log',
+ platform: 'unix',
+ stateFilter: null,
+ ignoreUnknown: false,
+ separateIc: false,
+ nm: 'nm'
+};
+
- while (args.length) {
- var arg = args[0];
+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(' '));
Erik Corry 2009/07/07 11:15:32 I hope this part isn't performance critical in any
Mikhail Naganov 2009/07/07 12:08:10 No, this is just for printing an usage message. B
+ }
+ 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);
+};
+

Powered by Google App Engine
This is Rietveld 408576698