mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-01-11 15:15:26 +01:00
Feat/add summary only option to profile callbacks (#511)
* profile_tasks callback: add parameter to show only summary
This commit is contained in:
parent
0a07bdb358
commit
51b94f536c
3 changed files with 54 additions and 6 deletions
|
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
minor_changes:
|
||||||
|
- "Add summary_only parameter to profile_roles and profile_tasks callbacks."
|
||||||
|
|
@ -14,6 +14,19 @@ DOCUMENTATION = '''
|
||||||
- This callback module provides profiling for ansible roles.
|
- This callback module provides profiling for ansible roles.
|
||||||
requirements:
|
requirements:
|
||||||
- whitelisting in configuration
|
- whitelisting in configuration
|
||||||
|
options:
|
||||||
|
summary_only:
|
||||||
|
description:
|
||||||
|
- Only show summary, not individual task profiles.
|
||||||
|
Especially usefull in combination with C(DISPLAY_SKIPPED_HOSTS=false) and/or C(ANSIBLE_DISPLAY_OK_HOSTS=false).
|
||||||
|
type: bool
|
||||||
|
default: False
|
||||||
|
env:
|
||||||
|
- name: PROFILE_ROLES_SUMMARY_ONLY
|
||||||
|
ini:
|
||||||
|
- section: callback_profile_roles
|
||||||
|
key: summary_only
|
||||||
|
version_added: 1.5.0
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
|
@ -76,13 +89,26 @@ class CallbackModule(CallbackBase):
|
||||||
self.stats = collections.Counter()
|
self.stats = collections.Counter()
|
||||||
self.totals = collections.Counter()
|
self.totals = collections.Counter()
|
||||||
self.current = None
|
self.current = None
|
||||||
|
|
||||||
|
self.summary_only = None
|
||||||
|
|
||||||
super(CallbackModule, self).__init__()
|
super(CallbackModule, self).__init__()
|
||||||
|
|
||||||
|
def set_options(self, task_keys=None, var_options=None, direct=None):
|
||||||
|
|
||||||
|
super(CallbackModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct)
|
||||||
|
|
||||||
|
self.summary_only = self.get_option('summary_only')
|
||||||
|
|
||||||
|
def _display_tasktime(self):
|
||||||
|
if not self.summary_only:
|
||||||
|
self._display.display(tasktime())
|
||||||
|
|
||||||
def _record_task(self, task):
|
def _record_task(self, task):
|
||||||
"""
|
"""
|
||||||
Logs the start of each task
|
Logs the start of each task
|
||||||
"""
|
"""
|
||||||
self._display.display(tasktime())
|
self._display_tasktime()
|
||||||
timestamp(self)
|
timestamp(self)
|
||||||
|
|
||||||
if task._role:
|
if task._role:
|
||||||
|
|
@ -99,10 +125,10 @@ class CallbackModule(CallbackBase):
|
||||||
self._record_task(task)
|
self._record_task(task)
|
||||||
|
|
||||||
def playbook_on_setup(self):
|
def playbook_on_setup(self):
|
||||||
self._display.display(tasktime())
|
self._display_tasktime()
|
||||||
|
|
||||||
def playbook_on_stats(self, stats):
|
def playbook_on_stats(self, stats):
|
||||||
self._display.display(tasktime())
|
self._display_tasktime()
|
||||||
self._display.display(filled("", fchar="="))
|
self._display.display(filled("", fchar="="))
|
||||||
|
|
||||||
timestamp(self)
|
timestamp(self)
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,18 @@ DOCUMENTATION = '''
|
||||||
ini:
|
ini:
|
||||||
- section: callback_profile_tasks
|
- section: callback_profile_tasks
|
||||||
key: sort_order
|
key: sort_order
|
||||||
|
summary_only:
|
||||||
|
description:
|
||||||
|
- Only show summary, not individual task profiles.
|
||||||
|
Especially usefull in combination with C(DISPLAY_SKIPPED_HOSTS=false) and/or C(ANSIBLE_DISPLAY_OK_HOSTS=false).
|
||||||
|
type: bool
|
||||||
|
default: False
|
||||||
|
env:
|
||||||
|
- name: PROFILE_TASKS_SUMMARY_ONLY
|
||||||
|
ini:
|
||||||
|
- section: callback_profile_tasks
|
||||||
|
key: summary_only
|
||||||
|
version_added: 1.5.0
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
|
@ -120,6 +132,7 @@ class CallbackModule(CallbackBase):
|
||||||
self.current = None
|
self.current = None
|
||||||
|
|
||||||
self.sort_order = None
|
self.sort_order = None
|
||||||
|
self.summary_only = None
|
||||||
self.task_output_limit = None
|
self.task_output_limit = None
|
||||||
|
|
||||||
super(CallbackModule, self).__init__()
|
super(CallbackModule, self).__init__()
|
||||||
|
|
@ -137,6 +150,8 @@ class CallbackModule(CallbackBase):
|
||||||
elif self.sort_order == 'none':
|
elif self.sort_order == 'none':
|
||||||
self.sort_order = None
|
self.sort_order = None
|
||||||
|
|
||||||
|
self.summary_only = self.get_option('summary_only')
|
||||||
|
|
||||||
self.task_output_limit = self.get_option('output_limit')
|
self.task_output_limit = self.get_option('output_limit')
|
||||||
if self.task_output_limit is not None:
|
if self.task_output_limit is not None:
|
||||||
if self.task_output_limit == 'all':
|
if self.task_output_limit == 'all':
|
||||||
|
|
@ -144,11 +159,15 @@ class CallbackModule(CallbackBase):
|
||||||
else:
|
else:
|
||||||
self.task_output_limit = int(self.task_output_limit)
|
self.task_output_limit = int(self.task_output_limit)
|
||||||
|
|
||||||
|
def _display_tasktime(self):
|
||||||
|
if not self.summary_only:
|
||||||
|
self._display.display(tasktime())
|
||||||
|
|
||||||
def _record_task(self, task):
|
def _record_task(self, task):
|
||||||
"""
|
"""
|
||||||
Logs the start of each task
|
Logs the start of each task
|
||||||
"""
|
"""
|
||||||
self._display.display(tasktime())
|
self._display_tasktime()
|
||||||
timestamp(self)
|
timestamp(self)
|
||||||
|
|
||||||
# Record the start time of the current task
|
# Record the start time of the current task
|
||||||
|
|
@ -171,10 +190,10 @@ class CallbackModule(CallbackBase):
|
||||||
self._record_task(task)
|
self._record_task(task)
|
||||||
|
|
||||||
def playbook_on_setup(self):
|
def playbook_on_setup(self):
|
||||||
self._display.display(tasktime())
|
self._display_tasktime()
|
||||||
|
|
||||||
def playbook_on_stats(self, stats):
|
def playbook_on_stats(self, stats):
|
||||||
self._display.display(tasktime())
|
self._display_tasktime()
|
||||||
self._display.display(filled("", fchar="="))
|
self._display.display(filled("", fchar="="))
|
||||||
|
|
||||||
timestamp(self)
|
timestamp(self)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue