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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 WindowsCppEntriesProvider.prototype.unmangleName = function(name) { 504 WindowsCppEntriesProvider.prototype.unmangleName = function(name) {
505 // Empty or non-mangled name. 505 // Empty or non-mangled name.
506 if (name.length < 1 || name.charAt(0) != '?') return name; 506 if (name.length < 1 || name.charAt(0) != '?') return name;
507 var nameEndPos = name.indexOf('@@'); 507 var nameEndPos = name.indexOf('@@');
508 var components = name.substring(1, nameEndPos).split('@'); 508 var components = name.substring(1, nameEndPos).split('@');
509 components.reverse(); 509 components.reverse();
510 return components.join('::'); 510 return components.join('::');
511 }; 511 };
512 512
513 513
514 function padRight(s, len) { 514 function ArgumentsProcessor(args) {
515 s = s.toString(); 515 this.args_ = args;
516 if (s.length < len) { 516 this.result_ = ArgumentsProcessor.DEFAULTS;
517 s = s + (new Array(len - s.length + 1).join(' '));
518 }
519 return s;
520 };
521 517
522 518 this.argsDispatch_ = {
523 function processArguments(args) {
524 var result = {
525 logFileName: 'v8.log',
526 platform: 'unix',
527 stateFilter: null,
528 ignoreUnknown: false,
529 separateIc: false,
530 nm: 'nm'
531 };
532 var argsDispatch = {
533 '-j': ['stateFilter', TickProcessor.VmStates.JS, 519 '-j': ['stateFilter', TickProcessor.VmStates.JS,
534 'Show only ticks from JS VM state'], 520 '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
535 '-g': ['stateFilter', TickProcessor.VmStates.GC, 521 '-g': ['stateFilter', TickProcessor.VmStates.GC,
536 'Show only ticks from GC VM state'], 522 'Show only ticks from GC VM state'],
537 '-c': ['stateFilter', TickProcessor.VmStates.COMPILER, 523 '-c': ['stateFilter', TickProcessor.VmStates.COMPILER,
538 'Show only ticks from COMPILER VM state'], 524 'Show only ticks from COMPILER VM state'],
539 '-o': ['stateFilter', TickProcessor.VmStates.OTHER, 525 '-o': ['stateFilter', TickProcessor.VmStates.OTHER,
540 'Show only ticks from OTHER VM state'], 526 'Show only ticks from OTHER VM state'],
541 '-e': ['stateFilter', TickProcessor.VmStates.EXTERNAL, 527 '-e': ['stateFilter', TickProcessor.VmStates.EXTERNAL,
542 'Show only ticks from EXTERNAL VM state'], 528 'Show only ticks from EXTERNAL VM state'],
543 '--ignore-unknown': ['ignoreUnknown', true, 529 '--ignore-unknown': ['ignoreUnknown', true,
544 'Exclude ticks of unknown code entries from processing'], 530 'Exclude ticks of unknown code entries from processing'],
545 '--separate-ic': ['separateIc', true, 531 '--separate-ic': ['separateIc', true,
546 'Separate IC entries'], 532 'Separate IC entries'],
547 '--unix': ['platform', 'unix', 533 '--unix': ['platform', 'unix',
548 'Specify that we are running on *nix platform'], 534 'Specify that we are running on *nix platform'],
549 '--windows': ['platform', 'windows', 535 '--windows': ['platform', 'windows',
550 'Specify that we are running on Windows platform'], 536 'Specify that we are running on Windows platform'],
551 '--nm': ['nm', 'nm', 537 '--nm': ['nm', 'nm',
552 'Specify the \'nm\' executable to use (e.g. --nm=/my_dir/nm)'] 538 'Specify the \'nm\' executable to use (e.g. --nm=/my_dir/nm)']
553 }; 539 };
554 argsDispatch['--js'] = argsDispatch['-j']; 540 this.argsDispatch_['--js'] = this.argsDispatch_['-j'];
555 argsDispatch['--gc'] = argsDispatch['-g']; 541 this.argsDispatch_['--gc'] = this.argsDispatch_['-g'];
556 argsDispatch['--compiler'] = argsDispatch['-c']; 542 this.argsDispatch_['--compiler'] = this.argsDispatch_['-c'];
557 argsDispatch['--other'] = argsDispatch['-o']; 543 this.argsDispatch_['--other'] = this.argsDispatch_['-o'];
558 argsDispatch['--external'] = argsDispatch['-e']; 544 this.argsDispatch_['--external'] = this.argsDispatch_['-e'];
545 };
559 546
560 function printUsageAndExit() {
561 print('Cmdline args: [options] [log-file-name]\n' +
562 'Default log file name is "v8.log".\n');
563 print('Options:');
564 for (var arg in argsDispatch) {
565 var synonims = [arg];
566 var dispatch = argsDispatch[arg];
567 for (var synArg in argsDispatch) {
568 if (arg !== synArg && dispatch === argsDispatch[synArg]) {
569 synonims.push(synArg);
570 delete argsDispatch[synArg];
571 }
572 }
573 print(' ' + padRight(synonims.join(', '), 20) + dispatch[2]);
574 }
575 quit(2);
576 }
577 547
578 while (args.length) { 548 ArgumentsProcessor.DEFAULTS = {
579 var arg = args[0]; 549 logFileName: 'v8.log',
550 platform: 'unix',
551 stateFilter: null,
552 ignoreUnknown: false,
553 separateIc: false,
554 nm: 'nm'
555 };
556
557
558 ArgumentsProcessor.prototype.parse = function() {
559 while (this.args_.length) {
560 var arg = this.args_[0];
580 if (arg.charAt(0) != '-') { 561 if (arg.charAt(0) != '-') {
581 break; 562 break;
582 } 563 }
583 args.shift(); 564 this.args_.shift();
584 var userValue = null; 565 var userValue = null;
585 var eqPos = arg.indexOf('='); 566 var eqPos = arg.indexOf('=');
586 if (eqPos != -1) { 567 if (eqPos != -1) {
587 userValue = arg.substr(eqPos + 1); 568 userValue = arg.substr(eqPos + 1);
588 arg = arg.substr(0, eqPos); 569 arg = arg.substr(0, eqPos);
589 } 570 }
590 if (arg in argsDispatch) { 571 if (arg in this.argsDispatch_) {
591 var dispatch = argsDispatch[arg]; 572 var dispatch = this.argsDispatch_[arg];
592 result[dispatch[0]] = userValue == null ? dispatch[1] : userValue; 573 this.result_[dispatch[0]] = userValue == null ? dispatch[1] : userValue;
593 } else { 574 } else {
594 printUsageAndExit(); 575 return false;
595 } 576 }
596 } 577 }
597 578
598 if (args.length >= 1) { 579 if (this.args_.length >= 1) {
599 result.logFileName = args.shift(); 580 this.result_.logFileName = this.args_.shift();
600 } 581 }
601 return result; 582 return true;
602 }; 583 };
603 584
604 585
605 var params = processArguments(arguments); 586 ArgumentsProcessor.prototype.result = function() {
606 var tickProcessor = new TickProcessor( 587 return this.result_;
607 params.platform == 'unix' ? new UnixCppEntriesProvider(params.nm) : 588 };
608 new WindowsCppEntriesProvider(), 589
609 params.separateIc, 590
610 params.ignoreUnknown, 591 ArgumentsProcessor.prototype.printUsageAndExit = function() {
611 params.stateFilter); 592
612 tickProcessor.processLogFile(params.logFileName); 593 function padRight(s, len) {
613 tickProcessor.printStatistics(); 594 s = s.toString();
595 if (s.length < len) {
596 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
597 }
598 return s;
599 }
600
601 print('Cmdline args: [options] [log-file-name]\n' +
602 'Default log file name is "' +
603 ArgumentsProcessor.DEFAULTS.logFileName + '".\n');
604 print('Options:');
605 for (var arg in this.argsDispatch_) {
606 var synonims = [arg];
607 var dispatch = this.argsDispatch_[arg];
608 for (var synArg in this.argsDispatch_) {
609 if (arg !== synArg && dispatch === this.argsDispatch_[synArg]) {
610 synonims.push(synArg);
611 delete this.argsDispatch_[synArg];
612 }
613 }
614 print(' ' + padRight(synonims.join(', '), 20) + dispatch[2]);
615 }
616 quit(2);
617 };
618
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698