Created
February 3, 2017 03:31
-
-
Save major/b090eaa865b5e86ec9676610acb6b47f to your computer and use it in GitHub Desktop.
Gate Recap Parser for OpenStack-Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# Usage: ./gate-recap-parser.py console-html-url | |
# | |
"""Parse OpenStack-Ansible gate console logs for slow tasks.""" | |
import re | |
import sys | |
import requests | |
def read_console_file(url): | |
"""Read console data from a downloaded file.""" | |
r = requests.get(url, stream=True) | |
for line in r.iter_lines(): | |
yield line | |
regex = r"TASK: (.*)\s-{3,}\s([0-9\.]+)s" | |
metrics = [] | |
for line in read_console_file(sys.argv[1]): | |
match = re.findall(regex, line, re.IGNORECASE) | |
if len(match) > 0: | |
metrics.append(match[0]) | |
total_time = sum([float(x[1]) for x in metrics]) | |
print("{} TOTAL TIME".format(str(total_time).ljust(8))) | |
print("-" * 80) | |
for metric in sorted(metrics, reverse=True, key=lambda x: float(x[1]))[:50]: | |
report_line = "{:8} {}".format(metric[1], metric[0]) | |
print(report_line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment