grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a úº†jÆÕã @sÊ dZddlZddlZddlZddlZddlZddlmZddlmZddl Z ddl Z ddl m Z m Z mZmZmZmZddl mZmZmZmZmZmZddl mZmZmZmZmZddl mZmZmZm Z m!Z!dd l"m#Z#ee#d ƒƒZ$ej%d kròd nd Z&ee#e&ƒƒZ'ej(dk�re)fZ*e)Z+e,Z-n e)e+fZ*e.Z-dd„Z/Gdd„de0ƒZ1Gdd„de0ƒZ2e j3dk�rdeZ4ne j3dk�rveZ4n e1e j5dƒ‚e j6dk�r”eZ7ne j6dk�r¦eZ7n e1e j5dƒ‚Gdd„deƒZ8Gdd„deƒZ9Gdd„deƒZ:Gdd „d eƒZ;Gd!d"„d"eƒZGd'd(„d(eƒZ?Gd)d*„d*eƒZ@ee@ƒZAeBd+d,„dddƒeA_CeBd-d,„dddƒeA_DeBd.d,„dddƒeA_EeBd/d,„dddƒeA_FGd0d1„d1eƒZGGd2d3„d3eƒZHeZIeZJGd4d5„d5eƒZKeeKƒZLeBd6d,„dddƒeL_MeBd7d,„dddƒeL_NeBd8d,„dddƒeL_OeBd9d,„dddƒeL_Pd:d;„ZQGdd?„d?eƒZSGd@dA„dAeƒZTGdBdC„dCeƒZUeeUƒZVeBdDd,„dddƒeV_WeBdEd,„dddƒeV_XeBdFd,„dddƒeV_YeBdGd,„dddƒeV_ZeBdHd,„dddƒeV_[GdIdJ„dJeƒZ\e e$j]_^eeeeƒƒge$j]__e e$j`_^eeeeƒƒeee ƒƒge$j`__e e$ja_^ge$ja__e e$jb_^ege$jb__e e$jc_^e edKeeƒge$jc__e e$jd_^e eeeƒƒge$jd__e e$je_^e eeƒge$je__edeƒZfe e$jg_^eefge$jg__e e$jh_^ge$jh__e e$ji_^eeeeƒge$ji__e e$jj_^ege$jj__e e$jk_^eeeKƒge$jk__e e$jl_^e eeƒeeKƒge$jl__e e$jm_^ee eeƒge$jm__e e$jn_^ee eeƒge$jn__e e$jo_^eeee ƒƒeeeƒƒge$jo__e e$jp_^eege$jp__e e$jq_^eeeeƒge$jq__e e$jr_^e ege$jr__e e$js_^e ge$js__e e$jt_^ge$jt__e e$ju_^e ge$ju__e e$jv_^ge$jv__e e$jw_^ee ee ƒge$jw__e e$jx_^ee ee ƒge$jx__e e$jy_^e ee8ƒe ge$jy__e e$jz_^e ee9ƒee9ƒge$jz__e e$j{_^e ge$j{__ee$j|_^e ee ge$j|__e e$j}_^ge$j}__e e$j~_^ege$j~__e e$j_^e ge$j__e e$j€_^eeƒge$j€__ee:ƒe$j�_^eeƒee:ƒge$j�__ee$j‚_^eeƒege$j‚__e e$jƒ_^e eeƒeeeGƒƒge$jƒ__e e$j„_^e eeƒeeeHƒƒge$j„__e e$j…_^e eeƒeeeHƒƒge$j…__de$j†_^eeGƒge$j†__de$j‡_^eeHƒge$j‡__e e$jˆ_^eeGƒge$jˆ__e e$j‰_^eeHƒge$j‰__e e$jŠ_^eeSƒge$jŠ__e e$j‹_^ee8ƒge$j‹__e e$jŒ_^eeTƒge$jŒ__e e$j�_^ee9ƒge$j�__e e$jŽ_^eeee ƒƒeeeƒƒge$jŽ__e e$j�_^eege$jp__eJege$j�__e e$j�_^eJe ge$j�__e e$j‘_^eeeGƒƒge$j‘__e e$j’_^eeeHƒƒge$j’__ee$j“_^ege$j“__ee$j”_^e ee ge$j”__e e$j•_^e ee?ƒe ee;ƒe ge$j•__e e$j–_^e ee;ƒee<ƒee;ƒee<ƒge$j–__ee$j—_^ee<ƒee ge$j—__ee$j˜_^eee ge$j˜__ee$j™_^eeege$j™__ee$jš_^ege$jš__ee$j›_^ege$j›__ee$jœ_^ege$jœ__ee$j�_^eee ge$j�__ee$jž_^eege$jž__ee$jŸ_^ege$jŸ__ee$j _^ege$j __ee$j¡_^eee ge$j¡__ee$j¢_^e ee ge$j¢__ee$j£_^ee;ƒe ee ge$j£__ee$j¤_^e ee ge$j¤__de$j¥_^ee e ee?ƒe ge$j¥__e e$j¦_^eee9ƒeeƒge$j¦__e e$j§_^eee8ƒeeƒge$j§__e e$j¨_^ee eeeeRƒƒeeƒge$j¨__e e$j©_^ge$j©__e e$jª_^ege$jª__de$j«_^eeHƒge$j«__de$j¬_^eeGƒge$j¬__e e$j­_^e eee\ƒƒge$j­__e e$j®_^e eee\ƒƒge$j®__e e$j¯_^e eee\ƒƒge$j¯__e e$j°_^e eee\ƒƒge$j°__e e$j±_^e eee\ƒƒge$j±__e e$j²_^e eee\ƒƒge$j²__e e$j³_^eee\ƒƒge$j³__e e$j´_^eeƒe ee ge$j´__ee eeUƒeeƒZµe e$j¶_^eee\ƒƒe ee eµege$j¶__de$j·_^ee\ƒe ge$j·__GdLdM„dMe¸ƒZ¹GdNdO„dOe¸ƒZºe e$j»_^eeƒe ege$j»__e e$j¼_^ege$j¼__e e$j½_^ege$j½__e e$j¾_^ege$j¾__e e$j¿_^eeeeee;ƒe ee ƒge$j¿__e e$jÀ_^eeeee ƒeeƒee;ƒe ee ƒeeeƒee ƒg e$jÀ__e e$jÁ_^eeeeeee9ƒee;ƒe ee ƒeeeƒee ƒg e$jÁ__e e$jÂ_^eee8ƒge$jÂ__e e$jÃ_^eee9ƒge$jÃ__e e$jÄ_^ege$jÄ__GdPdQ„dQe¸ƒZÅdS)Raí Wrapper module for LIBPCP - the core Performace Co-Pilot API # # Copyright (C) 2012-2024 Red Hat # Copyright (C) 2009-2012 Michael T. Werner # # This file is part of the "pcp" module, the python interfaces for the # Performance Co-Pilot toolkit. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2 of the License, or (at your # option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # Additional Information: # # Performance Co-Pilot Web Site # https://pcp.io # # Performance Co-Pilot Programmer's Guide # cf. Chapter 3. PMAPI - The Performance Metrics API # # EXAMPLE from pcp import pmapi import cpmapi as c_api # Create a pcp class context = pmapi.pmContext(c_api.PM_CONTEXT_HOST, "local:") # Get ids for number cpus and load metrics metric_ids = context.pmLookupName(("hinv.ncpu","kernel.all.load")) # Get the description of the metrics descs = context.pmLookupDescs(metric_ids) # Fetch the current value for number cpus results = context.pmFetch(metric_ids) # Extract the value into a scalar value atom = context.pmExtractValue(results.contents.get_valfmt(0), results.contents.get_vlist(0, 0), descs[0].contents.type, c_api.PM_TYPE_U32) print "#cpus=", atom.ul # Get the instance ids for kernel.all.load inst1 = context.pmLookupInDom(descs[1], "1 minute") inst5 = context.pmLookupInDom(descs[1], "5 minute") # Loop through the metric ids for i in range(results.contents.numpmid): # Is this the kernel.all.load id? if (results.contents.get_pmid(i) != metric_ids[1]): continue # Extract the kernel.all.load instance for j in range(results.contents.get_numval(i) - 1): atom = context.pmExtractValue(results.contents.get_valfmt(i), results.contents.get_vlist(i, j), descs[i].contents.type, c_api.PM_TYPE_FLOAT) value = atom.f if results.contents.get_inst(i, j) == inst1: print "load average 1=",atom.f elif results.contents.get_inst(i, j) == inst5: print "load average 5=",atom.f # ... or, using the fetchgroup interface: from pcp import pmapi import cpmapi as c_api pmfg = pmapi.fetchgroup(c_api.PM_CONTEXT_HOST, "local:") v = pmfg.extend_item("hinv.ncpu") vv = pmfg.extend_indom("kernel.all.load", c_api.PM_TYPE_FLOAT) vvv = pmfg.extend_event("systemd.journal.records", field="systemd.journal.field.string") t = pmfg.extend_timestamp() pmfg.fetch() print("time: %s" % t()) print("number of cpus: %d" % v()) for icode, iname, value in vv(): print("load average %s: %f" % (iname, value())) for ts, line in vvv(): print("%s : %s" % (ts, line())) éN)Údatetime)Úmodf)Úc_charÚc_intÚc_uintÚc_longÚc_char_pÚc_void_p)Úc_floatÚc_doubleÚc_int32Úc_uint32Úc_int64Úc_uint64)ÚCDLLÚPOINTERÚ CFUNCTYPEÚ StructureÚUnion)Ú addressofÚpointerÚsizeofÚcastÚbyref)Ú find_libraryZpcpÚwin32ÚcZmsvcrtÚ3cCsbtjdkr:ttjj_tjgtjj_t j tj |¡ddd�St tjj _tjgtjj _tj  |¡SdS)NrÚrF)Úclosefd) ÚsysÚversionrÚctypesZ pythonapiZPyObject_AsFileDescriptorÚrestypeZ py_objectÚargtypesÚosÚfdopenr Z PyFile_AsFile)ÚfileObj©r(ú//usr/lib64/python3.9/site-packages/pcp/pmapi.pyÚ pyFileToCFileˆs   r*cs<eZdZ‡fdd„Zdd„Zdd„Zdd„Zd d „Z‡ZS) ÚpmErrcsBtt|ƒj|Žt|ƒ|_|r8t|dtƒr8|d|_nd|_dS©Nr)Úsuperr+Ú__init__ÚlistÚargsÚ isinstanceÚintÚcode©Úselfr0©Ú __class__r(r)r.™s   zpmErr.__init__cCsHd}ztj|j}Wnty&Yn0|dur8| ¡Sd|| ¡fS)Nz%s %s)Úc_apiZ pmErrSymDictr3ÚKeyErrorÚmessage)r5ZerrSymr(r(r)Ú__str__¡s z pmErr.__str__cCsZt tj¡}t |j|tj¡}t| ¡ƒ}t dt |j ƒƒD]}|dt|j |ƒ7}q:|S)Néú ) r"Úcreate_string_bufferr8ÚPM_MAXERRMSGLENÚLIBPCPÚ pmErrStr_rr3ÚstrÚdecodeÚrangeÚlenr0)r5ZerrStrÚresultÚindexr(r(r)r:«s   z pmErr.messagecCstt td¡j ¡ƒS©NÚ pmProgname©rBrÚin_dllr@ÚvaluerC©r5r(r(r)Úprogname³szpmErr.prognamecCs|jS©N)r3rMr(r(r)Úerrno¶sz pmErr.errno) Ú__name__Ú __module__Ú __qualname__r.r;r:rNrPÚ __classcell__r(r(r6r)r+˜s   r+cs$eZdZ‡fdd„Zdd„Z‡ZS)Ú pmUsageErrcstt|ƒj|Žt|ƒ|_dSrO)r-rUr.r/r0r4r6r(r)r.ºszpmUsageErr.__init__cCs8tdt|jƒƒD]}t t|j|ƒ d¡¡qt ¡S)Nrúutf-8) rDrEr0r@ÚpmprintfrBÚencoder8ZpmUsageMessage)r5rGr(r(r)r:¾szpmUsageErr.message)rQrRrSr.r:rTr(r(r6r)rU¹s rUéézUnexpected suseconds_t sizezUnexpected time_t sizec@sjeZdZdefdefgZddd„Zedd„ƒZd d „Z d d „Z d d„Z dd„Z dd„Z dd„Zdd„ZdS)ÚtimevalÚtv_secÚtv_usecrNcCszt |¡|durbt|tƒr6t d¡}t|| ¡ƒ}t|tƒr^t|ƒ}|d}|dd}nd}t|ƒ|_ t|ƒ|_ dS)Nrr<i@B) rr.r1rÚutcfromtimestampÚfloatÚ total_secondsrr2r\r])r5ÚsecZusecÚepochÚtsr(r(r)r.ès     ztimeval.__init__cCsL|ƒ}tƒ}t|tƒs | d¡}t |t|ƒt|ƒ¡}|dkrHt||ƒ‚|S©z7 Construct timeval from a string using pmParseInterval rVr)rr1ÚbytesrXr@ÚpmParseIntervalrr+)ÚclsÚintervalÚtvpÚerrmsgÚstatusr(r(r)Ú fromInterval÷s   ztimeval.fromIntervalcCsdt |j|j¡S©Nz%.3f)r8ÚpmtimevalToRealr\r]rMr(r(r)r;sztimeval.__str__cCstt |j|j¡ƒSrO)r_r8rnr\r]rMr(r(r)Ú __float__sztimeval.__float__cCstt |j|j¡ƒSrO)Úcomplexr8rnr\r]rMr(r(r)Ú __complex__ sztimeval.__complex__cCs t|jƒSrO©r2r\rMr(r(r)Ú __index__ sztimeval.__index__cCs t|jƒSrO©Úlongr\rMr(r(r)Ú__long__sztimeval.__long__cCs t|jƒSrOrrrMr(r(r)Ú__int__sztimeval.__int__cCst t|ƒ¡dS)z9 Delay for the amount of time specified by this timeval. N©ÚtimeÚsleepr_rMr(r(r)rzsz timeval.sleep)rN)rQrRrSÚc_time_tÚ c_suseconds_tÚ_fields_r.Ú classmethodrlr;rorqrsrvrwrzr(r(r(r)r[äsÿ  r[c@sjeZdZdefdefgZddd„Zedd„ƒZd d „Z d d „Z d d„Z dd„Z dd„Z dd„Zdd„ZdS)Útimespecr\Útv_nsecrNcCszt |¡|durjt|tƒr6t d¡}t|| ¡ƒ}t|tƒrft|ƒ}t|dƒ}t|ddƒ}nd}||_ ||_ dS)Nrr<iÊš;) rr.r1rr^r_r`rr2r\r€)r5raZnsecrbrcr(r(r)r.s     ztimespec.__init__cCsL|ƒ}tƒ}t|tƒs | d¡}t |t|ƒt|ƒ¡}|dkrHt||ƒ‚|Srd)rr1rerXr@ÚpmParseHighResIntervalrr+)rgrhZtsprjrkr(r(r)rl,s   ztimespec.fromIntervalcCsdt |j|j¡Srm)r8ÚpmtimespecToRealr\r€rMr(r(r)r;8sztimespec.__str__cCstt |j|j¡ƒSrO)r_r8r‚r\r€rMr(r(r)ro;sztimespec.__float__cCstt |j|j¡ƒSrO)rpr8r‚r\r€rMr(r(r)rq>sztimespec.__complex__cCs t|jƒSrOrrrMr(r(r)rsAsztimespec.__index__cCs t|jƒSrOrtrMr(r(r)rvDsztimespec.__long__cCs t|jƒSrOrrrMr(r(r)rwGsztimespec.__int__cCst t|ƒ¡dS)z: Delay for the amount of time specified by this timespec. NrxrMr(r(r)rzJsztimespec.sleep)rN)rQrRrSr{rr}r.r~rlr;rorqrsrvrwrzr(r(r(r)rsÿ  rc @sbeZdZdefdefdefdefdefdefdefdefd efd efd efg Zd d „Zdd„ZdS)ÚtmÚtm_secÚtm_minÚtm_hourÚtm_mdayÚtm_monÚtm_yearÚtm_wdayÚtm_ydayÚtm_isdstÚ tm_gmtoffÚtm_zonec CsR|jd}|dkrd}|jd|jd|j|j|j|j||jd|jg }t   |¡S)Nr<réél) rŠr‰rˆr‡r†r…r„r‹rŒryÚ struct_time)r5ZpywdayZstlistr(r(r)r‘[s  þztm.struct_timecCstt d¡}t |j|j|j|j|j|j |j |j |j t |jƒt|jƒ¡ }tt |ƒƒ}t t|ƒ|¡t|j ¡ƒ ¡S)Né )r"r>r8ZpmMktimer„r…r†r‡rˆr‰rŠr‹rŒrur�rBrŽrr@ÚpmCtimerrLrCÚrstrip)r5rFÚsecondÚtimetpr(r(r)r;fs   ý z tm.__str__N) rQrRrSrrrr}r‘r;r(r(r(r)rƒNsö  rƒc@sÒeZdZdZdefdefdefdefdefde fde fd e fgZ e jd d „e jd d „e jd d „e jdd „e jdd „e jdd „e jdd „e jdd „e jdd „e jdd „e jdd „e jdd „e jdd „i Zdd„ZdS)Ú pmAtomValuez„Union used for unpacking metric values according to type Constants for specifying metric types are defined in module pmapi ÚlÚulÚllÚullÚfÚdÚcpZvpcCs|jSrO)r˜©Úxr(r(r)Ú…ózpmAtomValue.cCs|jSrO)r™rŸr(r(r)r¡†r¢cCs|jSrO)ršrŸr(r(r)r¡‡r¢cCs|jSrO)r›rŸr(r(r)r¡ˆr¢cCs|jSrO)rœrŸr(r(r)r¡‰r¢cCs|jSrO)r�rŸr(r(r)r¡Šr¢cCs|jSrO)ržrŸr(r(r)r¡‹r¢cCsdSrOr(rŸr(r(r)r¡Œr¢cCsdSrOr(rŸr(r(r)r¡�r¢cCsdSrOr(rŸr(r(r)r¡Žr¢cCsdSrOr(rŸr(r(r)r¡�r¢cCsdSrOr(rŸr(r(r)r¡�r¢cCsdSrOr(rŸr(r(r)r¡‘r¢cCsJ|j||ƒ}|tjkrFzt| d¡ƒ}WntyDt|ƒ}Yn0|S)NrV)Ú _atomDrefDr8ÚPM_TYPE_STRINGrBrCÚ Exception)r5ÚtypedrLr(r(r)Údref”s  zpmAtomValue.drefN)rQrRrSÚ__doc__r r rrr r rr r}r8Z PM_TYPE_32Z PM_TYPE_U32Z PM_TYPE_64Z PM_TYPE_U64Z PM_TYPE_FLOATZPM_TYPE_DOUBLEr¤ZPM_TYPE_AGGREGATEZPM_TYPE_AGGREGATE_STATICZ PM_TYPE_EVENTZPM_TYPE_HIGHRES_EVENTZPM_TYPE_NOSUPPORTZPM_TYPE_UNKNOWNr£r§r(r(r(r)r—ws2ù             ôr—c @sªeZdZdZejrPdedfdedfdedfdedfdedfdedfd ed fgZn HAVE_BITFIELDS_LTOR, gcc => not so much ÚdimSpacerYÚdimTimeÚdimCountÚ scaleSpaceÚ scaleTimeÚ scaleCountÚpadrZrcCs8t |¡||_||_||_||_||_||_d|_dSr,) rr.rªr«r¬r­r®r¯r°)r5ZdimSZdimTZdimCZscaleSZscaleTZscaleCr(r(r)r.´s zpmUnits.__init__cCs t |j|j|j|j|j|j¡SrO)r8Z pmUnits_intrªr«r¬r­r®r¯rMr(r(r)rw¾s ÿzpmUnits.__int__cCs$t d¡}t ||d¡}t| ¡ƒS)Né@©r"r>r@Ú pmUnitsStr_rrBrC)r5ÚunitstrrFr(r(r)r;Âs zpmUnits.__str__N)rrrrrr) rQrRrSr¨r8ÚHAVE_BITFIELDS_LTORrr}r.rwr;r(r(r(r)r©�s*úú r©c@sTeZdZdZejr2dedfdedfdedfgZndedfdedfdedfgZdS) Ú pmValueBlockzîValue block bitfields for different compilers A value block holds the value of an instance of a metric pointed to by the pmValue structure, when that value is too large (> 32 bits) to fit in the pmValue structure ZvtyperZZvlenéZvbufr<N) rQrRrSr¨r8rµrrr}r(r(r(r)r¶Çs þ þr¶c@s,eZdZdZdeeƒfdefgZdd„ZdS)Ú valueDrefzèUnion in pmValue for dereferencing the value of an instance of a metric For small items, e.g. a 32-bit number, the union contains the actual value For large items, e.g. a text string, the union points to a pmValueBlock ÚpvalÚlvalcCs d|jS)Nz value=%#lx)rºrMr(r(r)r;ÞszvalueDref.__str__N) rQrRrSr¨rr¶rr}r;r(r(r(r)r¸Ös  ÿr¸c@s(eZdZdZdefdefgZdd„ZdS)ÚpmValuez1Structure holding the value of a metric instance ÚinstrLcCs t|jƒ}dt|ƒ|jf|S)NzpmValue@%#lx inst=%d )rBrLrr¼)r5Úvstrr(r(r)r;ås zpmValue.__str__N)rQrRrSr¨rr¸r}r;r(r(r(r)r»ás ÿr»c@sNeZdZdZdefdefdefdedfgZdd„Zd d „Z e e d d d ƒZ d S) Ú pmValueSetaÙStructure holding a metric's list of instance values A performance metric may contain one or more instance values, one for each item that the metric concerns. For example, a metric measuring filesystem free space would contain one instance value for each filesystem that exists on the target machine. Whereas, a metric measuring free memory would have only one instance value, representing the total amount of free memory on the target system. ÚpmidÚnumvalÚvalfmtÚvlistr<csTˆjdkrLtˆjƒ}t‡fdd„|Dƒƒ}tˆƒˆjˆjˆjf}d||SdSdS)Nrcsg|]}dtˆj|ƒ‘qS©z %s)rBr©Ú.0ÚirMr(r)Ú ûr¢z&pmValueSet.__str__..z+pmValueSet@%#lx id=%#lx numval=%d valfmt=%dÚ)rÁrDrÀrBrr¿)r5Úvalsr½Úvsetr(rMr)r;øs    zpmValueSet.__str__cCst|jdƒSr,)rZ_vlistrMr(r(r)Ú vlist_readszpmValueSet.vlist_readN) rQrRrSr¨rrr»r}r;rËÚpropertyrÂr(r(r(r)r¾és  ý r¾cCs|jjSrO)Úcontentsr¿rŸr(r(r)r¡r¢r¡cCs|jjSrO)rÍrÀrŸr(r(r)r¡ r¢cCs|jjSrO)rÍrÁrŸr(r(r)r¡ r¢cCs|jjSrO)rÍrÂrŸr(r(r)r¡ r¢c@sneZdZdZdefdefdeeƒdfgZdd„Z dd „Z d d „Z d d „Z dd„Z dd„Zdd„Zdd„ZdS)ÚpmResultzéStructure returned by pmFetch, with a value set for each metric queried The vset is defined with a "fake" array bounds of 1, which can give runtime array bounds complaints. The getter methods are array bounds agnostic. Ú timestampÚnumpmidrÊr<cCst |¡d|_dSr,©rr.rÐrMr(r(r)r.s zpmResult.__init__cs6tˆjƒ}t‡fdd„|Dƒƒ}dtˆƒˆjf|S)Ncs g|]}dtˆj|jƒ‘qSrérBrÊrÍrÄrMr(r)rÇr¢z$pmResult.__str__..zpmResult@%#lx id#=%d ©rDrÐrBr©r5rÉr½r(rMr)r;s zpmResult.__str__cCst|jttƒƒ}||jjS©z# Return the pmid of vset[vset_idx] ©rrÊrÚ pmValueSetPtrrÍr¿©r5Úvset_idxZvsetptrr(r(r)Úget_pmid!szpmResult.get_pmidcCs t|jtttƒƒƒ}||jjS©z% Return the valfmt of vset[vset_idx] ©rrÊrr¾rÍrÁrØr(r(r)Ú get_valfmt&szpmResult.get_valfmtcCs t|jtttƒƒƒ}||jjS©z% Return the numval of vset[vset_idx] ©rrÊrr¾rÍrÀrØr(r(r)Ú get_numval+szpmResult.get_numvalcCst|jtttƒƒƒ}||S©z Return the vset[vset_idx] ©rrÊrr¾rØr(r(r)Úget_vset0szpmResult.get_vsetcCs t| |¡jjttƒƒ}||S©z/ Return the vlist[vlist_idx] of vset[vset_idx] ©rrãrÍrÂrr»©r5rÙÚ vlist_idxZlistptrr(r(r)Ú get_vlist5szpmResult.get_vlistcCs| ||¡jS©z8 Return the inst for vlist[vlist_idx] of vset[vset_idx] ©rèr¼©r5rÙrçr(r(r)Úget_inst:szpmResult.get_instN)rQrRrSr¨r[rrr¾r}r.r;rÚrÝràrãrèrìr(r(r(r)rÎsýrÎc@s†eZdZdZdefdefdeeƒdfgZdd„Z dd „Z d d „Z d d „Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„ZdS)ÚpmHighResResultzHStructure returned by pmFetchHighRes, uses struct timespec for time rÏrÐrÊr<cCst |¡d|_dSr,rÑrMr(r(r)r.Es zpmHighResResult.__init__cs6tˆjƒ}t‡fdd„|Dƒƒ}dtˆƒˆjf|S)Ncs g|]}dtˆj|jƒ‘qSrÃrÒrÄrMr(r)rÇKr¢z+pmHighResResult.__str__..zpmHighResResult@%#lx id#=%d rÓrÔr(rMr)r;Is zpmHighResResult.__str__cCs|jjS)z& Return the sec part of the timestamp )rÏr\rMr(r(r)Úget_secNszpmHighResResult.get_seccCs|jjS)z' Return the nsec part of the timestamp )rÏr€rMr(r(r)Úget_nsecRszpmHighResResult.get_nseccCs|jS)z Return the number of pmids )rÐrMr(r(r)Ú get_numpmidVszpmHighResResult.get_numpmidcCst|jttƒƒ}||jjSrÕrÖrØr(r(r)rÚZszpmHighResResult.get_pmidcCs t|jtttƒƒƒ}||jjSrÛrÜrØr(r(r)rÝ_szpmHighResResult.get_valfmtcCs t|jtttƒƒƒ}||jjSrÞrßrØr(r(r)ràdszpmHighResResult.get_numvalcCst|jtttƒƒƒ}||SrárârØr(r(r)rãiszpmHighResResult.get_vsetcCs t| |¡jjttƒƒ}||Srärårær(r(r)rènszpmHighResResult.get_vlistcCs| ||¡jSrérêrër(r(r)rìsszpmHighResResult.get_instN)rQrRrSr¨rrrr¾r}r.r;rîrïrðrÚrÝràrãrèrìr(r(r(r)rí>s ýríc@s:eZdZdZdefdefdefdefdefgZdd„Zd S) ÚpmDescz"Structure describing a metric r¿ÚtypeÚindomÚsemÚunitscCst|ƒ|j|jf}d|S)NzpmDesc@%#lx id=%#lx type=%d)rr¿rò)r5Úfieldsr(r(r)r;‚szpmDesc.__str__N) rQrRrSr¨rrr©r}r;r(r(r(r)rñzsürñcCs|jjSrO)rÍrôrŸr(r(r)r¡‡r¢cCs|jjSrO)rÍròrŸr(r(r)r¡ˆr¢cCs|jjSrO)rÍrórŸr(r(r)r¡‰r¢cCs|jjSrO)rÍrõrŸr(r(r)r¡Šr¢cCs<Gdd„dtƒ}t|ttƒƒr&|jjS|ƒ}||_|jSdS)z‚Internal function to extract an indom from a pmdesc Allow functions requiring an indom to be passed a pmDesc* instead c@s eZdZdeeƒfdefgZdS)zget_indom..Valuer¹rºN)rQrRrSrrñrr}r(r(r(r)ÚValue’s ÿr÷N)rr1rrñrÍrór¹rº)Úpmdescr÷rLr(r(r)Ú get_indom�s rùc@sPeZdZdZdefdefdefdefdeeƒfgZdZdd „Z e dd d „ƒZ dS)Ú pmMetricSpecz.Structure describing a metric's specification ÚisarchÚsourceÚmetricÚninstr¼Ncs8tt‡fdd„tˆjƒƒƒ}tˆƒˆjˆj|f}d|S)Ncstˆj|ƒSrO)rBr¼rŸrMr(r)r¡§r¢z&pmMetricSpec.__str__..z+pmMetricSpec@%#lx src=%s metric=%s insts=%s)r/ÚmaprDrþrrûrü)r5Zinstsrör(rMr)r;¦szpmMetricSpec.__str__rrÈc Cs‚t|ƒƒ}tƒ}t|tƒs$| d¡}t|tƒs8| d¡}t |¡}t |¡}t |||t |ƒt |ƒ¡}|dkrxt ||ƒ‚||_ |S©NrVr) rrr1rerXr"r>r@ÚpmParseMetricSpecrr+Úcsbuffer) rgÚstringrûrürFrjZcstringZcsourcerkr(r(r)Ú fromString«s         ÿ zpmMetricSpec.fromString)rrÈ) rQrRrSr¨rrrr}rr;r~rr(r(r(r)rú�s ürúc@sNeZdZdZdefdefdefdeejfdeej fgZ dd„Z d d „Z d S) Ú pmLogLabelz1Label record at the start of every (v2) log file ÚmagicÚpid_tÚstartÚhostnameÚtzcCst|j ¡ƒS©z6 Return the hostname from the structure as native str ©rBr rCrMr(r(r)Ú get_hostnameÅszpmLogLabel.get_hostnamecCst|j ¡ƒS©z6 Return the timezone from the structure as native str )rBr rCrMr(r(r)Ú get_timezoneÉszpmLogLabel.get_timezoneN) rQrRrSr¨rr[rr8ÚPM_LOG_MAXHOSTLENZ PM_TZ_MAXLENr}r rr(r(r(r)r½s  ürc@sbeZdZdZdefdefdefdeejfdeej fdeej fgZ dd „Z d d „Z d d „ZdS)ÚpmHighResLogLabelz1Label record at the start of every (v3) log file rrrr ÚtimezoneÚzoneinfocCst|j ¡ƒSr r rMr(r(r)r ÖszpmHighResLogLabel.get_hostnamecCst|j ¡ƒSr)rBrrCrMr(r(r)rÚszpmHighResLogLabel.get_timezonecCst|j ¡ƒS)z6 Return the zoneinfo from the structure as native str )rBrrCrMr(r(r)Ú get_zoneinfoÞszpmHighResLogLabel.get_zoneinfoN)rQrRrSr¨rrrr8ZPM_MAX_HOSTNAMELENZPM_MAX_TIMEZONELENZPM_MAX_ZONEINFOLENr}r rrr(r(r(r)rÍs   ûrc@sDeZdZdZdedfdedfdedfdedfdedfgZd d „Zd S) ÚpmLabelz*Structure describing label's specificationÚnameéÚnamelenrZÚflagsrLÚvaluelencCs|jdd|jdS)Nú:ú")rrLrMr(r(r)r;észpmLabel.__str__N)rQrRrSr¨rr}r;r(r(r(r)râsürcCs|jjSrO)rÍrrŸr(r(r)r¡ír¢cCs|jjSrO)rÍrrŸr(r(r)r¡îr¢cCs|jjSrO)rÍrrŸr(r(r)r¡ïr¢cCs|jjSrO)rÍrLrŸr(r(r)r¡ðr¢cCs|jjSrO)rÍrrŸr(r(r)r¡ñr¢c @sVeZdZdZdefdefdefdedfdedfd ed fd eeƒfd e fgZ d d„Z dS)Ú pmLabelSetz. Structure describing label set specificationsr¼ZnlabelsÚjsonÚjsonlenrZpaddingéZcompoundr<ÚlabelsÚhashcCs|jdurdS|j ¡S)Nz{})rrCrMr(r(r)r;ýs zpmLabelSet.__str__N) rQrRrSr¨rrrrrr r}r;r(r(r(r)rós ùrr<c@s�eZdZdZdd„Zdd„Zdd„Zdd „Zeed d d ƒZ eed d d ƒZ eeed d ƒZ d˜d d „Z dd„Z edd„ƒZdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Z d4d5„Z!d6d7„Z"d8d9„Z#d:d;„Z$dd?„Z&d@dA„Z'dBdC„Z(dDdE„Z)dFdG„Z*dHdI„Z+dJdK„Z,dLdM„Z-dNdO„Z.dPdQ„Z/dRdS„Z0dTdU„Z1dVdW„Z2dXdY„Z3dZd[„Z4d\d]„Z5d^d_„Z6d`da„Z7dbdc„Z8ddde„Z9dfdg„Z:dhdi„Z;djdk„Zdpdq„Z?drds„Z@dtdu„ZAdvdw„ZBdxdy„ZCdzd{„ZDd|d}„ZEd~d„ZFd€d�„ZGd‚dƒ„ZHd„d…„ZId†d‡„ZJdˆd‰„ZKdŠd‹„ZLdŒd�„ZMdŽd�„ZNd�d‘„ZOd’d“„ZPd”d•„ZQd–d—„ZRd S)™Ú pmOptionszŠ Command line option parsing for short and long form arguments Passed into pmGetOptions, pmGetContextOptions, pmUsageMessage. cCs|jSrO)Ú_moderMr(r(r)Ú_R_modeJszpmOptions._R_modecCs|jSrO)Ú_deltarMr(r(r)Ú_R_deltaLszpmOptions._R_deltacCs|jSrO©Ú _need_resetrMr(r(r)Ú _R_need_resetNszpmOptions._R_need_resetcCs ||_dSrOr()r5rLr(r(r)Ú _W_need_resetPszpmOptions._W_need_resetNrcCsdt ¡|durt |¡|dur,t |¡|dkr@t |¡n t tj¡d|_tj|_d|_ dS)Nrr<F) r8ÚpmResetAllOptionsÚpmSetShortOptionsÚpmSetShortUsageÚpmSetOptionFlagsZPM_OPTFLAG_BOUNDARIESr&ÚPM_MODE_INTERPr$r))r5Ú short_optionsÚ short_usagerr(r(r)r.]s    zpmOptions.__init__cCstdur|jrt ¡dSrO)r@r)r8r,rMr(r(r)Ú__del__kszpmOptions.__del__cCst ¡S)z> Cross-platform --daemonize (re-parent to init) option helper )r8Z pmServerStartr(r(r(r)Ú daemonizeoszpmOptions.daemonizecCst ¡SrO)r8ÚpmGetOptionFlagsrMr(r(r)r5wszpmOptions.pmGetOptionFlagscCs t |¡SrO)r8ÚpmSetOptionContext)r5Úcontextr(r(r)r6zszpmOptions.pmSetOptionContextcCs t |¡SrO)r8r/)r5rr(r(r)r/}szpmOptions.pmSetOptionFlagscCst ¡SrO)r8ÚpmGetOptionErrorsrMr(r(r)r8€szpmOptions.pmGetOptionErrorscCst ¡d}t |¡S©Nr<)r8r8ÚpmSetOptionErrors)r5Úerrorsr(r(r)r:ƒs zpmOptions.pmSetOptionErrorscCs t |¡SrO)r8r.)r5r2r(r(r)r.‡szpmOptions.pmSetShortUsagecCs t |¡SrO)r8r-)r5r1r(r(r)r-ŠszpmOptions.pmSetShortOptionscCs t |¡S)z/ Set sample count (converts string to integer) )r8ÚpmSetOptionSamples)r5Úcountr(r(r)r<�szpmOptions.pmSetOptionSamplescCs t |¡S)z7 Set sampling interval (pmParseHighResInterval string) )r8ÚpmSetOptionInterval)r5rhr(r(r)r>‘szpmOptions.pmSetOptionIntervalcCst ¡S)a! After a pmGetOptions(3) call has been made this method returns a list of any remaining parameters which were not parsed as command line options, aka "operands". http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_254 )r8Ú pmGetOperandsrMr(r(r)r?•szpmOptions.pmGetOperandscCs t |¡SrO©r8ÚpmGetNonOptionsFromList©r5Úargvr(r(r)rAžsz!pmOptions.pmGetNonOptionsFromListcCs t |¡SrOr@rBr(r(r)ÚpmNonOptionsFromList¢szpmOptions.pmNonOptionsFromListcCs t |¡S)a¸ Handle individual command line options, outside of the PCP "standard" set (or overridden). For every non-standard or overridden option, this callback will be called with the short option character (as an int) or zero for long-option only, and the usual getopts global state (optind, opterr, optopt, optarg, and index - all int except optarg which is a str). )r8ÚpmSetOptionCallback©r5Úfuncr(r(r)rE¥s zpmOptions.pmSetOptionCallbackcCs t |¡S)az Allow a "standard" PCP option to be overridden. For every option parsed, this callback is called and it may return zero, meaning continue with processing the option in the standard way, or non-zero, meaning the caller wishes to override and interpret the option differently. Callback input: int, output: int )r8ÚpmSetOverrideCallbackrFr(r(r)rH±s zpmOptions.pmSetOverrideCallbackcCs|dur d}t |||||¡S)a& Add long option into the set of supported long options Pass in the option name (str), whether it takes an argument (int), its short option form (str), and two usage message hints (argname (str) and message (str) - see pmGetOptions(3) for details). NrÈ)r8ÚpmSetLongOption)r5Zlong_optZhas_argZ short_optÚargnamer:r(r(r)rI¼szpmOptions.pmSetLongOptioncCs t |¡S)z> Add a new section heading into the long option usage message )r8ÚpmSetLongOptionHeader)r5Úheadingr(r(r)rKÇszpmOptions.pmSetLongOptionHeadercCs t |¡S)z> Add some descriptive text into the long option usage message )r8ÚpmSetLongOptionText)r5Útextr(r(r)rMËszpmOptions.pmSetLongOptionTextcCst ¡S)z4 Add support for -A/--align into PMAPI monitor tool )r8ÚpmSetLongOptionAlignrMr(r(r)rOÏszpmOptions.pmSetLongOptionAligncCst ¡S)z6 Add support for -a/--archive into PMAPI monitor tool )r8ÚpmSetLongOptionArchiverMr(r(r)rPÓsz pmOptions.pmSetLongOptionArchivecCst ¡S)z4 Add support for -D/--debug into PMAPI monitor tool )r8ÚpmSetLongOptionDebugrMr(r(r)rQ×szpmOptions.pmSetLongOptionDebugcCsdS©z Unimplemented Nr(rMr(r(r)ÚpmSetLongOptionGuiModeÛsz pmOptions.pmSetLongOptionGuiModecCst ¡S)z3 Add support for -h/--host into PMAPI monitor tool )r8ÚpmSetLongOptionHostrMr(r(r)rTßszpmOptions.pmSetLongOptionHostcCst ¡S)z8 Add support for -H/--hostsfile into PMAPI monitor tool )r8ÚpmSetLongOptionHostsFilerMr(r(r)rUãsz"pmOptions.pmSetLongOptionHostsFilecCst ¡S)z9 Add support for -K/--spec-local into PMAPI monitor tool )r8ÚpmSetLongOptionSpecLocalrMr(r(r)rVçsz"pmOptions.pmSetLongOptionSpecLocalcCst ¡S)z9 Add support for -L/--local-PMDA into PMAPI monitor tool )r8ÚpmSetLongOptionLocalPMDArMr(r(r)rWësz"pmOptions.pmSetLongOptionLocalPMDAcCst ¡S)z5 Add support for -O/--origin into PMAPI monitor tool )r8ÚpmSetLongOptionOriginrMr(r(r)rXïszpmOptions.pmSetLongOptionOrigincCsdSrRr(rMr(r(r)ÚpmSetLongOptionGuiPortósz pmOptions.pmSetLongOptionGuiPortcCst ¡S)z4 Add support for -S/--start into PMAPI monitor tool )r8ÚpmSetLongOptionStartrMr(r(r)rZ÷szpmOptions.pmSetLongOptionStartcCst ¡S)z6 Add support for -s/--samples into PMAPI monitor tool )r8ÚpmSetLongOptionSamplesrMr(r(r)r[ûsz pmOptions.pmSetLongOptionSamplescCst ¡S)z5 Add support for -T/--finish into PMAPI monitor tool )r8ÚpmSetLongOptionFinishrMr(r(r)r\ÿszpmOptions.pmSetLongOptionFinishcCst ¡S)z7 Add support for -t/--interval into PMAPI monitor tool )r8ÚpmSetLongOptionIntervalrMr(r(r)r]sz!pmOptions.pmSetLongOptionIntervalcCst ¡S)z6 Add support for -V/--version into PMAPI monitor tool )r8ÚpmSetLongOptionVersionrMr(r(r)r^sz pmOptions.pmSetLongOptionVersioncCst ¡S)z7 Add support for -Z/--timezone into PMAPI monitor tool )r8ÚpmSetLongOptionTimeZonerMr(r(r)r_ sz!pmOptions.pmSetLongOptionTimeZonecCst ¡S)z7 Add support for -z/--hostzone into PMAPI monitor tool )r8ÚpmSetLongOptionHostZonerMr(r(r)r`sz!pmOptions.pmSetLongOptionHostZonecCst ¡S)z3 Add support for -?/--help into PMAPI monitor tool )r8ÚpmSetLongOptionHelprMr(r(r)raszpmOptions.pmSetLongOptionHelpcCst ¡S)z8 Add support for --archive-list into PMAPI monitor tool )r8ÚpmSetLongOptionArchiveListrMr(r(r)rbsz$pmOptions.pmSetLongOptionArchiveListcCst ¡S)z9 Add support for --archive-folio into PMAPI monitor tool )r8ÚpmSetLongOptionArchiveFoliorMr(r(r)rcsz%pmOptions.pmSetLongOptionArchiveFoliocCst ¡S)z5 Add support for --container into PMAPI monitor tool )r8ÚpmSetLongOptionContainerrMr(r(r)rdsz"pmOptions.pmSetLongOptionContainercCst ¡S)z5 Add support for --host-list into PMAPI monitor tool )r8ÚpmSetLongOptionHostListrMr(r(r)re#sz!pmOptions.pmSetLongOptionHostListcCst ¡SrO)r8ÚpmGetOptionContextrMr(r(r)rf'szpmOptions.pmGetOptionContextcCst ¡SrO)r8ÚpmGetOptionHostsrMr(r(r)rg*szpmOptions.pmGetOptionHostscCst ¡SrO)r8ÚpmGetOptionArchivesrMr(r(r)rh-szpmOptions.pmGetOptionArchivescCst ¡}|durdSt |¡SrO)r8ÚpmGetOptionAlign_optargr[rl©r5Z alignmentr(r(r)ÚpmGetOptionAlignment0szpmOptions.pmGetOptionAlignmentcCst ¡}|durdSt |¡SrO)r8rirrlrjr(r(r)ÚpmGetOptionHighResAlignment6sz%pmOptions.pmGetOptionHighResAlignmentcCs"t ¡}|durdSt|t ¡ƒSrO)r8ÚpmGetOptionStart_secr[ZpmGetOptionStart_usec©r5rar(r(r)ÚpmGetOptionStart<szpmOptions.pmGetOptionStartcCs"t ¡}|durdSt|t ¡ƒSrO)r8rmrZpmGetOptionStart_nsecrnr(r(r)ÚpmGetOptionHighResStartBsz!pmOptions.pmGetOptionHighResStartcCst ¡SrO)r8rirMr(r(r)ÚpmGetOptionAlignOptargHsz pmOptions.pmGetOptionAlignOptargcCst ¡SrO)r8ZpmGetOptionFinish_optargrMr(r(r)ÚpmGetOptionFinishOptargKsz!pmOptions.pmGetOptionFinishOptargcCs"t ¡}|durdSt|t ¡ƒSrO)r8ÚpmGetOptionFinish_secr[ZpmGetOptionFinish_usecrnr(r(r)ÚpmGetOptionFinishNszpmOptions.pmGetOptionFinishcCs"t ¡}|durdSt|t ¡ƒSrO)r8rsrZpmGetOptionFinish_nsecrnr(r(r)ÚpmGetOptionHighResFinishTsz"pmOptions.pmGetOptionHighResFinishcCs"t ¡}|durdSt|t ¡ƒSrO)r8ÚpmGetOptionOrigin_secr[ZpmGetOptionOrigin_usecrnr(r(r)ÚpmGetOptionOriginZszpmOptions.pmGetOptionOrigincCs"t ¡}|durdSt|t ¡ƒSrO)r8rvrZpmGetOptionOrigin_nsecrnr(r(r)ÚpmGetOptionHighResOrigin`sz"pmOptions.pmGetOptionHighResOrigincCs"t ¡}|durdSt|t ¡ƒSrO)r8ÚpmGetOptionInterval_secr[ZpmGetOptionInterval_usecrnr(r(r)ÚpmGetOptionIntervalfszpmOptions.pmGetOptionIntervalcCs"t ¡}|durdSt|t ¡ƒSrO)r8ryrZpmGetOptionInterval_nsecrnr(r(r)ÚpmGetOptionHighResIntervallsz$pmOptions.pmGetOptionHighResIntervalcCst ¡SrO)r8ÚpmGetOptionSamplesrMr(r(r)r|rszpmOptions.pmGetOptionSamplescCst ¡dkrdSdS©NrFT)r8ÚpmGetOptionHostZonerMr(r(r)r~us zpmOptions.pmGetOptionHostZonecCst ¡SrO)r8ÚpmGetOptionTimezonerMr(r(r)rzszpmOptions.pmGetOptionTimezonecCst ¡SrO)r8ÚpmGetOptionContainerrMr(r(r)r€}szpmOptions.pmGetOptionContainercCst ¡dkrdSdSr})r8ÚpmGetOptionLocalPMDArMr(r(r)r�€s zpmOptions.pmGetOptionLocalPMDAcCs t |¡SrO)r8ÚpmSetOptionArchive)r5Úarchiver(r(r)r‚…szpmOptions.pmSetOptionArchivecCs t |¡SrO)r8ÚpmSetOptionArchiveList)r5Úarchivesr(r(r)r„ˆsz pmOptions.pmSetOptionArchiveListcCs t |¡SrO)r8ÚpmSetOptionArchiveFolio)r5Zfolior(r(r)r†‹sz!pmOptions.pmSetOptionArchiveFoliocCs t |¡SrO)r8ÚpmSetOptionContainer)r5Ú containerr(r(r)r‡ŽszpmOptions.pmSetOptionContainercCs t |¡SrO)r8ÚpmSetOptionHost)r5Úhostr(r(r)r‰‘szpmOptions.pmSetOptionHostcCs t |¡SrO)r8ÚpmSetOptionHostList)r5Úhostsr(r(r)r‹”szpmOptions.pmSetOptionHostListcCs t |¡SrO)r8ÚpmSetOptionSpecLocal)r5Úspecr(r(r)r�—szpmOptions.pmSetOptionSpecLocalcCst ¡SrO)r8ÚpmSetOptionLocalPMDArMr(r(r)r�šszpmOptions.pmSetOptionLocalPMDA)NNr)SrQrRrSr¨r%r'r*r+rÌÚmodeÚdeltaÚ need_resetr.r3Ú staticmethodr4r5r6r/r8r:r.r-r<r>r?rArDrErHrIrKrMrOrPrQrSrTrUrVrWrXrYrZr[r\r]r^r_r`rarbrcrdrerfrgrhrkrlrorprqrrrtrurwrxrzr{r|r~rr€r�r‚r„r†r‡r‰r‹r�r�r(r(r(r)r#Csž      r#c@s„eZdZdZdd„Zdd„Zdd„ZeedddƒZeedddƒZ eedddƒZ e j d fd d „Z d d „Zedádd„ƒZedd„ƒZdd„Zdd„Zdd„Zdd„Zdâdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zed)d*„ƒZd+d,„Zd-d.„Z e j!fd/d0„Z"e j!fd1d2„Z#dãd3d4„Z$d5d6„Z%d7d8„Z&d9d:„Z'd;d<„Z(d=d>„Z)d?d@„Z*dAdB„Z+edCdD„ƒZ,dEdF„Z-dGdH„Z.dIdJ„Z/dKdL„Z0dMdN„Z1dOdP„Z2dQdR„Z3edSdT„ƒZ4edUdV„ƒZ5edWdX„ƒZ6dYdZ„Z7d[d\„Z8d]d^„Z9d_d`„Z:dadb„Z;edcdd„ƒZdidj„Z?dkdl„Z@dmdn„ZAdodp„ZBdqdr„ZCdsdt„ZDdudv„ZEdwdx„ZFdydz„ZGd{d|„ZHdäd~d„ZId€d�„ZJd‚dƒ„ZKd„d…„ZLd†d‡„ZMdˆd‰„ZNdŠd‹„ZOdŒd�„ZPedŽd�„ƒZQedåd�d‘„ƒZRedæd“d”„ƒZSed•d–„ƒZTed—d˜„ƒZUed™dš„ƒZVed›dœ„ƒZWed�dž„ƒZXedŸd „ƒZYed¡d¢„ƒZZed£d¤„ƒZ[ed¥d¦„ƒZ\ed§d¨„ƒZ]ed©dª„ƒZ^ed«d¬„ƒZ_ed­d®„ƒZ`ed¯d°„ƒZaed±d²„ƒZbed³d´„ƒZcedµd¶„ƒZded·d¸„ƒZeed¹dº„ƒZfed»d¼„ƒZged½d¾„ƒZhed¿dÀ„ƒZiedÁd„ƒZjedÃdÄ„ƒZkedÅdÆ„ƒZledçdÈdÉ„ƒZmedÊdË„ƒZnedÌdÍ„ƒZoedÎdÏ„ƒZpedÐdÑ„ƒZqedÒdÓ„ƒZredèdÕdÖ„ƒZsed×dØ„ƒZtedÙdÚ„ƒZuee jvfdÛdÜ„ƒZwedÝdÞ„ƒZxdßdà„ZydS)éÚ pmContextaÌDefines a metrics source context (e.g. host, archive, etc) to operate on pmContext(c_api.PM_CONTEXT_HOST,"local:") pmContext(c_api.PM_CONTEXT_ARCHIVE,"FILENAME") This object defines a PMAPI context, and its methods wrap calls to PMAPI library functions. Detailled information about those C library functions can be found in the following document. SGI Document: 007-3434-005 Performance Co-Pilot Programmer's Guide Section 3.7 - PMAPI Procedural Interface, pp. 67 Detailed information about the underlying data structures can be found in the same document. Section 3.4 - Performance Metric Descriptions, pp. 59 Section 3.5 - Performance Metric Values, pp. 62 cCs|jSrO)Ú_typerMr(r(r)Ú_R_typeÀszpmContext._R_typecCs|jSrO)Ú_targetrMr(r(r)Ú _R_targetÂszpmContext._R_targetcCs|jSrO)Ú_ctxrMr(r(r)Ú_R_ctxÄszpmContext._R_ctxNúlocal:cCs\||_||_tj|_|r.t|tƒs.| d¡}n|}t  ||¡|_|jdkrXt |j|gƒ‚dSr) r•r—r8ÚPM_ERR_NOCONTEXTr™r1rerXr@Ú pmNewContextr+)r5r¦Útargetrür(r(r)r.Ñs  zpmContext.__init__cCs$tdur |jtjkr t |j¡dSrO)r@r™r8rœÚpmDestroyContextrMr(r(r)r3ÝszpmContext.__del__rc CsÈ|dus|dkr,d|_t |¡r$t‚| ¡}|tjkrH| ¡}||}nZ|tjkrd| ¡}||}n>|tj krtd}n.|  ¡dur˜| ¡}||}tj}n tj}d}|||ƒ}t  |j |j |j¡rÄt‚|S)aÅ Helper interface, simple PCP monitor argument parsing. Take argv list, create a context using pmGetOptions(3) and standard options default values like local: etc based on the contents of the list. Caller should have already registered any options of interest using the option family of interfaces, i.e. pmSetShortOptions, pmSetLongOption*, pmSetOptionFlags, pmSetOptionCallback, and pmSetOptionOverrideCallback. When the MULTI/MIXED pmGetOptions flags are being used, the typed/index parameters can be used to setup several contexts based on the given command line parameters. NrTr›)r’r8ZpmGetOptionsFromListrUrfÚPM_CONTEXT_ARCHIVErhÚPM_CONTEXT_HOSTrgÚPM_CONTEXT_LOCALrwZpmSetContextOptionsÚctxr�r‘) rgÚoptionsrCr¦rGr…rürŒr7r(r(r)Ú fromOptionsás.        zpmContext.fromOptionscCs<d}t ¡r,tj}| tj¡| ¡d}nFt ¡rTtj}| tj¡| ¡d}nt ¡rrtj}| tj¡d}|sàd|vrœtj}| |¡| tj¡nD|dkrÂtj}|  |¡| tj¡ntj}|  ¡| tj¡d}|tjk�r|�rt d|  d¡ƒD]}|  |¡�q| ¡}| |tjB¡t ¡||fS)zF Helper to set connection options and to get context/source for pmfg. Nrú/ú@ú;)r8rhr r6rgr¡r�r¢r‚r‰r�ÚfilterÚsplitr�r5r/ZPM_OPTFLAG_DONEZ pmEndOptions)r¤rüZ speclocalr7rŽrr(r(r)Úset_connect_optionssB      zpmContext.set_connect_optionscs�ttƒƒ‰t |j¡}|dkr&t|ƒ‚t|tƒs:| d¡}t  |t ˆƒ¡}|dkrZt|ƒ‚|dkrˆt t ‡fdd„t |ƒƒƒ}t ˆ¡ndS|S)zsPMAPI - Return names of children of the given PMNS node NAME tuple names = pmGetChildren("kernel") rrVcstˆ| ¡ƒSrO©rBrCrŸ©Ú offspringr(r)r¡Nr¢z)pmContext.pmGetChildren..N)rrr@Ú pmUseContextr£r+r1rerXÚ pmGetChildrenrr/rÿrDÚLIBCÚfree)r5rrkÚchildLr(r­r)r°@s     zpmContext.pmGetChildrencsÈttƒƒ‰ttƒƒ‰t |j¡}|dkr0t|ƒ‚t|tƒsD|  d¡}t  |t ˆƒt ˆƒ¡}|dkrjt|ƒ‚|dkr¼t t ‡fdd„t|ƒƒƒ}t t ‡fdd„t|ƒƒƒ}t ˆ¡t ˆ¡ndS||fS)z�PMAPI - Return names and status of children of the given metric NAME (tuple names,tuple status) = pmGetChildrenStatus("kernel") rrVcstˆ| ¡ƒSrOr¬rŸr­r(r)r¡dr¢z/pmContext.pmGetChildrenStatus..cs tˆ|ƒSrO©r2rŸ)Ú childstatr(r)r¡er¢)NN)rrrr@r¯r£r+r1rerXÚpmGetChildrenStatusrr/rÿrDr±r²)r5rrkr³ZstatLr()rµr®r)r¶Ts&      ÿ  zpmContext.pmGetChildrenStatuscCs8t |j¡}|dkrt|ƒ‚t ¡}|dkr4t|ƒ‚|S)zUPMAPI - Return the namespace location type loc = pmGetPMNSLocation() r)r@r¯r£r+ÚpmGetPMNSLocation©r5rkr(r(r)r·ls zpmContext.pmGetPMNSLocationcCsNt |j¡}|dkrt|ƒ‚t|tƒs0| d¡}t |¡}|dkrJt|ƒ‚|S)zTPMAPI - Load a local namespace status = pmLoadNameSpace("filename") rrV)r@r¯r£r+r1rerXÚpmLoadNameSpace)r5Úfilenamerkr(r(r)r¹xs    zpmContext.pmLoadNameSpacec Cs,t |j¡}|dkrt|ƒ‚t|ttfƒr0d}nt|ƒ}t|ƒ}t|tƒr`t|  d¡ƒ|d<nTt|tƒrxt|ƒ|d<n.)r@r¯r£r+r1rBrerErrXÚ enumeraterrrÚ pmLookupNamer$Úzipr8Z PM_ERR_NAME) r5ZnameAZrelaxedrkÚnÚnamesrÆrÚpmidAZbadLr(r(r)r¼†s0        zpmContext.pmLookupNamecsnt |j¡}|dkrt|ƒ‚ttƒƒ‰t |tˆƒ¡}|dkrFt|ƒ‚tt ‡fdd„t |ƒƒƒ}t   ˆ¡|S)zvPMAPI - Return list of all metric names having this identical PMID tuple names = pmNameAll(metric_id) rcstˆ| ¡ƒSrOr¬rŸ©ÚnameA_pr(r)r¡´r¢z%pmContext.pmNameAll..) r@r¯r£r+rrÚ pmNameAllrr/rÿrDr±r²)r5r¿rkÚnameLr(rÁr)rés   zpmContext.pmNameAllcCs^tƒ}t |j¡}|dkr"t|ƒ‚t |t|ƒ¡}|dkrBt|ƒ‚|j}t  |¡t |  ¡ƒS)zYPMAPI - Return a metric name from a PMID name = pmNameID(self.metric_id) r) rr@r¯r£r+ÚpmNameIDrrLr±r²rBrC)r5r¿rrkrFr(r(r)rŸs  zpmContext.pmNameIDcCs<t |j¡}|dkrt|ƒ‚t ||¡}|dkr8t|ƒ‚dS)z„PMAPI - Scan namespace, depth first, run CALLBACK at each node status = pmTraversePMNS("kernel", traverse_callback) rN)r@r¯r£r+r8Z pmnsTraverse)r5rÚcallbackrkr(r(r)ÚpmTraversePMNSÇs   zpmContext.pmTraversePMNScCs8t |j¡}|dkrt|ƒ‚t ¡}|dkr4t|ƒ‚dS)zmPMAPI - Unloads a local PMNS, if one was previously loaded pm.pmUnLoadNameSpace("NameSpace") rN)r@r¯r£r+ÚpmUnloadNameSpacer¸r(r(r)ÚpmUnLoadNameSpaceÒs  zpmContext.pmUnLoadNameSpacecCsŒt|tƒs| d¡}t|tƒs(| d¡}tƒ}t ||t|ƒ¡}|dkrlt|j  ¡ƒ}t   |¡t t j|ƒ‚t |j¡}|dkrˆt |ƒ‚dS)z‚PMAPI - Register a derived metric name and definition pm.pmRegisterDerived("MetricName", "MetricName Expression") rVrN)r1rerXrr@ÚpmRegisterDerivedMetricrrBrLrCr±r²r+r8Ú PM_ERR_CONVÚpmReconnectContextr£)r5rÚexprrjrFrNrkr(r(r)ÚpmRegisterDerivedÝs       zpmContext.pmRegisterDerivedcCsRt|tƒs| d¡}t |¡}}|dkr2t|ƒ‚t |j¡}|dkrNt|ƒ‚|S)zuPMAPI - Register derived metric names and definitions from a file pm.pmLoadDerivedConfig("FileName") rVr)r1rerXr@ÚpmLoadDerivedConfigr+rÌr£)r5Úfnamerkr=r(r(r)rÏïs   zpmContext.pmLoadDerivedConfigcCs t ¡}|durt| ¡ƒSdS)zŽPMAPI - Return an error message if the pmRegisterDerived(3) metric definition cannot be parsed pm.pmRegisterDerived() N)r@ÚpmDerivedErrStrrBrC)rFr(r(r)rÑÿs zpmContext.pmDerivedErrStrcCs`t |j¡}|dkrt|ƒ‚t ttƒ¡}t|t tƒƒ}t |ƒ}t  ||¡}|dkr\t|ƒ‚|S)zvPMAPI - Lookup a metric description structure from a pmID pmDesc* pmdesc = pmLookupDesc(c_uint pmid) r) r@r¯r£r+r"r>rrñrrrÚ pmLookupDesc)r5Zpmid_prkZdescbufÚdescr¿r(r(r)rÒ s  zpmContext.pmLookupDescc Csät |j¡}|dkrt|ƒ‚t|tƒr:tdƒ}||d<n,tt|ƒƒ}t|ƒD]\}}t|ƒ||<qPt   t|ƒt t ƒ¡}t |tt ƒƒ}t t|ƒ||¡}|dkr¬t|ƒ‚tt ƒt|ƒƒ}tt|ƒƒD]}t||ƒ||<qÊ|S)z´PMAPI - Lookup metric description structures from pmIDs (pmDesc* pmdesc)[] = pmLookupDescs(c_uint pmid[N]) (pmDesc* pmdesc)[] = pmLookupDescs(c_uint pmid) rr<)r@r¯r£r+r1Ú integer_typesrrEr»r"r>rrñrrÚ pmLookupDescsrDr) r5Zpmids_prkÚpmidsrÆr¿ZdescsbufZdesclistÚdescsr(r(r)rÕs$    zpmContext.pmLookupDescscCsdtƒ}t |j¡}|dkr"t|ƒ‚t t|ƒ|t|ƒ¡}|dkrHt|ƒ‚|j}t   |¡t |  ¡ƒS)z|PMAPI - Lookup the description of a metric's instance domain "instance" = pmLookupInDomText(pmDesc pmdesc) r) rr@r¯r£r+ÚpmLookupInDomTextrùrrLr±r²rBrC)r5røÚkindÚbufrkrFr(r(r)rØ>s  zpmContext.pmLookupInDomTextcCs`tƒ}t |j¡}|dkr"t|ƒ‚t ||t|ƒ¡}|dkrDt|ƒ‚|j}t  |¡t |  ¡ƒS)zePMAPI - Lookup the description of a metric from its pmID "desc" = pmLookupText(pmid) r) rr@r¯r£r+Ú pmLookupTextrrLr±r²rBrC)r5r¿rÙrÚrkrNr(r(r)rÛOs  zpmContext.pmLookupTextcsä|dur|durttjdƒ‚ttƒƒ‰ttƒƒ‰t |j¡}|dkrLt|ƒ‚|dur\t |ƒ}t  |t ˆƒt ˆƒ¡}|dkr‚t|ƒ‚|dkrÔt t ‡fdd„t|ƒƒƒ}t t ‡fdd„t|ƒƒƒ}t ˆ¡t ˆ¡nd}d}||fS)z¦PMAPI - Lookup the list of instances from an instance domain PMDESCP or indom ([instance1, instance2...] [name1, name2...]) pmGetInDom(pmDesc pmdesc) Nzinvalid argumentsrcstˆ| dd¡ƒS©NÚasciiÚignorer¬rŸrÁr(r)r¡sr¢z&pmContext.pmGetInDom..cs tˆ|ƒSrOr´rŸ©ÚinstA_pr(r)r¡tr¢)r+r8ZPM_ERR_GENERICrrrr@r¯r£rùÚ pmGetInDomrr/rÿrDr±r²)r5ÚpmdescprórkrÄÚinstLr(©ràrÂr)ráas(      zpmContext.pmGetInDomcCstt |j¡}|dkrt|ƒ‚i}|j|d�\}}|dus@|durD|St|ƒ}t|ƒD]}| ||||i¡qT|S)z1 helper to return dict of inst:name for an indom r)róN)r@r¯r£r+rárErDÚupdate)r5rórkZretDrãrÄr¾rÆr(r(r)ÚpmGetInDomDict|s  zpmContext.pmGetInDomDictcCsTt |j¡}|dkrt|ƒ‚t|tƒs0| d¡}t t|ƒ|¡}|dkrPt|ƒ‚|S)zŠPMAPI - Lookup the instance id with the given NAME in the indom c_uint instid = pmLookupInDom(pmDesc pmdesc, "Instance") rrV) r@r¯r£r+r1rerXÚ pmLookupInDomrù©r5rørrkr(r(r)rçŠs   zpmContext.pmLookupInDomcCsv|tjkrdStƒ}t |j¡}|dkr0t|ƒ‚t t|ƒ|t |ƒ¡}|dkrVt|ƒ‚|j }t   |¡t | dd¡ƒS)zˆPMAPI - Lookup the text name of an instance in an instance domain "string" = pmNameInDom(pmDesc pmdesc, c_uint instid) Ú PM_IN_NULLrrÝrÞ)r8rérr@r¯r£r+Ú pmNameInDomrùrrLr±r²rBrC)r5røZinstvalÚname_prkrFr(r(r)rê™s   zpmContext.pmNameInDomcCsdS)z´PMAPI - NOOP - Establish a new PMAPI context (done in constructor) This is unimplemented. A new context is established when a pmContext object is created. Nr()r5r¦rr(r(r)r�®szpmContext.pmNewContextcCsdS)z­PMAPI - NOOP - Destroy a PMAPI context (done in destructor) This is unimplemented. The context is destroyed when the pmContext object is destroyed. Nr(©r5Zhandler(r(r)rŸµszpmContext.pmDestroyContextcCs8t |j¡}|dkrt|ƒ‚t ¡}|dkr4t|ƒ‚|S)zfPMAPI - Duplicate the current PMAPI Context This supports copying a pmContext object r)r@r¯r£r+Ú pmDupContextr¸r(r(r)rí¼s zpmContext.pmDupContextcCsdS)zÇPMAPI - NOOP - Set the PMAPI context to that identified by handle This is unimplemented. Context changes are handled by the individual methods in a pmContext class instance. Nr(rìr(r(r)r¯ÉszpmContext.pmUseContextcCst ¡}|dkrt|ƒ‚|S)zcPMAPI - Returns the handle of the current PMAPI context context = pmWhichContext() r)r@ÚpmWhichContextr+©rkr(r(r)rîÐszpmContext.pmWhichContextcCs¬t|tƒr"d}t|ƒ}||d<nH|dus.|s>d}ttƒƒ}n,t|ƒ}t|ƒ}t|ƒD]\}}|||<qXt |j¡}|dkr†t |ƒ‚t  t |ƒ||¡}|dkr¨t |ƒ‚|S)z…PMAPI - add instances to list that will be collected from indom status = pmAddProfile(pmDesc pmdesc, c_uint instid) r<rN) r1r2rrrEr»r@r¯r£r+Ú pmAddProfilerù©r5rørãZnuminstZinstArGrLrkr(r(r)rðÚs$        zpmContext.pmAddProfilecCsŠ|dus |sd}ttƒƒ}n,t|ƒ}t|ƒ}t|ƒD]\}}|||<q6t |j¡}|dkrdt|ƒ‚t t |ƒ||¡}|dkr†t|ƒ‚|S)z½PMAPI - delete instances from list to be collected from indom status = pmDelProfile(pmDesc pmdesc, c_uint inst) status = pmDelProfile(pmDesc pmdesc, [c_uint inst]) Nr) rrrEr»r@r¯r£r+Ú pmDelProfilerùrñr(r(r)ròós     zpmContext.pmDelProfilecCsnt |j¡}|dkrt|ƒ‚d}|dur0t|ƒ}d}|durL|dkrLt|ƒ}t |||¡}|dkrjt|ƒ‚|S)z‹PMAPI - set interpolation mode for reading archive files code = pmSetModeHighRes(c_api.PM_MODE_INTERP, timespec, timespec) rN)r@r¯r£r+rÚpmSetModeHighRes)r5r�ÚoriginrhrkÚwhenr‘r(r(r)ró s zpmContext.pmSetModeHighRescCsRt |j¡}|dkrt|ƒ‚d}|dur0t|ƒ}t |||¡}|dkrNt|ƒ‚|S)z|PMAPI - set interpolation mode for reading archive files code = pmSetMode(c_api.PM_MODE_INTERP, timeval, 0) rN)r@r¯r£r+rÚ pmSetMode)r5r�ZtimeValr‘rkrõr(r(r)rös zpmContext.pmSetModecCs t |j¡}|dkrt|ƒ‚|S)zùPMAPI - Reestablish the context connection Unlike the underlying PMAPI function, this method takes no parameter. This method simply attempts to reestablish the the context belonging to its pmContext instance object. r)r@rÌr£r+r¸r(r(r)rÌ*s zpmContext.pmReconnectContextcCs,tj}t |¡}t |j||¡}t| ¡ƒS)zÜPMAPI - Lookup the hostname for the given context This method simply returns the hostname for the context belonging to its pmContext instance object. "hostname" = pmGetContextHostName() ) r8rr"r>r@ÚpmGetContextHostName_rr£rBrC)r5ÚbuflenÚbufferrFr(r(r)ÚpmGetContextHostName6s zpmContext.pmGetContextHostNamecCs8t |j¡}|dkrt|ƒ‚t ¡}|dkr4t|ƒ‚|S)z5PMAPI - Query and set the current reporting timezone r)r@r¯r£r+ÚpmNewContextZoner¸r(r(r)rûFs zpmContext.pmNewContextZonecCs2t|tƒs| d¡}t |¡}|dkr.t|ƒ‚|S)z:PMAPI - Create new zone handle and set reporting timezone rVr)r1rerXr@Ú pmNewZoner+)r rkr(r(r)rüPs    zpmContext.pmNewZonecCst |¡}|dkrt|ƒ‚|S)z,PMAPI - Sets the current reporting timezone r)r@Ú pmUseZoner+)Z tz_handlerkr(r(r)rýZs zpmContext.pmUseZonecCs6tƒ}t t|ƒ¡}|dkr$t|ƒ‚|j}t| ¡ƒS)z-PMAPI - Query the current reporting timezone r)rr@Ú pmWhichZonerr+rLrBrC)Ztz_prkr r(r(r)rþbs zpmContext.pmWhichZonecCsFt |j¡}|dkrt|ƒ‚tƒ}tt|ƒƒ}t t|ƒt|ƒ¡|S)z;PMAPI - convert the date and time for a reporting timezone r) r@r¯r£r+rƒrruÚ pmLocaltimer©r5ÚsecondsrkrFr–r(r(r)rÿls  zpmContext.pmLocaltimecCsPt |j¡}|dkrt|ƒ‚t d¡}tt|ƒƒ}t t |ƒ|¡t |j   ¡ƒS)z:PMAPI - format the date and time for a reporting timezone rr’) r@r¯r£r+r"r>rrur“rrBrLrCrr(r(r)r“vs   zpmContext.pmCtimecCsPttƒƒ}t |j¡}|dkr&t|ƒ‚t t|ƒ|t|ƒ¡}|dkrLt|ƒ‚|S)zkPMAPI - Fetch pmResult from the target source pmResult* pmresult = pmFetch(c_uint pmid[]) r) rrÎr@r¯r£r+ÚpmFetchrEr©r5rÀÚresult_prkr(r(r)rƒs  zpmContext.pmFetchcCsPttƒƒ}t |j¡}|dkr&t|ƒ‚t t|ƒ|t|ƒ¡}|dkrLt|ƒ‚|S)z€PMAPI - Fetch pmHighResResult from the target source pmHighResResult* pmresult = pmFetchHighRes(c_uint pmid[]) r© rrír@r¯r£r+ÚpmFetchHighResrErrr(r(r)r‘s  zpmContext.pmFetchHighRescCsPttƒƒ}t |j¡}|dkr&t|ƒ‚t t|ƒ|t|ƒ¡}|dkrLt|ƒ‚|S)z�PMAPI - Fetch pmHighResResult from the target source (deprecated) pmHighResResult* pmresult = pmHighResFetch(c_uint pmid[]) rrrr(r(r)ÚpmHighResFetchŸs  zpmContext.pmHighResFetchcCst |¡dS)zgPMAPI - Free a result previously allocated by pmFetch pmFreeResult(pmResult* pmresult) N)r@Ú pmFreeResult©rr(r(r)r­szpmContext.pmFreeResultcCst |¡dS)zuPMAPI - Free a result previously allocated by pmFetch pmFreeHighResResult(pmHighResResult* pmresult) N)r@ÚpmFreeHighResResultr r(r(r)r ´szpmContext.pmFreeHighResResultcCsHt|ƒgtj_t |j¡}|dkr*t|ƒ‚t |¡}|dkrDt|ƒ‚|S)zoPMAPI - Set values on target source, inverse of pmFetch pmresult = pmStore(pmResult* pmresult) r)ròr@ÚpmStorer$r¯r£r+©r5rFrkr(r(r)r »s  zpmContext.pmStorecCsHt|ƒgtj_t |j¡}|dkr*t|ƒ‚t |¡}|dkrDt|ƒ‚|S)z„PMAPI - Set values on target source, inverse of pmFetchHighRes pmresult = pmStoreHighRes(pmHighResResult* pmresult) r)ròr@ÚpmStoreHighResr$r¯r£r+r r(r(r)r Ès  zpmContext.pmStoreHighRescCsDtƒ}t |j¡}|dkr"t|ƒ‚t t|ƒ¡}|dkr@t|ƒ‚|S)z]PMAPI - Get the label record from the archive loglabel = pmGetArchiveLabel() r)rr@r¯r£r+ÚpmGetArchiveLabelr©r5Zloglabelrkr(r(r)rÙs zpmContext.pmGetArchiveLabelcCsDtƒ}t |j¡}|dkr"t|ƒ‚t t|ƒ¡}|dkr@t|ƒ‚|S)zdPMAPI - Get the label record from the archive loglabel = pmGetHighResArchiveLabel() r)rr@r¯r£r+ÚpmGetHighResArchiveLabelrrr(r(r)ræs z"pmContext.pmGetHighResArchiveLabelcCsDtƒ}t |j¡}|dkr"t|ƒ‚t t|ƒ¡}|dkr@t|ƒ‚|S©zAPMAPI - Get the last recorded timestamp from the archive r)r[r@r¯r£r+ÚpmGetArchiveEndr)r5rirkr(r(r)rós zpmContext.pmGetArchiveEndcCsDtƒ}t |j¡}|dkr"t|ƒ‚t t|ƒ¡}|dkr@t|ƒ‚|Sr)rr@r¯r£r+ÚpmGetHighResArchiveEndr)r5rŽrkr(r(r)rÿs z pmContext.pmGetHighResArchiveEndcsÀttƒƒ‰ttƒƒ‰t |j¡}|dkr0t|ƒ‚t|ƒ}t |t ˆƒt ˆƒ¡}|dkr^t|ƒ‚|dkr°t t ‡fdd„t |ƒƒƒ}t t ‡fdd„t |ƒƒƒ}t  ˆ¡t  ˆ¡nd}d}||fS)z—PMAPI - Get the instance IDs and names for an instance domain ((instance1, instance2...) (name1, name2...)) pmGetInDom(pmDesc pmdesc) rcstˆ| dd¡ƒSrÜr¬rŸrÁr(r)r¡ r¢z-pmContext.pmGetInDomArchive..cs tˆ|ƒSrOr´rŸrßr(r)r¡ r¢N)rrrr@r¯r£r+rùÚpmGetInDomArchiverr/rÿrDr±r²)r5rârkrórÄrãr(rär)r s"     zpmContext.pmGetInDomArchivecCsTt |j¡}|dkrt|ƒ‚t|tƒs0| d¡}t t|ƒ|¡}|dkrPt|ƒ‚|S)z‘PMAPI - Lookup the instance id with the given name in the indom c_uint instid = pmLookupInDomArchive(pmDesc pmdesc, "Instance") rrV) r@r¯r£r+r1rerXÚpmLookupInDomArchiverùrèr(r(r)r# s   zpmContext.pmLookupInDomArchivecCsltƒ}t |j¡}|dkr"t|ƒ‚t|ƒ}t ||t|ƒ¡}|dkrLt|ƒ‚|j}t   |¡t |  dd¡ƒS)z�PMAPI - Lookup the text name of an instance in an instance domain "string" = pmNameInDomArchive(pmDesc pmdesc, c_uint instid) rrÝrÞ) rr@r¯r£r+rùÚpmNameInDomArchiverrLr±r²rBrC)r5rør¼rërkrórFr(r(r)r2 s  zpmContext.pmNameInDomArchivecCsHttƒƒ}t |j¡}|dkr&t|ƒ‚t t|ƒ¡}|dkrDt|ƒ‚|S)zmPMAPI - Fetch raw measurements from the target source pmResult* pmresult = pmFetchArchive() r)rrÎr@r¯r£r+ÚpmFetchArchiver©r5rrkr(r(r)rC s  zpmContext.pmFetchArchivecCsHttƒƒ}t |j¡}|dkr&t|ƒ‚t t|ƒ¡}|dkrDt|ƒ‚|S)z{PMAPI - Fetch raw measurements from the target source pmHighResResult* pmresult = pmFetchHighResArchive() r)rrír@r¯r£r+ÚpmFetchHighResArchiverrr(r(r)rQ s  zpmContext.pmFetchHighResArchiveéÿcCs4i}|dur0|jdkr0|jdur0t |j ¡¡}|S)zk return a dict of a pmLabelSet, i.e. {name: value, ...} flags arg is currently ignored Nr)rrÚloadsrC)r5ÚlsetrÚretr(r(r)Úpmlabelset_to_dict_ szpmContext.pmlabelset_to_dictcCsÖi}t |j¡}|dkr t|ƒ‚| |¡}| ¡}|rF| tj|i¡|  t  |¡¡}|rj| tj |i¡|j tj kr–| |j ¡}|r–| tj|i¡| |¡}|r´| tj|i¡| |¡}|rÒ| tj|i¡|S)z¿PMAPI - Get all labels for a single metric, excluding instance level labels (use pmGetInstancesLabels for those). Return dict of {type: {name: value, ...}, ...} r)r@r¯r£r+rÒÚpmGetContextLabelsrår8ZPM_LABEL_CONTEXTÚpmGetDomainLabelsÚ pmID_domainZPM_LABEL_DOMAINróÚ PM_INDOM_NULLÚpmGetInDomLabelsZPM_LABEL_INDOMÚpmGetClusterLabelsZPM_LABEL_CLUSTERÚpmGetItemLabelsZ PM_LABEL_ITEM)r5r¿rrkrÓrr(r(r)ÚpmLookupLabelsi s,      zpmContext.pmLookupLabelscCs¬i}t |j¡}|dkr t|ƒ‚|tjkr.|Sttƒƒ}t |t |ƒ¡}|dkrXt|ƒ‚t |ƒD]2}||}|j dur`|  |j t  |j  ¡¡i¡q`|dkr¨t ||¡|S)z€PMAPI - Get instance level labels for all instances in indom return a dict {instid: {name: value, ...}, ...} rN)r@r¯r£r+r8r"rrÚpmGetInstancesLabelsrrDrrår¼rrCÚpmFreeLabelSets)r5róZ instlabelsDrkrrÆrr(r(r)r'‹ s"      zpmContext.pmGetInstancesLabelscCspttƒƒ}t |j¡}|dkr&t|ƒ‚t |t|ƒ¡}|dkrFt|ƒ‚|dkrRiS| |d¡}|  |d¡|S)zˆPMAPI - Get labels of a given metric identifier On success, this returns a dict of the labels in a single pmLabelSet rr<) rrr@r¯r£r+r%rrr(©r5r¿rrkrr(r(r)r%¢ s   zpmContext.pmGetItemLabelscCspttƒƒ}t |j¡}|dkr&t|ƒ‚t |t|ƒ¡}|dkrFt|ƒ‚|dkrRiS| |d¡}|  |d¡|S)z…PMAPI - Get labels of a given metric cluster On success, this returns a dict of the labels in a single pmLabelSet rr<) rrr@r¯r£r+r$rrr(r)r(r(r)r$³ s   zpmContext.pmGetClusterLabelscCs~i}ttƒƒ}t |j¡}|dkr*t|ƒ‚|tjkr8|St |t |ƒ¡}|dkrXt|ƒ‚|dkrz|  |d¡}|  |d¡|S)z†PMAPI - Get labels of a given instance domain On success, this returns a dict of the labels in a single pmLabelSet rr<) rrr@r¯r£r+r8r"r#rrr()r5róZ indomLabelsDrrkr(r(r)r#Ä s    zpmContext.pmGetInDomLabelscCspttƒƒ}t |j¡}|dkr&t|ƒ‚t |t|ƒ¡}|dkrFt|ƒ‚|dkrRiS| |d¡}|  |d¡|S)z‰PMAPI - Get labels of a given performance domain On success, this returns a dict of the labels in a single pmLabelSet rr<) rrr@r¯r£r+r rrr()r5Údomainrrkrr(r(r)r × s   zpmContext.pmGetDomainLabelscCsnttƒƒ}t |j¡}|dkr&t|ƒ‚t t|ƒ¡}|dkrDt|ƒ‚|dkrPiS| |d¡}|  |d¡|S)z‚PMAPI - Get labels of the current context On success, this returns a dict of the labels in a single pmLabelSet rr<) rrr@r¯r£r+rrrr()r5rrkrr(r(r)rè s   zpmContext.pmGetContextLabelscCs’t|tƒs|g}n|}t tj¡}tt|ƒƒ}t|ƒD]\}}t|  d¡ƒ||<q8t   |t|ƒ|t|ƒ¡}|dkr|t |ƒ‚|j }t| dd¡ƒS)z3PMAPI - Merges string labels into a string rVrrÝrÞ)r1r/r"r>r8ÚPM_MAXLABELJSONLENrrEr»rXr@Ú pmMergeLabelsr+rLrBrC)r!ZlabelsLrÚarg_arrrÆZlabelrkrFr(r(r)r,ü s   ÿzpmContext.pmMergeLabelsc Cst tj¡}|durdd„}t|ƒ}|dur4d|_n¼t|tƒsF|g}n6g}|D],}t|tƒrh| |¡qN|durN|  |¡qNt t ƒt |ƒƒ}t |ƒD]\}} tt| ƒt t ƒƒ||<q–tt|ƒtƒ}t |t |ƒ|t |ƒ||¡} | dkrðt| ƒ‚|j} t|  dd¡ƒS)z—PMAPI - Merges list of pmLabelSets based on labelSets hierarchy into a string. Each list element may also be either a list or None. NcSsdSr9r()r ÚyÚzr(r(r)r¡ r¢z,pmContext.pmMergeLabelSets..s{}rrÝrÞ)r"r>r8r+ÚmergeLabelSetsCB_typerLr1r/ÚextendÚappendrrrEr»rrrr r@ÚpmMergeLabelSetsr+rBrC) Ú labelSetsrÆÚargrZcb_funcZ labelSetsLr˜r-rÆZlabelsetrkrFr(r(r)r3 s2      ÿzpmContext.pmMergeLabelSetsr<cCs8t|ƒD]*}tt||ƒttƒƒ}|rt |d¡qdS)z{PMAPI - Free the pmLabelSets memory. The labelsets argument is an array of nsets pmLabelSet structures. r<N)rDrrrrr@r()r4ZnsetsrÆr5r(r(r)r(2 s zpmContext.pmFreeLabelSetscCs6t|tƒs| d¡}t |¡}|dur*|St| ¡ƒS)z@PMAPI - Return single value from environment or pcp config file rVN)r1rerXr@ÚpmGetOptionalConfigrBrC)ÚvariablerFr(r(r)Ú pmGetConfig< s    zpmContext.pmGetConfigcCs(t tj¡}t ||tj¡}t| ¡ƒS)z4PMAPI - Convert an error code to a readable string )r"r>r8r?r@rArBrC)r3ZerrstrrFr(r(r)ÚpmErrStrF s zpmContext.pmErrStrcCs0tƒ}t |||t|ƒ|¡}|dkr,t|ƒ‚|S)aOPMAPI - Extract a value from a pmValue struct and convert its type pmAtomValue = pmExtractValue(results.contents.get_valfmt(i), results.contents.get_vlist(i, 0), descs[i].contents.type, c_api.PM_TYPE_FLOAT) r)r—r@ÚpmExtractValuerr+)rÁrÂZintypeZouttypeÚoutAtomrkr(r(r)r:M s  ÿzpmContext.pmExtractValuecCsft|tƒrtƒ}d|_||_n|}tƒ}t |t|ƒt||j j ƒt|ƒt|ƒ¡}|dkrbt |ƒ‚|S)zÈPMAPI - Convert a value to a different scale pmAtomValue = pmConvScale(c_api.PM_TYPE_FLOAT, pmAtomValue, pmDesc*, 3, c_api.PM_SPACE_MBYTE) r<r) r1r2r©rªr­r—r@Ú pmConvScalerrÍrõr+)ZinTypeZinAtomrÓZ metric_idxZoutUnitsZpmunitsr;rkr(r(r)r<] s   þzpmContext.pmConvScalecCs$t d¡}t ||d¡}t| ¡ƒS)z2PMAPI - Convert units struct to a readable string r±r²)rõr´rFr(r(r)Ú pmUnitsStrr s zpmContext.pmUnitsStrcCs$t d¡}t ||d¡}t| ¡ƒS)z3PMAPI - Convert double value to fixed-width string rZ)r"r>r@Ú pmNumberStr_rrBrC)rLZnumstrrFr(r(r)Ú pmNumberStry s zpmContext.pmNumberStrcCst |||¡}|S)z/PMAPI - build a pmID from domain, cluster, item)r@Ú pmID_build)r�rrÆrFr(r(r)r@€ szpmContext.pmID_buildcCst |¡}|S)z&PMAPI - return domain number from pmID)r@r!©r¿rFr(r(r)r!† s zpmContext.pmID_domaincCst |¡}|S)z'PMAPI - return cluster number from pmID)r@Ú pmID_clusterrAr(r(r)rBŒ s zpmContext.pmID_clustercCst |¡}|S)z$PMAPI - return item number from pmID)r@Ú pmID_itemrAr(r(r)rC’ s zpmContext.pmID_itemcCs$t d¡}t ||d¡}t| ¡ƒS)z,PMAPI - Convert a pmID to a readable string r’)r"r>r@Ú pmIDStr_rrBrC)r¿ZpmidstrrFr(r(r)ÚpmIDStr˜ s zpmContext.pmIDStrcCst ||¡}|S)z-PMAPI - build an indom from domain and serial)r@Ú pmInDom_build)r�ÚsrFr(r(r)rFŸ s zpmContext.pmInDom_buildcCst |¡}|S)z'PMAPI - return domain number from indom)r@ÚpmInDom_domain©rórFr(r(r)rH¥ s zpmContext.pmInDom_domaincCst |¡}|S)z'PMAPI - return serial number from indom)r@ÚpmInDom_serialrIr(r(r)rJ« s zpmContext.pmInDom_serialcCs(t d¡}t t|ƒ|d¡}t| ¡ƒS)zpPMAPI - Convert an instance domain ID to a readable string "indom" = pmGetInDom(pmDesc pmdesc) r’)r"r>r@Ú pmInDomStr_rrùrBrC)râZindomstrrFr(r(r)Ú pmInDomStr± s zpmContext.pmInDomStrcCs$t d¡}t ||d¡}t| ¡ƒS)zwPMAPI - Convert a performance metric type to a readable string "type" = pmTypeStr(c_api.PM_TYPE_FLOAT) r’)r"r>r@Ú pmTypeStr_rrBrC)r¦ZtypestrrFr(r(r)Ú pmTypeStrº s zpmContext.pmTypeStrcCs*t d¡}t t|ƒ||d¡}t| ¡ƒS)zoPMAPI - Convert a value atom to a readable string "value" = pmAtomStr(atom, c_api.PM_TYPE_U32) é`)r"r>r@Ú pmAtomStr_rrrBrC)Zatomr¦ZatomstrrFr(r(r)Ú pmAtomStrà s zpmContext.pmAtomStrcCs$t d¡}t ||d¡}t| ¡ƒS)z}PMAPI - Convert a performance metric semantic to a readable string "string" = pmSemStr(c_api.PM_SEM_COUNTER) r’)r"r>r@Ú pmSemStr_rrBrC)rôZsemstrrFr(r(r)ÚpmSemStrÌ s zpmContext.pmSemStrcCsFt t|ƒt|jj|jjƒt|jjƒt|jj|jj |ƒ|¡dS)zzPMAPI - Print the value of a metric pmPrintValue(file, value, pmdesc, vset_index, vlist_index, min_width) N) r@Ú pmPrintValuer*rrÍrÊrÁròrrÂ)r'rFZptyperÙrçZ min_widthr(r(r)rTÕ s   üzpmContext.pmPrintValuecCst ¡}|dkrt|ƒ‚|S)z7PMAPI - flush the internal buffer shared with pmprintf r)r@Úpmflushr+rïr(r(r)rUà szpmContext.pmflushcGs&tj|g|¢RŽ}|dkr"t|ƒ‚dS)z=PMAPI - append message to internal buffer for later printing rN)r@rWr+)Úfmtr0rkr(r(r)rWè szpmContext.pmprintfcCst |¡dS)zGPMAPI - sort all metric instances in result returned by pmFetchHighRes N)r@ÚpmSortHighResInstancesr r(r(r)rWï sz pmContext.pmSortHighResInstancescCst |¡dS)z@PMAPI - sort all metric instances in result returned by pmFetch N)r@ÚpmSortInstancesr r(r(r)rXô szpmContext.pmSortInstancescCst |¡dfS)zŠPMAPI - parse a textual time interval into a timespec struct (timespec_ctype, '') = pmParseHighResInterval("time string") rÈ)rrl©rhr(r(r)r�ù sz pmContext.pmParseHighResIntervalcCst |¡dfS)z�PMAPI - parse a textual time interval into a timeval struct (timeval_ctype, '') = pmParseInterval("time string") rÈ)r[rlrYr(r(r)rf szpmContext.pmParseIntervalrÈcCst |||¡dfS)z‰PMAPI - parse a textual metric specification into a struct (result, '') = pmParseMetricSpec("hinv.ncpu", 0, "localhost") rÈ)rúr)rrûrür(r(r)r szpmContext.pmParseMetricSpeccCs”t|ttfƒsttjt|ƒƒ‚t|tƒs2| d¡}tƒ}t ƒ}t ƒ}t   |t |ƒt |ƒt |ƒ¡}|dkrŠt|j ¡ƒ}t |¡t||ƒ‚||jfSr)r1reÚ text_typer+r8rËrBrXr©rr r@ÚpmParseUnitsStrrrLrCr±r²)rrFrjZ multiplierrkrNr(r(r)r[ s    zpmContext.pmParseUnitsStrcCs| ¡S)zÑ Delay for a specified amount of time (timespec). Useful for implementing tools that do metric sampling. Single arg is timespec in tuple returned from pmParseHighResInterval(). ©rz)rŽr(r(r)ÚpmtimespecSleep szpmContext.pmtimespecSleepcCs| ¡S)zÈ Delay for a specified amount of time (timeval). Useful for implementing tools that do metric sampling. Single arg is timeval in tuple returned from pmParseInterval(). r\)rir(r(r)ÚpmtimevalSleep& szpmContext.pmtimevalSleepcCstt td¡j ¡ƒSrHrJr(r(r(r)rI. szpmContext.pmPrognamecCst td¡j|@rdSdS)NÚpmDebugTF)rrKr@rL)rr(r(r)r_2 szpmContext.pmDebugéÿÿÿÿcCs¨|dkr|rdnd}n$|r0| ¡}t |¡j}n t ¡j}|rDtjntj}tj|}|r¤t|dƒ}t|ddƒ}|dkr„|d7}|t|ƒ7}|r¤|dt|ƒ7}|S)z; Get current timezone offset string using POSIX convention rr<ç ¬@ié<ú+r) rwryÚ localtimerŒÚaltzonerÚtznamer2rB)r¤Zset_dstÚdstriÚoffsetrZ offset_hrZ offset_minr(r(r)Úget_current_tz; s"    zpmContext.get_current_tzcsbˆrd‡fdd„dDƒvrdSdˆvr4ˆ d¡dn ˆ d¡d}dˆvrNdnd}d |t|ƒS) zC Convert POSIX timezone offset string to human readable UTC offset Tcsg|] }|ˆv‘qSr(r()rÅr©rr(r)rÇT r¢z4pmContext.posix_tz_to_utc_offset..)rcú-zUTC+0rcr<rkZUTC)rªrB)rrhÚsignr(rjr)Úposix_tz_to_utc_offsetQ s $z pmContext.posix_tz_to_utc_offsetcCsx| ¡r.| ¡tjd<t ¡t | ¡¡nF| ¡rNt ¡tjd<t ¡n&t  |¡}|tjd<t ¡t |¡dS)z Set timezone for a Python tool ZTZN) rr%ÚenvironryÚtzsetr”rür~rþri)r¤rr(r(r)Ú set_timezoneZ s   zpmContext.set_timezonecCsÒ|t d¡}|tjkr<|j|j|jdddd}n’|tjkrj|j|j|jdddd}nd|tjkr˜|j|j|jdddd}n6|tj krÆ|j|j|jdddd}nt dƒ‚|S)z6 Convert datetime value to seconds of given precision rg8@rag€„.Ag@�@gð?zUnsupported precision requested) rZ fromtimestampr8Ú PM_TIME_SECZ microsecondsrZdaysZ PM_TIME_MSECZ PM_TIME_USECZ PM_TIME_NSECÚ ValueError)rLZ precisionZtdtZtstr(r(r)Údatetime_to_secsj s $ $ $ $zpmContext.datetime_to_secscCs4|r|rtj}d}ntj}t|j|jdƒ}||fS)z! Get mode and step for pmSetMode Néè)r8Z PM_MODE_FORWr0rr\r])rƒÚinterpolrhr�Ústepr(r(r)Ú get_mode_stepz s zpmContext.get_mode_stepcCsZt |j¡}|dkrt|ƒ‚| |¡|jtjkrVt  |||¡\}}|  ||  ¡|¡dS)z Common execution preparation rN) r@r¯r£r+rpròr8r r”rwrórx)r5r¤rƒrurhrkr�rvr(r(r)Úprepare_execute… s   zpmContext.prepare_execute)rr)r)NN)r)NN)r<)rrÈ)Nr`)zrQrRrSr¨r–r˜ršrÌròržr£r8r¡r.r3r~r¥r“r«r°r¶r·r¹r¼rÃrÅrÇrÉrÎrÏrÑrÒrÕZPM_TEXT_ONELINErØrÛrárærçrêr�rŸrír¯rîrðròrórörÌrúrûrürýrþrÿr“rrrrr r r rrrrrrrrrrr&r'r%r$r#r rr,r3r(r8r9r:r<r=r?r@r!rBrCrErFrHrJrLrNrQrSrTrUrWrWrXr�rfrr[r]r^rIr_rirmrprqrsrwrxr(r(r(r)r”¥s@  / .  #                     "  "                                    r”c@sÖeZdZdZGdd„deƒZGdd„deƒZGdd„deƒZeZGdd „d eƒZ Gd d „d eƒZ Gd d „d e ƒZ e jdfdd„Zdd„Zdd„Zd%dd„Zd&dd„Zdd„Zdd„ZeZd'dd „Zd!d"„Zd#d$„ZdS)(Ú fetchgroupañDefines a PMAPI fetchgroup. This class wraps the pmFetchGroup set of C PMAPI functions (q.v.) in an object-oriented manner. Each instance of this class represents one fetchgroup, in which interest in several metrics (individual or indoms) is registered. Each registration results in an function-like object that may be called to decode that metric's value(s). Errors are signalled with exceptions rather than result integers. Strings are all UTF-8 encoded. c@s eZdZdZdd„Zdd„ZdS)zfetchgroup.fetchgroup_itemzë An internal class to receive value/status for a single item. It may be called as if it were a function object to decode the embedded pmAtomValue, which was set at the most recent .fetch() call. cCsttjƒ|_||_tƒ|_dS©z8Allocate a single instance to receive a fetchgroup item.N)rr8Z PM_ERR_VALUEÚstsÚpmtyper—rL)r5r|r(r(r)r.Ï s z#fetchgroup.fetchgroup_item.__init__cCs&|jjdkrt|jjƒ‚|j |j¡S)ú>Retrieve a converted value of a fetchgroup item, if available.r)r{rLr+r§r|rMr(r(r)Ú__call__Õ s  z#fetchgroup.fetchgroup_item.__call__N©rQrRrSr¨r.r~r(r(r(r)Úfetchgroup_itemÇ sr€c@s eZdZdZdd„Zdd„ZdS)zfetchgroup.fetchgroup_timespeczô An internal class to receive value for a single timespec. It may be called as if it were a function object to decode the timespec, which was set at the most recent .fetch() call, into a datetime object. cCstƒ|_||_dS)z.decode_onerVNcs‡‡‡fdd„S)Ncs ˆˆˆƒSrOr(r(©r�rÆr5r(r)r¡4 r¢zHfetchgroup.fetchgroup_indom.__call__....r(©rÆ©r�r5r’r)r¡4 r¢z6fetchgroup.fetchgroup_indom.__call__..) r{rLr+rDr‹r2r‰rŠrC)r5ÚvvrÆr(r“r)r~& s   üz$fetchgroup.fetchgroup_indom.__call__Nrr(r(r(r)Úfetchgroup_indom s r•c@s eZdZdZdd„Zdd„ZdS)zfetchgroup.fetchgroup_eventak An internal class to receive value/status for an event record field. It may be called as if it were a function object to create an list of tuples containing timestamp/value information. Each value is a function object that decodes the embedded pmAtomValue, which was set at the most recent fetch() call. cCsPt|}t|}t|}tƒ|_|ƒ|_||_|ƒ|_|ƒ|_tƒ|_ ||_ dSrz) rr—rr{r‡r|Útimesrˆrr‹r£)r5r|r‹r£rŒr�Z timespec_tr(r(r)r.B sz$fetchgroup.fetchgroup_event.__init__c s¨g}ˆjjdkrtˆjjƒ‚tˆjjƒD]z}dd„‰ˆj ˆj|j¡}t ˆj|j ƒd}t |j d|j d|j|j|j|j|dƒ}| |‡‡fdd „|ƒf¡q(|S) r}rcSs.|j|dkrt|j|ƒ‚|j| |j¡Sr,rŽr�r(r(r)r�V sz8fetchgroup.fetchgroup_event.__call__..decode_onertr�r<Ncs‡‡‡fdd„S)Ncs ˆˆˆƒSrOr(r(r‘r(r)r¡b r¢zHfetchgroup.fetchgroup_event.__call__....r(r’r“r’r)r¡b r¢z6fetchgroup.fetchgroup_event.__call__..)r{rLr+rDr‹r£rÿr–r\r2r€rr‰rˆr‡r†r…r„r2)r5r”rÆrcrƒr„r(r“r)r~O s  ÿÿz$fetchgroup.fetchgroup_event.__call__Nrr(r(r(r)Úfetchgroup_event8 s  r—c@s eZdZdZdd„Zdd„ZdS)zfetchgroup.pmContext_borrowedzþ An internal class for accessing the private PMAPI context belonging to a fetchgroup. It works just like a pmContext, except it overrides the constructor/destructor to reflect the "borrowed" state of the context. cCs||_||_||_dS)z/Override pmContext ctor to eschew pmNewContext.N)r™r•r—)r5r£r¦ržr(r(r)r.m sz&fetchgroup.pmContext_borrowed.__init__cCs tdur|jtjkrtj|_dS)z3Override pmContext ctor to eschew pmDestroyContext.N)r8r™rœrMr(r(r)r3u sz%fetchgroup.pmContext_borrowed.__del__N)rQrRrSr¨r.r3r(r(r(r)ÚpmContext_borrowedf sr˜r›cCsjtƒ|_g|_|tjkr$|dur$d}t t|jƒ|| d¡¡}|dkrNt |ƒ‚t   t  |j¡||¡|_ dS)z%Create a fetchgroup from a pmContext.NrÈrVr)r ÚpmfgÚitemsr8r¢r@ÚpmCreateFetchGrouprrXr+ryr˜ÚpmGetFetchGroupContextr£)r5r¦ržr{r(r(r)r.z sÿzfetchgroup.__init__cCs@tdur0|jjdur0t |j¡}|dkr0t|ƒ‚|jdd…=dS)z?Destroy the fetchgroup. Drop references to fetchgroup_* items.Nr)r@r™rLÚpmDestroyFetchGroupr+rš©r5r{r(r(r)r3† s  zfetchgroup.__del__cCs|jS)z· Return the private pmContext used by the fetchgroup. WARNING: mutation of this context by other PMAPI functions may disrupt fetchgroup functionality. )r£rMr(r(r)Ú get_contextŽ szfetchgroup.get_contextNc CsÆ|durttj ƒ‚|dur>|j |¡}|j |¡}|dj}t |¡}t   |j t |r`|  d¡ndƒt |rt|  d¡ndƒt |rˆ|  d¡ndƒt|jƒt|ƒt|jƒ¡}|dkr¶t|ƒ‚|j |¡|S)zÔExtend the fetchgroup with a single metric. Infer type if necessary. Convert scale/rate if appropriate/requested. Requires a specified instance if metric has an instance domain. NrrV)r+rPÚEINVALr£r¼rÕròryr€r@ÚpmExtendFetchGroup_itemr™rrXrrLrr{ršr2) r5rýÚmtypeÚscaleÚinstancerÖr×Úvr{r(r(r)Ú extend_item– s$     û zfetchgroup.extend_itemédc Cs |dus|dkrttj ƒ‚|durF|j |¡}|j |¡}|dj}t ||¡}t   |j t |rj|  d¡ndƒt |r~|  d¡ndƒtt|jƒttƒƒtt|jƒtt ƒƒtt|jƒttƒƒt|ƒtt|jƒttƒƒt|ƒt|jƒt|jƒ¡ }|dkrút|ƒ‚|j |¡|S)zÏExtend the fetchgroup with up to @maxnum instances of a metric. (Metrics without instances are also accepted.) Infer type if necessary. Convert scale/rate if appropriate/requested. NrrV)r+rPr r£r¼rÕròryr•r@ÚpmExtendFetchGroup_indomr™rrXrrr‰rrrŠrˆr—r‡rr‹r{ršr2) r5rýr¢r£ÚmaxnumrÖr×r”r{r(r(r)Ú extend_indom± s*     ø  zfetchgroup.extend_indomcCs@t |j¡}t |jt|jƒ¡}|dkr0t|ƒ‚|j   |¡|S)z-Extend the fetchgroup with a timespec query. r) ryr…r£r@ÚpmExtendFetchGroup_timespecr™rrLr+ršr2©r5r¥r{r(r(r)Úextend_timespecÍ s   zfetchgroup.extend_timespeccCs@t |j¡}t |jt|jƒ¡}|dkr0t|ƒ‚|j   |¡|S)z,Extend the fetchgroup with a timeval query. r) ryr†r£r@ÚpmExtendFetchGroup_timevalr™rrLr+ršr2r¬r(r(r)Úextend_timevalÖ s   zfetchgroup.extend_timevalc Cs&|dus|dkrttj ƒ‚|durF|j |¡}|j |¡}|dj}t |||j¡} t   |j t |rn|  d¡ndƒt |r‚|  d¡ndƒt |r–|  d¡ndƒt |rª|  d¡ndƒtt| jƒttƒƒtt| jƒttƒƒt|ƒtt| jƒttƒƒt|ƒt| jƒt| jƒ¡ } | dk�rt| ƒ‚|j | ¡| S)zÅExtend the fetchgroup with up to @maxnum instances of the given field of the given event metric's records. Infer type if necessary. Convert scale if appropriate/requested. NrrV)r+rPr r£r¼rÕròryr—r@ÚpmExtendFetchGroup_eventr™rrXrrr–rrrˆr—rr‡rr‹r{ršr2) r5rýZfieldZftyper£r¤r©rÖr×r”r{r(r(r)Ú extend_eventâ s,    ÷  zfetchgroup.extend_eventcCs t |j¡}|dkrt|ƒ‚|S)z?Fetch all the metrics in this fetchgroup and update all values.r)r@Ú pmFetchGroupr™r+ržr(r(r)Úfetchÿ s zfetchgroup.fetchcCs2t |j¡}|jdd…=|dkr(t|ƒ‚g|_dS)z>Clear all the metrics in this fetchgroup ready to start again.Nr)r@ÚpmClearFetchGroupr™ršr+ržr(r(r)Úclear s   zfetchgroup.clear)NNNN)NNNr§)NNNNNr§)rQrRrSr¨Úobjectr€r…r†Zfetchgroup_timestampr•r—r”r˜r8r¡r.r3rŸr¦rªr­r¯Zextend_timestampr±r³rµr(r(r(r)ry¹ s& *.      ry)Ær¨r%r ryrPrrZmathrZcpmapir8r"rrrrrr r r r r rrrrrrrrrrrrZ ctypes.utilrr@ÚplatformZ libc_namer±r!r2rÔrurBrZZunicoder*r¥r+rUZPM_SIZEOF_SUSECONDS_Tr|rËZPM_SIZEOF_TIME_Tr{r[rrƒr—r©r¶r¸r»r¾r×rÌr¿rÀrÁrÂrÎríZpmIDZpmInDomrñZ pmDescPtrrôròrórõrùrúrrrZ pmLabelPtrrrrrLrrr°r#r$r¶r·r¹r¼rÃrÅZtraverseCB_typerÇrÈrÊrÏrÒrÕrØrÛrárçrêr�rŸrír¯rîrðròrörórÌr÷rûrürýrþrÿr“rrrrr r r rrrrrrrrrr6rAr:r<r³r>r@r!rBrCrDrFrHrJrKrMrPrRrTr�rfrrUrWrWrXr&r'r%r$r#r rr,r0r3r(r¶r#r”r›rœr´r�r¡r¨r°r®r«r²ryr(r(r(r)Ús‚\        !      55)&* 09   ÿ    ÿ          ÿ    ÿþ      ÿÿ þ  þ dy   ÿø  ù