From d54a3a2ba30f0728f0bc224f1a715e5caa9800e1 Mon Sep 17 00:00:00 2001 From: jwg4 Date: Tue, 15 May 2018 10:52:46 +0000 Subject: [PATCH] Keep a running total of each job runtime. --- callback_plugins/profile_tasks.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/callback_plugins/profile_tasks.py b/callback_plugins/profile_tasks.py index fc93350..9d51ca7 100644 --- a/callback_plugins/profile_tasks.py +++ b/callback_plugins/profile_tasks.py @@ -1,6 +1,7 @@ import datetime import os import time +from collections import defaultdict from ansible.plugins.callback import CallbackBase @@ -10,7 +11,8 @@ class CallbackModule(CallbackBase): """ def __init__(self): super(CallbackModule, self).__init__() - self.stats = {} + self.start_times = {} + self.stats = defaultdict(lambda: 0) self.current = None def playbook_on_task_start(self, name, is_conditional): @@ -23,11 +25,11 @@ def playbook_on_task_start(self, name, is_conditional): if self.current is not None: # Record the running time of the last executed task - self.stats[self.current] = time.time() - self.stats[self.current] + self.stats[self.current] = self.stats[self.current] + (time.time() - self.start_times[self.current]) # Record the start time of the current task self.current = name - self.stats[self.current] = time.time() + self.start_times[self.current] = time.time() def playbook_on_stats(self, stats): """ @@ -39,7 +41,7 @@ def playbook_on_stats(self, stats): # Record the timing of the very last task if self.current is not None: - self.stats[self.current] = time.time() - self.stats[self.current] + self.stats[self.current] = self.stats[self.current] + (time.time() - self.start_times[self.current]) # Sort the tasks by their running time results = sorted(