def create_run(self): start_time = monotonic_clock() self.compute() self.metadata['duration'] = monotonic_clock() - start_time return perf.Run(self.values, warmups=self.warmups, metadata=self.metadata, collect_metadata=False)
def filter(self, record): if (self.except_level is not None and record.levelno >= self.except_level): # don't limit levels >= except_level return True timestamp = monotonic_clock() if timestamp >= self.end_time: self._reset(timestamp) self.counter += 1 return True self.counter += 1 if self.counter <= self.burst: return True if self.emit_warn: # Allow to log our own warning: self.logger is also filtered by # rate limiting return True if self.counter == self.burst + 1: self.emit_warn = True self.logger.error( "Logging rate limit: " "drop after %s records/%s sec", self.burst, self.interval) self.emit_warn = False # Drop the log return False
def filter(self, record): if (self.except_level is not None and record.levelno >= self.except_level): # don't limit levels >= except_level return True timestamp = monotonic_clock() if timestamp >= self.end_time: self._reset(timestamp) self.counter += 1 return True self.counter += 1 if self.counter <= self.burst: return True if self.emit_warn: # Allow to log our own warning: self.logger is also filtered by # rate limiting return True if self.counter == self.burst + 1: self.emit_warn = True self.logger.error("Logging rate limit: " "drop after %s records/%s sec", self.burst, self.interval) self.emit_warn = False # Drop the log return False
def load_controller(min_load, max_load): if max_load is not None: diff = max_load - min_load else: diff = 0.0 if diff < 1.0: max_load = min_load + 1.0 print("Adjust max load: %.2f" % max_load) processes = [] next_stop = monotonic_clock() + NEXT_STOP try: while True: load = get_system_load() print("System load: %.2f (min=%.2f, max=%.2f)" " -- %s child processes" % (load, min_load, max_load, len(processes))) if load < min_load: args = [sys.executable, sys.argv[0], 'burn'] proc = subprocess.Popen(args) processes.append(proc) print("Spawn a new child: %s" % proc.pid) next_stop = monotonic_clock() + NEXT_STOP else: now = monotonic_clock() if now >= next_stop and processes and load > max_load: next_stop = now + NEXT_STOP proc = processes.pop() stop_child(proc) time.sleep(1.0) except KeyboardInterrupt: print() print("CTRL+c: stop") for proc in processes: stop_child(proc) print() print("System load at exit: %.2f" % get_system_load())
def _reset(self, now=None): if now is None: now = monotonic_clock() self.counter = 0 self.end_time = now + self.interval self.emit_warn = False