Skip to content

Instantly share code, notes, and snippets.

@jctanner
Last active December 15, 2017 17:03
Show Gist options
  • Save jctanner/6cf5b571539cad33180ce87239b4b432 to your computer and use it in GitHub Desktop.
Save jctanner/6cf5b571539cad33180ce87239b4b432 to your computer and use it in GitHub Desktop.
- name: Demonstrate memory growth as tasks are included
hosts: localhost
gather_facts: false
tasks:
- include: foo/some_tasks.yml
with_sequence: start=1 end=10
- include: foo/some_tasks.yml
with_sequence: start=1 end=10
- include: foo/some_tasks.yml
with_sequence: start=1 end=10
#!/usr/bin/env python
import json
import sys
from pprint import pprint
INV = {}
INV['_meta'] = {'hostvars': {}}
groups = ['group_one', 'group_two', 'group_three']
hosts = ['host' + str(x) for x in range(0, 600)]
for idx, group in enumerate(groups):
INV[group] = {}
INV[group]['children'] = []
INV[group]['vars'] = {}
INV[group]['hosts'] = hosts[:]
for host in hosts:
INV['_meta']['hostvars'][host] = {}
INV['_meta']['hostvars'][host]['ansible_connection'] = 'local'
print json.dumps(INV, indent=2)
import datetime
import gc
import os
import psutil
from ansible.plugins.action.normal import ActionModule as _ActionModule
class ActionModule(_ActionModule):
def run(self, tmp=None, task_vars=None):
# http://stackoverflow.com/questions/17990227/whats-the-unit-of-rss-in-psutil-process-get-memory-info
version = os.environ.get('PROFILE_KEY')
if '/' in version:
version = version.split('/')[-1]
result = {
'failed': False,
'changed': False,
'ppid': None,
'cpids': []
}
process = psutil.Process(os.getpid())
parent = process.parent()
ppid = parent.pid
result['ppid'] = ppid
children = parent.children()
mem = []
mem.append(parent.memory_info().rss)
for child in children:
try:
mem.append(child.memory_info().rss)
result['cpids'].append(child.pid)
except Exception:
pass
result['memory'] = mem
result['memory_total'] = sum(mem)
ts = datetime.datetime.now().isoformat()
fn = os.path.join('/tmp', 'ansible-{}-profileme-data.csv'.format(version))
with open(fn, 'ab') as f:
f.write('%s,%s\n' % (ts, str(result['memory_total'])))
if result['memory_total'] >= 4000000000:
gc.disable()
import epdb; epdb.serve()
return result
- name: Get timestamp
set_fact:
timestamp: "{{ lookup('pipe', 'date +%s.%3N') }}"
delegate_to: localhost
register: task_result
- debug:
var: task_result
- profileme:
#!/bin/bash
export SSH_AUTH_SOCK=0
VERSION=$(ansible --version | head -n1 | awk '{print $2}')
export PROFILE_KEY=$VERSION
ANSIBLEDIR=$(which ansible)
CHECKOUTDIR=$(dirname $(dirname $ANSIBLEDIR))
export PROFILE_KEY=$CHECKOUTDIR
ansible-playbook -vvvv -i inventory.py call_includes.yml
RC=$?
exit $RC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment