def parse_log(lines, verbose=False): color = "(?:\x1b.*?m)?" r_start = re.compile(color + r"\[([0-9a-fA-F]+)\] \{([\w-]+)" + color + "$") r_stop = re.compile(color + r"\[([0-9a-fA-F]+)\] ([\w-]+)\}" + color + "$") lasttime = 0 log = DebugLog() time_decrase = False performance_log = True nested = 0 # if verbose and sys.stdout.isatty(): progress = progressbar.ProgressBar(color='green') counter = 0 else: progress = None single_percent = len(lines) / 100 if verbose: vnext = 0 else: vnext = -1 for i, line in enumerate(lines): if i == vnext: if progress is not None: progress.render(counter) counter += 1 vnext += single_percent else: sys.stderr.write('%d%%..' % int(100.0 * i / len(lines))) vnext += 500000 line = line.rstrip() match = r_start.match(line) if match: record = log.debug_start nested += 1 else: match = r_stop.match(line) if match: record = log.debug_stop nested -= 1 else: log.debug_print(line) performance_log = performance_log and nested == 0 continue time = int(int(match.group(1), 16)) time_decrase = time_decrase or time < lasttime lasttime = time record(match.group(2), time=int(match.group(1), 16)) if verbose: sys.stderr.write('loaded\n') if performance_log and time_decrase: print( "The time decreases! The log file may have been" " produced on a multi-CPU machine and the process" " moved between CPUs.") return log
def parse_log(lines, verbose=False): color = "(?:\x1b.*?m)?" r_start = re.compile(color + r"\[([0-9a-fA-F]+)\] \{([\w-]+)" + color + "$") r_stop = re.compile(color + r"\[([0-9a-fA-F]+)\] ([\w-]+)\}" + color + "$") lasttime = 0 log = DebugLog() time_decrase = False performance_log = True nested = 0 # if verbose and sys.stdout.isatty(): progress = progressbar.ProgressBar(color='green') counter = 0 else: progress = None single_percent = len(lines) / 100 if verbose: vnext = 0 else: vnext = -1 for i, line in enumerate(lines): if i == vnext: if progress is not None: progress.render(counter) counter += 1 vnext += single_percent else: sys.stderr.write('%d%%..' % int(100.0*i/len(lines))) vnext += 500000 line = line.rstrip() match = r_start.match(line) if match: record = log.debug_start nested += 1 else: match = r_stop.match(line) if match: record = log.debug_stop nested -= 1 else: log.debug_print(line) performance_log = performance_log and nested == 0 continue time = int(int(match.group(1), 16)) time_decrase = time_decrase or time < lasttime lasttime = time record(match.group(2), time=int(match.group(1), 16)) if verbose: sys.stderr.write('loaded\n') if performance_log and time_decrase: raise Exception("The time decreases! The log file may have been" " produced on a multi-CPU machine and the process" " moved between CPUs.") return log
def parse_log_file(filename, verbose=True): r_start = re.compile(r"\[([0-9a-fA-F]+)\] \{([\w-]+)$") r_stop = re.compile(r"\[([0-9a-fA-F]+)\] ([\w-]+)\}$") lasttime = 0 log = DebugLog() time_decrase = False performance_log = True nested = 0 # f = open(filename, 'r') if f.read(2) == 'BZ': f.close() import bz2 f = bz2.BZ2File(filename, 'r') else: f.seek(0) lines = f.readlines() f.close() # if verbose: vnext = 0 else: vnext = len(lines) for i, line in enumerate(lines): if i == vnext: sys.stderr.write('%d%%..' % int(100.0*i/len(lines))) vnext += 500000 line = line.rstrip() match = r_start.match(line) if match: record = log.debug_start nested += 1 else: match = r_stop.match(line) if match: record = log.debug_stop nested -= 1 else: log.debug_print(line) performance_log = performance_log and nested == 0 continue time = int(int(match.group(1), 16)) time_decrase = time_decrase or time < lasttime lasttime = time record(match.group(2), time=int(match.group(1), 16)) if verbose: sys.stderr.write('loaded\n') if performance_log and time_decrase: raise Exception("The time decreases! The log file may have been" " produced on a multi-CPU machine and the process" " moved between CPUs.") return log