mirror of
https://github.com/ansible/awx.git
synced 2026-05-06 08:57:35 -02:30
refactor some timedelta formatting in awx-manage bottleneck
This commit is contained in:
@@ -52,6 +52,9 @@ class Command(BaseCommand):
|
|||||||
)
|
)
|
||||||
slowest_events = cursor.fetchall()
|
slowest_events = cursor.fetchall()
|
||||||
|
|
||||||
|
def format_td(x):
|
||||||
|
return str(x).split('.')[0]
|
||||||
|
|
||||||
fastest = dict()
|
fastest = dict()
|
||||||
for event in slowest_events:
|
for event in slowest_events:
|
||||||
_id, job_id, host, duration, task, action, playbook = event
|
_id, job_id, host, duration, task, action, playbook = event
|
||||||
@@ -59,7 +62,7 @@ class Command(BaseCommand):
|
|||||||
if ignore and action in ignore:
|
if ignore and action in ignore:
|
||||||
continue
|
continue
|
||||||
if host:
|
if host:
|
||||||
fastest[(action, playbook)] = (_id, host, str(duration).split('.')[0])
|
fastest[(action, playbook)] = (_id, host, format_td(duration))
|
||||||
|
|
||||||
host_counts = dict()
|
host_counts = dict()
|
||||||
warned = set()
|
warned = set()
|
||||||
@@ -75,12 +78,12 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
fastest_summary = ''
|
fastest_summary = ''
|
||||||
fastest_match = fastest.get((action, playbook))
|
fastest_match = fastest.get((action, playbook))
|
||||||
if fastest_match[2] != duration.total_seconds() and (host, action, playbook) not in warned:
|
if fastest_match[2] != format_td(duration) and (host, action, playbook) not in warned:
|
||||||
warned.add((host, action, playbook))
|
warned.add((host, action, playbook))
|
||||||
fastest_summary = ' ' + self.style.WARNING(f'{fastest_match[1]} ran this in {fastest_match[2]}s at /api/v2/job_events/{fastest_match[0]}/')
|
fastest_summary = ' ' + self.style.WARNING(f'{fastest_match[1]} ran this in {fastest_match[2]}s at /api/v2/job_events/{fastest_match[0]}/')
|
||||||
|
|
||||||
url = f'/api/v2/jobs/{job_id}/'
|
url = f'/api/v2/jobs/{job_id}/'
|
||||||
human_duration = str(duration).split('.')[0]
|
human_duration = format_td(duration)
|
||||||
print(' -- '.join([url, host, human_duration, action, task, playbook]) + fastest_summary)
|
print(' -- '.join([url, host, human_duration, action, task, playbook]) + fastest_summary)
|
||||||
host_counts.setdefault(host, [])
|
host_counts.setdefault(host, [])
|
||||||
host_counts[host].append(duration)
|
host_counts[host].append(duration)
|
||||||
|
|||||||
Reference in New Issue
Block a user