Exemple #1
0
def log(logfile="", mode="w", top=10):
    """Enable logging to the given file.

If the file name is unspecified, a default name is built by appending
a 'log-psyco' extension to the main script name.

Mode is 'a' to append to a possibly existing file or 'w' to overwrite
an existing file. Note that the log file may grow quickly in 'a' mode."""
    import profiler, logger

    if not logfile:
        import os

        logfile, dummy = os.path.splitext(sys.argv[0])
        if os.path.basename(logfile):
            logfile += "."
        logfile += "log-psyco"
    if hasattr(_psyco, "VERBOSE_LEVEL"):
        print >>sys.stderr, "psyco: logging to", logfile
    # logger.current should be a real file object; subtle problems
    # will show up if its write() and flush() methods are written
    # in Python, as Psyco will invoke them while compiling.
    logger.current = open(logfile, mode)
    logger.print_charges = top
    profiler.logger = logger
    logger.writedate("Logging started")
    cannotcompile(logger.psycowrite)
    _psyco.statwrite(logger=logger.psycowrite)
Exemple #2
0
def log(logfile='', mode='w', top=10):
    """Enable logging to the given file.

If the file name is unspecified, a default name is built by appending
a 'log-psyco' extension to the main script name.

Mode is 'a' to append to a possibly existing file or 'w' to overwrite
an existing file. Note that the log file may grow quickly in 'a' mode."""
    import profiler, logger
    if not logfile:
        import os
        logfile, dummy = os.path.splitext(sys.argv[0])
        if os.path.basename(logfile):
            logfile += '.'
        logfile += 'log-psyco'
    if hasattr(_psyco, 'VERBOSE_LEVEL'):
        print >> sys.stderr, 'psyco: logging to', logfile
    # logger.current should be a real file object; subtle problems
    # will show up if its write() and flush() methods are written
    # in Python, as Psyco will invoke them while compiling.
    logger.current = open(logfile, mode)
    logger.print_charges = top
    profiler.logger = logger
    logger.writedate('Logging started')
    cannotcompile(logger.psycowrite)
    _psyco.statwrite(logger=logger.psycowrite)
Exemple #3
0
 def do_profile(self):
     _psyco.statcollect()
     if logger:
         logger.dumpcharges()
     nunit = _psyco.statread('unit') * self.progress
     if nunit > self.reset_limit:
         self.reset()
     else:
         _psyco.statwrite(unit=nunit, callback=self.charge_callback)
     return self.passivealarm_args
Exemple #4
0
 def do_profile(self):
     _psyco.statcollect()
     if logger:
         logger.dumpcharges()
     nunit = _psyco.statread('unit') * self.progress
     if nunit > self.reset_limit:
         self.reset()
     else:
         _psyco.statwrite(unit = nunit, callback = self.charge_callback)
     return self.passivealarm_args
Exemple #5
0
 def reset(self):
     _psyco.statwrite(unit=self.initial_charge_unit, callback=None)
     _psyco.statreset()
     if logger:
         logger.write("%s: resetting stats" % self.__class__.__name__, 1)
Exemple #6
0
 def do_start(self):
     self.init_charges()
     self.active_start()
     _psyco.statwrite(callback=self.charge_callback)
Exemple #7
0
 def do_stop(self):
     _psyco.profiling('.')
     _psyco.statwrite(callback=None)
Exemple #8
0
 def init_charges(self):
     _psyco.statwrite(watermark=self.watermark, parent2=self.parent2)
Exemple #9
0
 def reset(self):
     _psyco.statwrite(unit = self.initial_charge_unit, callback = None)
     _psyco.statreset()
     if logger:
         logger.write("%s: resetting stats" % self.__class__.__name__, 1)
Exemple #10
0
 def do_start(self):
     self.init_charges()
     self.active_start()
     _psyco.statwrite(callback = self.charge_callback)
Exemple #11
0
 def do_stop(self):
     _psyco.profiling('.')
     _psyco.statwrite(callback = None)
Exemple #12
0
 def init_charges(self):
     _psyco.statwrite(watermark = self.watermark,
                      parent2   = self.parent2)