Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
pybench.PyBenchCmdline Class Reference
Inheritance diagram for pybench.PyBenchCmdline:
Inheritance graph
[legend]
Collaboration diagram for pybench.PyBenchCmdline:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def main
def add_option
def startup
def exit
def parse
def check_files
def help
def notice
def print_header
def print_options
def handle_files
def handle_h
def handle_v
def handle__help
def handle__debug
def handle__copyright
def handle__examples

Public Attributes

 name
 verbose
 filename
 arguments
 option_map

Static Public Attributes

tuple header
 version = __version__
 debug = _debug
list options
string about
 copyright = __copyright__
list preset_options
string name = ''
string synopsis = '%(name)s [option] files...'
string examples = ''
int globbing = 1
int verbose = 0
 InternalError = BaseException
 values = None
 files = None
 optionlist = None

Detailed Description

Definition at line 744 of file pybench.py.


Member Function Documentation

def CommandLine.Application.add_option (   self,
  option 
) [inherited]
Add a new Option instance to the Application dynamically.

    Note that this has to be done *before* .parse() is being
    executed.

Definition at line 376 of file CommandLine.py.

00376 
00377     def add_option(self, option):
00378 
00379         """ Add a new Option instance to the Application dynamically.
00380 
00381             Note that this has to be done *before* .parse() is being
00382             executed.
00383 
00384         """
00385         self.options.append(option)
00386         self.option_map[option.name] = option

def CommandLine.Application.check_files (   self,
  filelist 
) [inherited]
Apply some user defined checks on the files given in filelist.

    This may modify filelist in place. A typical application
    is checking that at least n files are given.

    If this method returns anything other than None, the
    process is terminated with the return value as exit code.

Definition at line 482 of file CommandLine.py.

00482 
00483     def check_files(self,filelist):
00484 
00485         """ Apply some user defined checks on the files given in filelist.
00486 
00487             This may modify filelist in place. A typical application
00488             is checking that at least n files are given.
00489 
00490             If this method returns anything other than None, the
00491             process is terminated with the return value as exit code.
00492 
00493         """
00494         return None

Here is the caller graph for this function:

def CommandLine.Application.exit (   self,
  rc = 0 
) [inherited]
Exit the program.

    rc is used as exit code and passed back to the calling
    program. It defaults to 0 which usually means: OK.

Definition at line 397 of file CommandLine.py.

00397 
00398     def exit(self, rc=0):
00399 
00400         """ Exit the program.
00401 
00402             rc is used as exit code and passed back to the calling
00403             program. It defaults to 0 which usually means: OK.
00404 
00405         """
00406         raise SystemExit(rc)

def CommandLine.Application.handle__copyright (   self,
  arg 
) [inherited]

Definition at line 588 of file CommandLine.py.

00588 
00589     def handle__copyright(self,arg):
00590 
00591         self.print_header()
00592         copyright = self.copyright % self.__dict__
00593         print(copyright.strip())
00594         print()
00595         return 0

Here is the call graph for this function:

def CommandLine.Application.handle__debug (   self,
  arg 
) [inherited]

Definition at line 581 of file CommandLine.py.

00581 
00582     def handle__debug(self,arg):
00583 
00584         self.debug = 1
00585         # We don't want to catch internal errors:
00586         class NoErrorToCatch(Exception): pass
00587         self.InternalError = NoErrorToCatch

def CommandLine.Application.handle__examples (   self,
  arg 
) [inherited]

Definition at line 596 of file CommandLine.py.

00596 
00597     def handle__examples(self,arg):
00598 
00599         self.print_header()
00600         if self.examples:
00601             print('Examples:')
00602             print()
00603             examples = self.examples % self.__dict__
00604             print(examples.strip())
00605             print()
00606         else:
00607             print('No examples available.')
00608             print()
00609         return 0

Here is the call graph for this function:

def CommandLine.Application.handle__help (   self,
  arg 
) [inherited]

Definition at line 576 of file CommandLine.py.

00576 
00577     def handle__help(self,arg):
00578 
00579         self.help()
00580         return 0

Here is the call graph for this function:

def CommandLine.Application.handle_files (   self,
  files 
) [inherited]
This may process the files list in place.

Definition at line 557 of file CommandLine.py.

00557 
00558     def handle_files(self,files):
00559 
00560         """ This may process the files list in place.
00561         """
00562         return None

Here is the caller graph for this function:

def CommandLine.Application.handle_h (   self,
  arg 
) [inherited]

Definition at line 564 of file CommandLine.py.

00564 
00565     def handle_h(self,arg):
00566 
00567         self.help()
00568         return 0

Here is the call graph for this function:

def CommandLine.Application.handle_v (   self,
  value 
) [inherited]
Turn on verbose output.

Definition at line 569 of file CommandLine.py.

00569 
00570     def handle_v(self, value):
00571 
00572         """ Turn on verbose output.
00573         """
00574         self.verbose = 1

def CommandLine.Application.help (   self,
  note = '' 
) [inherited]

Definition at line 495 of file CommandLine.py.

00495 
00496     def help(self,note=''):
00497 
00498         self.print_header()
00499         if self.synopsis:
00500             print('Synopsis:')
00501             # To remain backward compatible:
00502             try:
00503                 synopsis = self.synopsis % self.name
00504             except (NameError, KeyError, TypeError):
00505                 synopsis = self.synopsis % self.__dict__
00506             print(' ' + synopsis)
00507         print()
00508         self.print_options()
00509         if self.version:
00510             print('Version:')
00511             print(' %s' % self.version)
00512             print()
00513         if self.about:
00514             about = self.about % self.__dict__
00515             print(about.strip())
00516             print()
00517         if note:
00518             print('-'*72)
00519             print('Note:',note)
00520             print()

Here is the call graph for this function:

Here is the caller graph for this function:

Override this method as program entry point.

    The return value is passed to sys.exit() as argument.  If
    it is None, 0 is assumed (meaning OK). Unhandled
    exceptions are reported with exit status code 1 (see
    __init__ for further details).

Reimplemented from CommandLine.Application.

Definition at line 809 of file pybench.py.

00809 
00810     def main(self):
00811 
00812         rounds = self.values['-n']
00813         reportfile = self.values['-f']
00814         show_bench = self.values['-s']
00815         compare_to = self.values['-c']
00816         hidenoise = self.values['-d']
00817         warp = int(self.values['-w'])
00818         withgc = self.values['--with-gc']
00819         limitnames = self.values['-t']
00820         if limitnames:
00821             if _debug:
00822                 print('* limiting test names to one with substring "%s"' % \
00823                       limitnames)
00824             limitnames = re.compile(limitnames, re.I)
00825         else:
00826             limitnames = None
00827         verbose = self.verbose
00828         withsyscheck = self.values['--with-syscheck']
00829         calibration_runs = self.values['-C']
00830         timer = self.values['--timer']
00831 
00832         print('-' * LINE)
00833         print('PYBENCH %s' % __version__)
00834         print('-' * LINE)
00835         print('* using %s %s' % (
00836             getattr(platform, 'python_implementation', lambda:'Python')(),
00837             ' '.join(sys.version.split())))
00838 
00839         # Switch off garbage collection
00840         if not withgc:
00841             try:
00842                 import gc
00843             except ImportError:
00844                 print('* Python version doesn\'t support garbage collection')
00845             else:
00846                 try:
00847                     gc.disable()
00848                 except NotImplementedError:
00849                     print('* Python version doesn\'t support gc.disable')
00850                 else:
00851                     print('* disabled garbage collection')
00852 
00853         # "Disable" sys check interval
00854         if not withsyscheck:
00855             # Too bad the check interval uses an int instead of a long...
00856             value = 2147483647
00857             try:
00858                 sys.setcheckinterval(value)
00859             except (AttributeError, NotImplementedError):
00860                 print('* Python version doesn\'t support sys.setcheckinterval')
00861             else:
00862                 print('* system check interval set to maximum: %s' % value)
00863 
00864         if timer == TIMER_SYSTIMES_PROCESSTIME:
00865             import systimes
00866             print('* using timer: systimes.processtime (%s)' % \
00867                   systimes.SYSTIMES_IMPLEMENTATION)
00868         else:
00869             print('* using timer: %s' % timer)
00870 
00871         print()
00872 
00873         if compare_to:
00874             try:
00875                 f = open(compare_to,'rb')
00876                 bench = pickle.load(f)
00877                 bench.name = compare_to
00878                 f.close()
00879                 compare_to = bench
00880             except IOError as reason:
00881                 print('* Error opening/reading file %s: %s' % (
00882                     repr(compare_to),
00883                     reason))
00884                 compare_to = None
00885 
00886         if show_bench:
00887             try:
00888                 f = open(show_bench,'rb')
00889                 bench = pickle.load(f)
00890                 bench.name = show_bench
00891                 f.close()
00892                 bench.print_header()
00893                 if compare_to:
00894                     bench.print_comparison(compare_to,
00895                                            hidenoise=hidenoise,
00896                                            limitnames=limitnames)
00897                 else:
00898                     bench.print_benchmark(hidenoise=hidenoise,
00899                                           limitnames=limitnames)
00900             except IOError as reason:
00901                 print('* Error opening/reading file %s: %s' % (
00902                     repr(show_bench),
00903                     reason))
00904                 print()
00905             return
00906 
00907         if reportfile:
00908             print('Creating benchmark: %s (rounds=%i, warp=%i)' % \
00909                   (reportfile, rounds, warp))
00910             print()
00911 
00912         # Create benchmark object
00913         bench = Benchmark(reportfile,
00914                           verbose=verbose,
00915                           timer=timer,
00916                           warp=warp,
00917                           calibration_runs=calibration_runs)
00918         bench.rounds = rounds
00919         bench.load_tests(Setup, limitnames=limitnames)
00920         try:
00921             bench.calibrate()
00922             bench.run()
00923         except KeyboardInterrupt:
00924             print()
00925             print('*** KeyboardInterrupt -- Aborting')
00926             print()
00927             return
00928         bench.print_header()
00929         if compare_to:
00930             bench.print_comparison(compare_to,
00931                                    hidenoise=hidenoise,
00932                                    limitnames=limitnames)
00933         else:
00934             bench.print_benchmark(hidenoise=hidenoise,
00935                                   limitnames=limitnames)
00936 
00937         # Ring bell
00938         sys.stderr.write('\007')
00939 
00940         if reportfile:
00941             try:
00942                 f = open(reportfile,'wb')
00943                 bench.name = reportfile
00944                 pickle.dump(bench,f)
00945                 f.close()
00946             except IOError as reason:
00947                 print('* Error opening/writing reportfile')
00948             except IOError as reason:
00949                 print('* Error opening/writing reportfile %s: %s' % (
00950                     reportfile,
00951                     reason))
00952                 print()

Here is the call graph for this function:

def CommandLine.Application.notice (   self,
  note 
) [inherited]

Definition at line 521 of file CommandLine.py.

00521 
00522     def notice(self,note):
00523 
00524         print('-'*72)
00525         print('Note:',note)
00526         print('-'*72)
00527         print()

def CommandLine.Application.parse (   self) [inherited]
Parse the command line and fill in self.values and self.files.

    After having parsed the options, the remaining command line
    arguments are interpreted as files and passed to .handle_files()
    for processing.

    As final step the option handlers are called in the order
    of the options given on the command line.

Definition at line 407 of file CommandLine.py.

00407 
00408     def parse(self):
00409 
00410         """ Parse the command line and fill in self.values and self.files.
00411 
00412             After having parsed the options, the remaining command line
00413             arguments are interpreted as files and passed to .handle_files()
00414             for processing.
00415 
00416             As final step the option handlers are called in the order
00417             of the options given on the command line.
00418 
00419         """
00420         # Parse arguments
00421         self.values = values = {}
00422         for o in self.options:
00423             if o.has_default:
00424                 values[o.prefix+o.name] = o.default
00425             else:
00426                 values[o.prefix+o.name] = 0
00427         flags,lflags = _getopt_flags(self.options)
00428         try:
00429             optlist,files = getopt.getopt(self.arguments,flags,lflags)
00430             if self.globbing:
00431                 l = []
00432                 for f in files:
00433                     gf = glob.glob(f)
00434                     if not gf:
00435                         l.append(f)
00436                     else:
00437                         l[len(l):] = gf
00438                 files = l
00439             self.optionlist = optlist
00440             self.files = files + self.files
00441         except getopt.error as why:
00442             self.help(why)
00443             sys.exit(1)
00444 
00445         # Call file handler
00446         rc = self.handle_files(self.files)
00447         if rc is not None:
00448             sys.exit(rc)
00449 
00450         # Call option handlers
00451         for optionname, value in optlist:
00452 
00453             # Try to convert value to integer
00454             try:
00455                 value = int(value)
00456             except ValueError:
00457                 pass
00458 
00459             # Find handler and call it (or count the number of option
00460             # instances on the command line)
00461             handlername = 'handle' + optionname.replace('-', '_')
00462             try:
00463                 handler = getattr(self, handlername)
00464             except AttributeError:
00465                 if value == '':
00466                     # count the number of occurances
00467                     if optionname in values:
00468                         values[optionname] = values[optionname] + 1
00469                     else:
00470                         values[optionname] = 1
00471                 else:
00472                     values[optionname] = value
00473             else:
00474                 rc = handler(value)
00475                 if rc is not None:
00476                     raise SystemExit(rc)
00477 
00478         # Apply final file check (for backward compatibility)
00479         rc = self.check_files(self.files)
00480         if rc is not None:
00481             sys.exit(rc)

Here is the call graph for this function:

Here is the caller graph for this function:

def CommandLine.Application.print_header (   self) [inherited]

Definition at line 528 of file CommandLine.py.

00528 
00529     def print_header(self):
00530 
00531         print('-'*72)
00532         print(self.header % self.__dict__)
00533         print('-'*72)
00534         print()

Here is the caller graph for this function:

def CommandLine.Application.print_options (   self) [inherited]

Definition at line 535 of file CommandLine.py.

00535 
00536     def print_options(self):
00537 
00538         options = self.options
00539         print('Options and default settings:')
00540         if not options:
00541             print('  None')
00542             return
00543         int = [x for x in options if x.prefix == '--']
00544         short = [x for x in options if x.prefix == '-']
00545         items = short + int
00546         for o in options:
00547             print(' ',o)
00548         print()

Here is the caller graph for this function:

def CommandLine.Application.startup (   self) [inherited]
Set user defined instance variables.

    If this method returns anything other than None, the
    process is terminated with the return value as exit code.

Definition at line 387 of file CommandLine.py.

00387 
00388     def startup(self):
00389 
00390         """ Set user defined instance variables.
00391 
00392             If this method returns anything other than None, the
00393             process is terminated with the return value as exit code.
00394 
00395         """
00396         return None


Member Data Documentation

Initial value:
"""\
The normal operation is to run the suite and display the
results. Use -f to save them for later reuse or comparisons.

Available timers:

   time.time
   time.clock
   systimes.processtime

Examples:

python2.1 pybench.py -f p21.pybench
python2.5 pybench.py -f p25.pybench
python pybench.py -s p25.pybench -c p21.pybench
"""

Reimplemented from CommandLine.Application.

Definition at line 791 of file pybench.py.

Definition at line 322 of file CommandLine.py.

Reimplemented from CommandLine.Application.

Definition at line 807 of file pybench.py.

Reimplemented from CommandLine.Application.

Definition at line 751 of file pybench.py.

string CommandLine.Application.examples = '' [static, inherited]

Definition at line 283 of file CommandLine.py.

Definition at line 311 of file CommandLine.py.

CommandLine.Application.files = None [static, inherited]

Definition at line 303 of file CommandLine.py.

int CommandLine.Application.globbing = 1 [static, inherited]

Definition at line 289 of file CommandLine.py.

Initial value:
("PYBENCH - a benchmark test suite for Python "
              "interpreters/compilers.")

Reimplemented from CommandLine.Application.

Definition at line 746 of file pybench.py.

CommandLine.Application.InternalError = BaseException [static, inherited]

Definition at line 298 of file CommandLine.py.

string CommandLine.Application.name = '' [static, inherited]

Definition at line 271 of file CommandLine.py.

Definition at line 313 of file CommandLine.py.

Definition at line 325 of file CommandLine.py.

CommandLine.Application.optionlist = None [static, inherited]

Definition at line 304 of file CommandLine.py.

Reimplemented from CommandLine.Application.

Definition at line 753 of file pybench.py.

list CommandLine.Application.preset_options [static, inherited]
Initial value:
[SwitchOption('-v',
                                   'generate verbose output'),
                      SwitchOption('-h',
                                   'show this help text'),
                      SwitchOption('--help',
                                   'show this help text'),
                      SwitchOption('--debug',
                                   'enable debugging'),
                      SwitchOption('--copyright',
                                   'show copyright'),
                      SwitchOption('--examples',
                                   'show examples of usage')]

Definition at line 237 of file CommandLine.py.

string CommandLine.Application.synopsis = '%(name)s [option] files...' [static, inherited]

Definition at line 274 of file CommandLine.py.

CommandLine.Application.values = None [static, inherited]

Definition at line 301 of file CommandLine.py.

int CommandLine.Application.verbose = 0 [static, inherited]

Definition at line 295 of file CommandLine.py.

Definition at line 573 of file CommandLine.py.

Reimplemented from CommandLine.Application.

Definition at line 749 of file pybench.py.


The documentation for this class was generated from the following file: