Anons79 Mini Shell

Directory : /proc/self/root/lib/python2.7/site-packages/ansible/plugins/callback/
Upload File :
Current File : //proc/self/root/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyo

�
�Udac@`s�ddlmZmZmZeZidd6dgd6dd6ZdZdd	lZdd	l	Z	dd	l
Z
dd	lZdd	lZdd
l
mZmZddlmZddlmZmZdd
lmZddlmZmZddlmZdZdZd	d�Zdeeej �fd��YZ!de!fd��YZ"de!fd��YZ#de!fd��YZ$d�Z%d�Z&defd��YZ'd	S(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys�
    callback: cgroup_perf_recap
    callback_type: aggregate
    requirements:
      - whitelist in configuration
      - cgroups
    short_description: Profiles system activity of tasks and full execution using cgroups
    version_added: "2.8"
    description:
        - This is an ansible callback plugin utilizes cgroups to profile system activity of ansible and
          individual tasks, and display a recap at the end of the playbook execution
    notes:
        - Requires ansible to be run from within a cgroup, such as with
          C(cgexec -g cpuacct,memory,pids:ansible_profile ansible-playbook ...)
        - This cgroup should only be used by ansible to get accurate results
        - To create the cgroup, first use a command such as
          C(sudo cgcreate -a ec2-user:ec2-user -t ec2-user:ec2-user -g cpuacct,memory,pids:ansible_profile)
    options:
      control_group:
        required: True
        description: Name of cgroups control group
        env:
          - name: CGROUP_CONTROL_GROUP
        ini:
          - section: callback_cgroup_perf_recap
            key: control_group
      cpu_poll_interval:
        description: Interval between CPU polling for determining CPU 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_CPU_POLL_INTERVAL
        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
        env:
          - name: CGROUP_DISPLAY_RECAP
        ini:
          - section: callback_cgroup_perf_recap
            key: display_recap
        type: bool
        default: true
      file_name_format:
        description: Format of filename. Accepts C(%(counter)s), C(%(task_uuid)s),
                     C(%(feature)s), C(%(ext)s). Defaults to C(%(feature)s.%(ext)s) when C(file_per_task) is C(False)
                     and C(%(counter)s-%(task_uuid)s-%(feature)s.%(ext)s) when C(True)
        env:
          - name: CGROUP_FILE_NAME_FORMAT
        ini:
          - section: callback_cgroup_perf_recap
            key: file_name_format
        type: str
        default: '%(feature)s.%(ext)s'
      output_dir:
        description: Output directory for files containing recorded performance readings. If the value contains a
                     single %s, the start time of the playbook run will be inserted in that space. Only the deepest
                     level directory will be created if it does not exist, parent directories will not be created.
        type: path
        default: /tmp/ansible-perf-%s
        env:
          - name: CGROUP_OUTPUT_DIR
        ini:
          - section: callback_cgroup_perf_recap
            key: output_dir
      output_format:
        description: Output format, either CSV or JSON-seq
        env:
          - name: CGROUP_OUTPUT_FORMAT
        ini:
          - section: callback_cgroup_perf_recap
            key: output_format
        type: str
        default: csv
        choices:
          - csv
          - json
      file_per_task:
        description: When set as C(True) along with C(write_files), this callback will write 1 file per task
                     instead of 1 file for the entire playbook run
        env:
          - name: CGROUP_FILE_PER_TASK
        ini:
          - section: callback_cgroup_perf_recap
            key: file_per_task
        type: bool
        default: False
      write_files:
        description: Dictates whether files will be written containing performance readings
        env:
          - name: CGROUP_WRITE_FILES
        ini:
          - section: callback_cgroup_perf_recap
            key: write_files
        type: bool
        default: false
N(tABCMetatabstractmethod(tpartial(tto_bytestto_text(twith_metaclass(tAnsibleJSONEncodertjson(tCallbackBasess
cC`s:i}x-|D]%}t|�r(|�n|||<q
W|S(N(tcallable(tkeystdefaulttdtkey((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyt
dict_fromkeys�s
#tBaseProfcB`s/eZddd�Zd�Zed��ZRS(cC`sAtjj|�||_||_d|_t|_||_dS(Ni(	t	threadingtThreadt__init__tobjtpathtmaxtTruetrunningtwriter(tselfRRR ((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyR�s				cC`sx|jr|j�qWdS(N(Rtpoll(R!((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pytrun�scC`sdS(N((R!((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyR"�sN(t__name__t
__module__tNoneRR#R	R"(((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyR�s	t
MemoryProfcB`s)eZdZdddd�Zd�ZRS(s(Python thread for recording memory usageg�?cC`s/tt|�j|d|d|�||_dS(NRR (tsuperR'Rt_poll_interval(R!Rt
poll_intervalRR ((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyR�s"cC`s�t|j��#}t|j�j��d}WdQX||jkrO||_n|jr�y/|jtj�|jj	�|jj
|�Wq�tk
r�t|_
q�Xntj|j�dS(Niii(topenRtinttreadtstripRR ttimeRtget_namet_uuidt
ValueErrortFalseRtsleepR)(R!tftval((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyR"�s"	/
N(R$R%t__doc__R&RR"(((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyR'�stCpuProfcB`s#eZdddd�Zd�ZRS(g�?cC`s/tt|�j|d|d|�||_dS(NRR (R(R8RR)(R!RR*RR ((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyR�s"cC`s%t|j��3}tj�d}t|j�j��d}WdQXtj|j�t|j��3}tj�d}t|j�j��d}WdQX||||d}||jkr�||_n|j	r!y/|j	tj�|j
j�|j
j|�Wq!t
k
rt|_q!XndS(Ni�iidi@Bi@B(R+RR/R,R-R.R4R)RR RR0R1R2R3R(R!R5t
start_timetstart_usagetend_timet	end_usageR6((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyR"�s""	/
N(R$R%R&RR"(((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyR8�stPidsProfcB`s#eZdddd�Zd�ZRS(g�?cC`s/tt|�j|d|d|�||_dS(NRR (R(R=RR)(R!RR*RR ((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyR�s"cC`s�t|j��}t|j�j��}WdQX||jkrK||_n|jr�y/|jtj�|jj	�|jj
|�Wq�tk
r�t|_
q�Xntj|j�dS(N(R+RR,R-R.RR R/RR0R1R2R3RR4R)(R!R5R6((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyR"�s	/
N(R$R%R&RR"(((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyR=�scC`s|j||||g�dS(N(twriterow(R t	timestampt	task_namet	task_uuidtvalue((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyt
csv_writer�scC`sOi|d6|d6|d6|d6}|jdttj|dt�tf�dS(NR?R@RARBs%s%s%stcls(twritetRSRtdumpsRtLF(R R?R@RARBtdata((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pytjson_writer�s
tCallbackModulecB`sheZdZdZdZeZd	d�Zd	d�Z	d	d	d	d�Z
d	d�Zd�Zd�Z
RS(
g@t	aggregatetcgroup_perf_recapcC`s�tt|�j|�d	|_idd6dd6dd6|_t|jdt�|_tj	|j�|_
tj	|j�|_tj	|j�|_t
|_d|_t
|_dS(
NtmemorytcputpidstMBt%tRi(RNRORP(R(RKRt	_featurest_unitsRtlistttask_resultstdicttfromkeyst
_profilerst_filest_writersR3t_file_per_taskt_countertwrite_files(R!tdisplay((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyRs	
		cC`sD|j}|j}x+|jD] }it|j�d6t|�d6t|�d6t|�d6}|jj|�r�y|j|j�Wq�tk
r�q�Xn|j	r|j
|}ttj
j||�d�|j|<|dkr
tttj|j|��|j|<q<|dkr<tt|j|�|j|<q<qqWdS(NtcounterRAtfeaturetextsw+tcsvR(t_output_formatt_output_dirRTRR^R[tgettcloset	ExceptionR_t_file_name_formatR+tosRtjoinR
RCRdR R\RJ(R!RAt
output_formatt
output_dirRbRItfilename((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyt_open_filess(		


	
%)cC`s�tt|�jd|d|d|�|jd�}|jd�}|jd�}|jd�|_t|jd�d	d
�}d||_d|}d
|}	d|}
x�|j||	|
fD]k}yt|��}WdQXWq�tk
r*}
|j	j
dt|�t|
�|jf�t
|_dSXq�Wy,t|jd��}|jd�WdQXWnFtk
r�}
|j	j
dt|j�t|
�f�t
|_dSXy)t|	d��}|jd�WdQXWnCtk
r}
|j	j
dt|	�t|
�f�t
|_dSXitt|d|�d6tt|	d|�d6tt|
d|�d6|_|jd�|_|jd�}t|jd��|_t|jd�d	d
�}y#|ttjj�j��;}Wntk
r�nX||_t|jd��}|jr�|r7t
|_|dkrLd}qLnt|jd��}||_tjj |�s�ytj!|�Wq�tk
r�}
|j	j
dt|�t|
�f�t
|_dSXn|js�|j"�q�ndS( Nt	task_keystvar_optionstdirecttcpu_poll_intervaltmemory_poll_intervaltpid_poll_intervalt
display_recapt
control_groupterrorstsurrogate_or_stricts2/sys/fs/cgroup/memory/%s/memory.max_usage_in_bytess./sys/fs/cgroup/memory/%s/memory.usage_in_bytess'/sys/fs/cgroup/cpuacct/%s/cpuacct.usages#/sys/fs/cgroup/pids/%s/pids.currentu-Cannot open %s for reading (%s). Disabling %ssw+t0u*Unable to reset max memory value in %s: %su)Unable to reset CPU usage value in %s: %sR*RNRORPR_t
file_per_taskRmRntfile_name_formats%(feature)s.%(ext)ss-%(counter)s-%(task_uuid)s-%(feature)s.%(ext)su/Could not create the output directory at %s: %s(#R(RKtset_optionst
get_optiont_display_recapRtmem_max_fileR+Rit_displaytwarningRt
CALLBACK_NAMERtdisabledRER
R'R8R=t
_profiler_mapR_Retdatetimetnowt	isoformatt	TypeErrorRfR]RjRkRtexiststmkdirRp(R!RqRrRsRtRuRvRxtmem_current_filetcpu_usage_filetpid_current_fileRR5teR|RnR}((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyR~5s�%




	#			 			#
							c
	C`s�d}tj|j�}|s(|jrxT|jj�D]@\}}|dkrVq8ny|j�Wq8tk
rwq8Xq8Wnycx&|j	j�D]\}}t
|_q�Wx*|j	j�D]\}}|j||<q�W|j
}Wntk
r�nXx[|j�D]M\}}|dk	ry|j|j||f�WqPtk
rLqPXqqW|dk	r�|jsx|jdkr�|jd|j�nxL|jD]A}	|j|	d|d|j|	�|j	|	<|j	|	j�q�W|jd7_ndS(NiRARR i(R&RXRYRTR]R[titemsRhRiRZR3RRRtAttributeErrorRWtappendR2R^RpR1R�R\tstart(
R!Rt	prev_tasktresultstdummyR5tnametproftresultRb((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyt_profile�s>




*cC`s|j|�dS(N(R�(R!ttasktis_conditional((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pytv2_playbook_on_task_start�sc	
C`s�|j�|jsdSt|j��'}t|j�j��dd}WdQX|jjd�|jj	d|�x�|j
j�D]�\}}|dkr�q�ny8|jj	d|td�|D��|j
|f�Wq�tk
r}|jj	d||f�q�Xq�W|jj	d�x�|j
j�D]�\}}|rV|jj	d	|�nxD|D]<\}}|jj	d
|j�|j||j
|f�q]W|jj	d�q-WdS(NisCGROUP PERF RECAPs"Memory Execution Maximum: %0.2fMB
RNs%s Execution Maximum: %0.2f%s
cs`s|]}|dVqdS(iN((t.0tt((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pys	<genexpr>�ss-%s profiling error: no results collected: %s
s
s%s:
s%s (%s): %0.2f%s(R�R�R+R�R,R-R.R�tbannerR`RWR�RRURiR0R1(	R!tstatsR5tmax_resultsR�RIR�R�RB((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pytv2_playbook_on_stats�s,
	&	/"4N(R$R%tCALLBACK_VERSIONt
CALLBACK_TYPER�RtCALLBACK_NEEDS_WHITELISTR&RRpR~R�R�R�(((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyRKsW'	((t
__future__RRRttypet
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONRdR�RkR/RtabcRR	t	functoolsR
tansible.module_utils._textRRtansible.module_utils.sixR
tansible.parsing.ajsonRRtansible.plugins.callbackRRFRHR&RRRR'R8R=RCRJRK(((sN/usr/lib/python2.7/site-packages/ansible/plugins/callback/cgroup_perf_recap.pyt<module>s4


y"		

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]