Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

callback/cgroup_perf_recap: Add options for configuring memory / pid polling interval #54936

Merged
merged 1 commit into from
Apr 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 34 additions & 4 deletions lib/ansible/plugins/callback/cgroup_perf_recap.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@
ini:
- section: callback_cgroup_perf_recap
key: cpu_poll_interval
memory_poll_interval:
description: Interval between memory polling for determining memory usage. A lower value may produce inaccurate
results, a higher value may not be short enough to collect results for short tasks.
default: 0.25
type: float
env:
- name: CGROUP_MEMORY_POLL_INTERVAL
ini:
- section: callback_cgroup_perf_recap
key: memory_poll_interval
pid_poll_interval:
description: Interval between PID polling for determining PID count. A lower value may produce inaccurate
results, a higher value may not be short enough to collect results for short tasks.
default: 0.25
type: float
env:
- name: CGROUP_PID_POLL_INTERVAL
ini:
- section: callback_cgroup_perf_recap
key: pid_poll_interval
display_recap:
description: Controls whether the recap is printed at the end, useful if you will automatically
process the output files
Expand Down Expand Up @@ -158,6 +178,10 @@ def poll(self):

class MemoryProf(BaseProf):
"""Python thread for recording memory usage"""
def __init__(self, path, poll_interval=0.25, obj=None, writer=None):
super(MemoryProf, self).__init__(path, obj=obj, writer=writer)
self._poll_interval = poll_interval

def poll(self):
with open(self.path) as f:
val = int(f.read().strip()) / 1024**2
Expand All @@ -169,7 +193,7 @@ def poll(self):
except ValueError:
# We may be profiling after the playbook has ended
self.running = False
time.sleep(0.01)
time.sleep(self._poll_interval)


class CpuProf(BaseProf):
Expand Down Expand Up @@ -197,6 +221,10 @@ def poll(self):


class PidsProf(BaseProf):
def __init__(self, path, poll_interval=0.25, obj=None, writer=None):
super(PidsProf, self).__init__(path, obj=obj, writer=writer)
self._poll_interval = poll_interval

def poll(self):
with open(self.path) as f:
val = int(f.read().strip())
Expand All @@ -208,7 +236,7 @@ def poll(self):
except ValueError:
# We may be profiling after the playbook has ended
self.running = False
time.sleep(0.01)
time.sleep(self._poll_interval)


def csv_writer(writer, timestamp, task_name, task_uuid, value):
Expand Down Expand Up @@ -280,6 +308,8 @@ 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)

cpu_poll_interval = self.get_option('cpu_poll_interval')
memory_poll_interval = self.get_option('memory_poll_interval')
pid_poll_interval = self.get_option('pid_poll_interval')
self._display_recap = self.get_option('display_recap')

control_group = to_bytes(self.get_option('control_group'), errors='surrogate_or_strict')
Expand Down Expand Up @@ -320,9 +350,9 @@ def set_options(self, task_keys=None, var_options=None, direct=None):
return

self._profiler_map = {
'memory': partial(MemoryProf, mem_current_file),
'memory': partial(MemoryProf, mem_current_file, poll_interval=memory_poll_interval),
'cpu': partial(CpuProf, cpu_usage_file, poll_interval=cpu_poll_interval),
'pids': partial(PidsProf, pid_current_file),
'pids': partial(PidsProf, pid_current_file, poll_interval=pid_poll_interval),
}

write_files = self.get_option('write_files')
Expand Down