forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummarize_timings.py
50 lines (38 loc) · 1.34 KB
/
summarize_timings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Script to parse timings out of a Galaxy log and summarize."""
from __future__ import print_function
from argparse import ArgumentParser
import re
import numpy
DESCRIPTION = ""
TIMING_LINE_PATTERN = re.compile("\((\d+.\d+) ms\)")
def main(argv=None):
"""Entry point for script."""
arg_parser = ArgumentParser(description=DESCRIPTION)
arg_parser.add_argument("--file", default="paster.log")
arg_parser.add_argument("--print_lines", default=False, action="store_true")
arg_parser.add_argument("--pattern", default=None)
args = arg_parser.parse_args(argv)
print_lines = args.print_lines
pattern_str = args.pattern
filter_pattern = re.compile(pattern_str) if pattern_str is not None else None
times = []
for line in open(args.file, "r"):
if filter_pattern and not filter_pattern.search(line):
continue
match = TIMING_LINE_PATTERN.search(line)
if not match:
continue
times.append(float(match.group(1)))
if print_lines:
print(line.strip())
template = "Summary (ms) - Mean: %f, Median: %f, Max: %f, Min: %f, StdDev: %f"
message = template % (
numpy.mean(times),
numpy.median(times),
numpy.max(times),
numpy.min(times),
numpy.std(times)
)
print(message)
if __name__ == "__main__":
main()