# Usage: process-ticks.py <logfile>
# Where <logfile> is the log file name (eg, v8.log).
-import subprocess, re, sys, tickprocessor, getopt
+import subprocess, re, sys, tickprocessor
class LinuxTickProcessor(tickprocessor.TickProcessor):
pipe.close()
-def Usage():
- print("Usage: linux-tick-processor.py --{js,gc,compiler,other} logfile-name");
- sys.exit(2)
+class LinuxCmdLineProcessor(tickprocessor.CmdLineProcessor):
+
+ def GetRequiredArgsNames(self):
+ return 'log_file'
+
+ def ProcessRequiredArgs(self, args):
+ if len(args) != 1:
+ self.PrintUsageAndExit()
+ else:
+ self.log_file = args[0]
+
def Main():
- # parse command line options
- ignore_unknown = False
- state = None;
- try:
- opts, args = getopt.getopt(sys.argv[1:], "jgco", ["js", "gc", "compiler", "other", "ignore-unknown"])
- except getopt.GetoptError:
- usage()
- # process options.
- for key, value in opts:
- if key in ("-j", "--js"):
- state = 0
- if key in ("-g", "--gc"):
- state = 1
- if key in ("-c", "--compiler"):
- state = 2
- if key in ("-o", "--other"):
- state = 3
- if key in ("--ignore-unknown"):
- ignore_unknown = True
- # do the processing.
- if len(args) != 1:
- Usage();
+ cmdline_processor = LinuxCmdLineProcessor()
+ cmdline_processor.ProcessArguments()
tick_processor = LinuxTickProcessor()
- tick_processor.ProcessLogfile(args[0], state, ignore_unknown)
+ cmdline_processor.RunLogfileProcessing(tick_processor)
tick_processor.PrintResults()
+
if __name__ == '__main__':
Main()
import csv, splaytree, sys
from operator import itemgetter
-
+import getopt, os
class CodeEntry(object):
'call_path' : stack[0] + ' <- ' + stack[1]
})
+
+class CmdLineProcessor(object):
+
+ def __init__(self):
+ # default values
+ self.state = None
+ self.ignore_unknown = False
+ self.log_file = None
+
+ def ProcessArguments(self):
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "jgco", ["js", "gc", "compiler", "other", "ignore-unknown"])
+ except getopt.GetoptError:
+ self.PrintUsageAndExit()
+ for key, value in opts:
+ if key in ("-j", "--js"):
+ self.state = 0
+ if key in ("-g", "--gc"):
+ self.state = 1
+ if key in ("-c", "--compiler"):
+ self.state = 2
+ if key in ("-o", "--other"):
+ self.state = 3
+ if key in ("--ignore-unknown"):
+ self.ignore_unknown = True
+ self.ProcessRequiredArgs(args)
+
+ def ProcessRequiredArgs(self, args):
+ return
+
+ def GetRequiredArgsNames(self):
+ return
+
+ def PrintUsageAndExit(self):
+ print('Usage: %(script_name)s --{js,gc,compiler,other} %(req_opts)s' % {
+ 'script_name': os.path.basename(sys.argv[0]),
+ 'req_opts': self.GetRequiredArgsNames()
+ })
+ sys.exit(2)
+
+ def RunLogfileProcessing(self, tick_processor):
+ tick_processor.ProcessLogfile(self.log_file, self.state, self.ignore_unknown)
+
+
if __name__ == '__main__':
sys.exit('You probably want to run windows-tick-processor.py or linux-tick-processor.py.')
# only works for statically linked executables - no information about
# shared libraries is logged from v8 on Windows.
-import os, re, sys, tickprocessor, getopt
+import os, re, sys, tickprocessor
class WindowsTickProcessor(tickprocessor.TickProcessor):
finally:
map_file.close()
-def Usage():
- print("Usage: windows-tick-processor.py binary logfile-name");
- sys.exit(2)
+
+class WindowsCmdLineProcessor(tickprocessor.CmdLineProcessor):
+
+ def __init__(self):
+ super(WindowsCmdLineProcessor, self).__init__()
+ self.binary_file = None
+
+ def GetRequiredArgsNames(self):
+ return 'binary log_file'
+
+ def ProcessRequiredArgs(self, args):
+ if len(args) != 2:
+ self.PrintUsageAndExit()
+ else:
+ self.binary_file = args[0]
+ self.log_file = args[1]
+
def Main():
- # parse command line options
- ignore_unknown = False
- state = None;
- try:
- opts, args = getopt.getopt(sys.argv[1:], "jgco", ["js", "gc", "compiler", "other", "ignore-unknown"])
- except getopt.GetoptError:
- usage()
- # process options.
- for key, value in opts:
- if key in ("-j", "--js"):
- state = 0
- if key in ("-g", "--gc"):
- state = 1
- if key in ("-c", "--compiler"):
- state = 2
- if key in ("-o", "--other"):
- state = 3
- if key in ("--ignore-unknown"):
- ignore_unknown = True
- # do the processing.
- if len(args) != 2:
- Usage();
+ cmdline_processor = WindowsCmdLineProcessor()
+ cmdline_processor.ProcessArguments()
tickprocessor = WindowsTickProcessor()
- tickprocessor.ParseMapFile(args[0])
- tickprocessor.ProcessLogfile(args[1], state, ignore_unknown)
+ tickprocessor.ParseMapFile(cmdline_processor.binary_file)
+ cmdline_processor.RunLogfileProcessing(tickprocessor)
tickprocessor.PrintResults()
if __name__ == '__main__':