class Profiler: MemoryTimerResolution = 0.103 def run(self, memory, time, memorymax, timemax): self.memory = memory self.memorymax = memorymax self.time = time if timemax is None: self.endtime = None else: self.endtime = now() + timemax self.alarms = [] profilers.append(self) go() def start(self): curmem = _psyco.memory() memlimits = [] if self.memorymax is not None: if curmem >= self.memorymax: if logger: logger.writememory() return self.limitreached('memorymax') memlimits.append(self.memorymax) if self.memory is not None: if self.memory <= 0: if logger: logger.writememory() return self.limitreached('memory') memlimits.append(curmem + self.memory) self.memory_at_start = curmem curtime = now() timelimits = [] if self.endtime is not None: if curtime >= self.endtime: return self.limitreached('timemax') timelimits.append(self.endtime - curtime) if self.time is not None: if self.time <= 0.0: return self.limitreached('time') timelimits.append(self.time) self.time_at_start = curtime try: self.do_start() except error, e: if logger: logger.write( '%s: disabled by psyco.error:' % (self.__class__.__name__), 4) logger.write(' %s' % str(e), 3) return 0 if memlimits: self.memlimits_args = (time.sleep, (self.MemoryTimerResolution, ), self.check_memory, (min(memlimits), )) self.alarms.append(_psyco.alarm(*self.memlimits_args)) if timelimits: self.alarms.append( _psyco.alarm(time.sleep, (min(timelimits), ), self.time_out)) return 1
def passive_start(self): self.passivealarm_args = (time.sleep, (1.0 / self.pollfreq, ), self.do_profile) self.alarms.append(_psyco.alarm(*self.passivealarm_args))
def passive_start(self): self.passivealarm_args = (time.sleep, (1.0 / self.pollfreq,), self.do_profile) self.alarms.append(_psyco.alarm(*self.passivealarm_args))