mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-01-11 23:25:28 +01:00
Correctly calculate task execution time with serial execution
- Fixes #83 Signed-off-by: Hideki Saito <saito@fgrep.org>
This commit is contained in:
parent
7f16f56c5b
commit
3d57a17ed6
2 changed files with 15 additions and 4 deletions
3
changelogs/fragments/263_profile_tasks_with_serial.yml
Normal file
3
changelogs/fragments/263_profile_tasks_with_serial.yml
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
bugfixes:
|
||||||
|
- profile_tasks - Correctly calculate task execution time with serial execution (https://github.com/ansible-collections/ansible.posix/issues/83).
|
||||||
|
|
@ -92,7 +92,8 @@ def filled(msg, fchar="*"):
|
||||||
|
|
||||||
def timestamp(self):
|
def timestamp(self):
|
||||||
if self.current is not None:
|
if self.current is not None:
|
||||||
self.stats[self.current]['time'] = time.time() - self.stats[self.current]['time']
|
elapsed = time.time() - self.stats[self.current]['started']
|
||||||
|
self.stats[self.current]['elapsed'] += elapsed
|
||||||
|
|
||||||
|
|
||||||
def tasktime():
|
def tasktime():
|
||||||
|
|
@ -151,8 +152,15 @@ class CallbackModule(CallbackBase):
|
||||||
timestamp(self)
|
timestamp(self)
|
||||||
|
|
||||||
# Record the start time of the current task
|
# Record the start time of the current task
|
||||||
|
# stats[TASK_UUID]:
|
||||||
|
# started: Current task start time. This value will be updated each time a task
|
||||||
|
# with the same UUID is executed when `serial` is specified in a playbook.
|
||||||
|
# elapsed: Elapsed time since the first serialized task was started
|
||||||
self.current = task._uuid
|
self.current = task._uuid
|
||||||
self.stats[self.current] = {'time': time.time(), 'name': task.get_name()}
|
if self.current not in self.stats:
|
||||||
|
self.stats[self.current] = {'started': time.time(), 'elapsed': 0.0, 'name': task.get_name()}
|
||||||
|
else:
|
||||||
|
self.stats[self.current]['started'] = time.time()
|
||||||
if self._display.verbosity >= 2:
|
if self._display.verbosity >= 2:
|
||||||
self.stats[self.current]['path'] = task.get_path()
|
self.stats[self.current]['path'] = task.get_path()
|
||||||
|
|
||||||
|
|
@ -178,7 +186,7 @@ class CallbackModule(CallbackBase):
|
||||||
if self.sort_order is not None:
|
if self.sort_order is not None:
|
||||||
results = sorted(
|
results = sorted(
|
||||||
self.stats.items(),
|
self.stats.items(),
|
||||||
key=lambda x: x[1]['time'],
|
key=lambda x: x[1]['elapsed'],
|
||||||
reverse=self.sort_order,
|
reverse=self.sort_order,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -187,7 +195,7 @@ class CallbackModule(CallbackBase):
|
||||||
|
|
||||||
# Print the timings
|
# Print the timings
|
||||||
for uuid, result in results:
|
for uuid, result in results:
|
||||||
msg = u"{0:-<{2}}{1:->9}".format(result['name'] + u' ', u' {0:.02f}s'.format(result['time']), self._display.columns - 9)
|
msg = u"{0:-<{2}}{1:->9}".format(result['name'] + u' ', u' {0:.02f}s'.format(result['elapsed']), self._display.columns - 9)
|
||||||
if 'path' in result:
|
if 'path' in result:
|
||||||
msg += u"\n{0:-<{1}}".format(result['path'] + u' ', self._display.columns)
|
msg += u"\n{0:-<{1}}".format(result['path'] + u' ', self._display.columns)
|
||||||
self._display.display(msg)
|
self._display.display(msg)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue