
    iog                    2(   S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJr  SSK	r
SSKrSSKJrJrJrJrJrJr  SSKJrJrJrJrJrJr  SSKJrJrJrJrJr  SSKJrJrJrJ r J!r!  SS	K"J#r#  \" \#" S
5      5      r$\RJ                  S:w  a  SOSr&\" \#" \&5      5      r'\RP                  S:  a  \)4r*\)r+\,r-O\)\+4r*\.r-S r/ " S S\05      r1 " S S\05      r2\
Rf                  S:X  a  \r4O&\
Rf                  S:X  a  \r4O\1" \
Rj                  S5      e\
Rl                  S:X  a  \r7O&\
Rl                  S:X  a  \r7O\1" \
Rj                  S5      e " S S\5      r8 " S S\5      r9 " S S\5      r: " S S\5      r; " S  S!\5      r< " S" S#\5      r= " S$ S%\5      r> " S& S'\5      r? " S( S)\5      r@\" \@5      rA\B" S* SSS5      \AlC        \B" S+ SSS5      \AlD        \B" S, SSS5      \AlE        \B" S- SSS5      \AlF         " S. S/\5      rG " S0 S1\5      rH\rI\rJ " S2 S3\5      rK\" \K5      rL\B" S4 SSS5      \LlM        \B" S5 SSS5      \LlN        \B" S6 SSS5      \LlO        \B" S7 SSS5      \LlP        S8 rQ " S9 S:\5      rR " S; S<\5      rS " S= S>\5      rT " S? S@\5      rU\" \U5      rV\B" SA SSS5      \VlW        \B" SB SSS5      \VlX        \B" SC SSS5      \VlY        \B" SD SSS5      \VlZ        \B" SE SSS5      \Vl[         " SF SG\5      r\\\$R                  l^        \\" \" \5      5      /\$R                  l_        \\$R                  l^        \\" \" \5      5      \" \" \5      5      /\$R                  l_        \\$R                  l^        / \$R                  l_        \\$R                  l^        \/\$R                  l_        \\$R                  l^        \\SH-  \" \5      /\$R                  l_        \\$R                  l^        \\" \" \5      5      /\$R                  l_        \\$R                  l^        \\" \5      /\$R                  l_        \" S\5      rf\\$R                  l^        \\f/\$R                  l_        \\$R                  l^        / \$R                  l_        \\$R                  l^        \\\" \5      /\$R                  l_        \\$R                  l^        \/\$R                  l_        \\$R                  l^        \\" \K5      /\$R                  l_        \\$R                  l^        \\" \5      \" \K5      /\$R                  l_        \\$R                  l^        \\\" \5      /\$R                  l_        \\$R                  l^        \\\" \5      /\$R                  l_        \\$R                  l^        \\" \" \5      5      \" \" \5      5      /\$R                  l_        \\$R                  l^        \\/\$R                  l_        \\$R                  l^        \\\" \5      /\$R                  l_        \\$R                  l^        \\/\$R                  l_        \\$R                  l^        \/\$R                  l_        \\$R                  l^        / \$R                  l_        \\$R                  l^        \/\$R                  l_        \\$R                  l^        / \$R                  l_        \\$R                  l^        \\\" \5      /\$R                  l_        \\$R                  l^        \\\" \5      /\$R                  l_        \\$R                  l^        \\" \85      \/\$R                  l_        \\$R                  l^        \\" \95      \" \95      /\$R                  l_        \\$R                  l^        \/\$R                  l_        \\$R                  l^        \\\/\$R                  l_        \\$R                  l^        / \$R                  l_        \\$R                  l^        \/\$R                  l_        \\$R                  l^        \/\$R                  l_        \\$GR                   l^        \" \5      /\$GR                   l_        \" \:5      \$GR                  l^        \" \5      \" \:5      /\$GR                  l_        \\$GR                  l^        \" \5      \/\$GR                  l_        \\$GR                  l^        \\" \5      \" \" \G5      5      /\$GR                  l_        \\$GR                  l^        \\" \5      \" \" \H5      5      /\$GR                  l_        \\$GR
                  l^        \\" \5      \" \" \H5      5      /\$GR
                  l_        S\$GR                  l^        \" \G5      /\$GR                  l_        S\$GR                  l^        \" \H5      /\$GR                  l_        \\$GR                  l^        \" \G5      /\$GR                  l_        \\$GR                  l^        \" \H5      /\$GR                  l_        \\$GR                  l^        \" \S5      /\$GR                  l_        \\$GR                  l^        \" \85      /\$GR                  l_        \\$GR                  l^        \" \T5      /\$GR                  l_        \\$GR                  l^        \" \95      /\$GR                  l_        \\$GR                  l^        \\" \" \5      5      \" \" \5      5      /\$GR                  l_        \\$GR                  l^        \\/\$R                  l_        \J\/\$GR                  l_        \\$GR                   l^        \J\/\$GR                   l_        \\$GR"                  l^        \" \" \G5      5      /\$GR"                  l_        \\$GR$                  l^        \" \" \H5      5      /\$GR$                  l_        \\$GR&                  l^        \/\$GR&                  l_        \\$GR(                  l^        \\\/\$GR(                  l_        \\$GR*                  l^        \\" \?5      \\" \;5      \/\$GR*                  l_        \\$GR,                  l^        \\" \;5      \" \<5      \" \;5      \" \<5      /\$GR,                  l_        \\$GR.                  l^        \" \<5      \\/\$GR.                  l_        \\$GR0                  l^        \\\/\$GR0                  l_        \\$GR2                  l^        \\\/\$GR2                  l_        \\$GR4                  l^        \/\$GR4                  l_        \\$GR6                  l^        \/\$GR6                  l_        \\$GR8                  l^        \/\$GR8                  l_        \\$GR:                  l^        \\\/\$GR:                  l_        \\$GR<                  l^        \\/\$GR<                  l_        \\$GR>                  l^        \/\$GR>                  l_        \\$GR@                  l^        \/\$GR@                  l_        \\$GRB                  l^        \\\/\$GRB                  l_        \\$GRD                  l^        \\\/\$GRD                  l_        \\$GRF                  l^        \" \;5      \\\/\$GRF                  l_        \\$GRH                  l^        \\\/\$GRH                  l_        S\$GRJ                  l^        \\\\" \?5      \/\$GRJ                  l_        \\$GRL                  l^        \\" \95      \" \5      /\$GRL                  l_        \\$GRN                  l^        \\" \85      \" \5      /\$GRN                  l_        \\$GRP                  l^        \\\\" \" \R5      5      \" \5      /\$GRP                  l_        \\$GRR                  l^        / \$GRR                  l_        \\$GRT                  l^        \/\$GRT                  l_        S\$GRV                  l^        \" \H5      /\$GRV                  l_        S\$GRX                  l^        \" \G5      /\$GRX                  l_        \\$GRZ                  l^        \\" \" \\5      5      /\$GRZ                  l_        \\$GR\                  l^        \\" \" \\5      5      /\$GR\                  l_        \\$GR^                  l^        \\" \" \\5      5      /\$GR^                  l_        \\$GR`                  l^        \\" \" \\5      5      /\$GR`                  l_        \\$GRb                  l^        \\" \" \\5      5      /\$GRb                  l_        \\$GRd                  l^        \\" \" \\5      5      /\$GRd                  l_        \\$GRf                  l^        \" \" \\5      5      /\$GRf                  l_        \\$GRh                  l^        \" \5      \\\/\$GRh                  l_        \" \\" \U5      \\5      r\\$GRl                  l^        \" \" \\5      5      \\\\\/\$GRl                  l_        S\$GRn                  l^        \" \\5      \/\$GRn                  l_         " SI SJ\5      r " SK SL\5      r\\$GRv                  l^        \" \5      \\/\$GRv                  l_        \\$GRx                  l^        \/\$GRx                  l_        \\$GRz                  l^        \/\$GRz                  l_        \\$GR|                  l^        \/\$GR|                  l_        \\$GR~                  l^        \\\\\" \;5      \\" \5      /\$GR~                  l_        \\$GR                  l^        \\\\" \5      \" \5      \" \;5      \\" \5      \\" \5      \" \5      /\$GR                  l_        \\$GR                  l^        \\\\\\" \95      \" \;5      \\" \5      \\" \5      \" \5      /\$GR                  l_        \\$GR                  l^        \\" \85      /\$GR                  l_        \\$GR                  l^        \\" \95      /\$GR                  l_        \\$GR                  l^        \/\$GR                  l_         " SM SN\5      rg)Oa  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_librarypcpwin32cmsvcrt3c                    [         R                  S:  a  [        [        R                  R
                  l        [        R                  /[        R                  R
                  l        [        R                  " [        R                  R                  U 5      SSS9$ [        [        R                  R                  l        [        R                  /[        R                  R                  l        [        R                  R                  U 5      $ )Nr    rF)closefd)sysversionr   ctypes	pythonapiPyObject_AsFileDescriptorrestype	py_objectargtypesosfdopenr
   PyFile_AsFile)fileObjs    +/usr/lib/python3/dist-packages/pcp/pmapi.pypyFileToCFiler1      s    
{{c=B22:?E?O?O>P22;yy))CCGLc[`aa19&&.393C3C2D&&/--g66    c                   @   ^  \ rS rSrU 4S jrS rS rS rS rSr	U =r
$ )pmErr   c                    > [         [        U ]
  " U6   [        U5      U l        U(       a#  [        US   [        5      (       a  US   U l        g SU l        g Nr   )superr4   __init__listargs
isinstanceintcodeselfr;   	__class__s     r0   r9   pmErr.__init__   sB    eT#T*J	JtAw,,QDIDIr2   c                     S n [         R                  U R                     nUc  U R	                  5       $ U< SU R	                  5       < 3$ ! [         a     N6f = f)N )c_apipmErrSymDictr>   KeyErrormessage)r@   errSyms     r0   __str__pmErr.__str__   sX    	''		2F ><<>! $,,.11	  		s   A 
AAc                 f   [         R                  " [        R                  5      n[        R                  U R                  U[        R                  5      n[        UR                  5       5      n[        S[        U R                  5      5       H!  nUS[        U R                  U   5      -   -  nM#     U$ )N   rD   )r&   create_string_bufferrE   PM_MAXERRMSGLENLIBPCP
pmErrStr_rr>   strdecoderangelenr;   )r@   errStrresultindexs       r0   rH   pmErr.message   s    ,,U-B-BC""499fe6K6KLV]]_%1c$))n-EcC		% 0111F .r2   c                 z    [        [        R                  " [        S5      R                  R                  5       5      $ N
pmPrognamerR   r	   in_dllrP   valuerS   r@   s    r0   prognamepmErr.progname   s'    8??6<8>>EEGHHr2   c                     U R                   $ N)r>   r`   s    r0   errnopmErr.errno       yyr2   )r;   r>   )__name__
__module____qualname____firstlineno__r9   rJ   rH   ra   re   __static_attributes____classcell__rA   s   @r0   r4   r4      s"    2I r2   r4   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )
pmUsageErr   c                 H   > [         [        U ]
  " U6   [        U5      U l        g rd   )r8   rp   r9   r:   r;   r?   s     r0   r9   pmUsageErr.__init__   s    j$($/J	r2   c                     [        S[        U R                  5      5       H=  n[        R	                  [        U R                  U   5      R                  S5      5        M?     [        R                  " 5       $ )Nr   utf-8)	rT   rU   r;   rP   pmprintfrR   encoderE   pmUsageMessage)r@   rX   s     r0   rH   pmUsageErr.message   sO    1c$))n-EOOC		% 0188AB .##%%r2   )r;   )rh   ri   rj   rk   r9   rH   rl   rm   rn   s   @r0   rp   rp      s    & &r2   rp         zUnexpected suseconds_t sizezUnexpected time_t sizec                   h    \ rS rSrS\4S\4/rSS jr\S 5       r	S r
S rS	 rS
 rS rS rS rSrg)timeval   tv_sectv_usecNc                 b   [         R                  " U 5        Ucv  [        U[        5      (       a1  [        R                  " S5      n[        X-
  R                  5       5      n[        U[
        5      (       a  [        U5      nUS   nUS   S-  nOSn[        U5      U l	        [        U5      U l
        g )Nr   rM   i@B )r   r9   r<   r   utcfromtimestampfloattotal_secondsr   r=   r   r   )r@   secusecepochtss        r0   r9   timeval.__init__   s    4 <#x(( 11!4S[779:#u%%#Ye!uw#h4yr2   c                     U " 5       n[        5       n[        U[        5      (       d  UR                  S5      n[        R                  U[        U5      [        U5      5      nUS:  a  [        XC5      eU$ z6Construct timeval from a string using pmParseInterval ru   r   )r	   r<   bytesrw   rP   pmParseIntervalr   r4   )clsintervaltvperrmsgstatuss        r0   fromIntervaltimeval.fromInterval   s`     e(E**w/H''%*eFmLA:''
r2   c                 ^    S[         R                  " U R                  U R                  5      -  $ Nz%.3f)rE   pmtimevalToRealr   r   r`   s    r0   rJ   timeval.__str__  s"    --dkk4<<HHHr2   c                 j    [        [        R                  " U R                  U R                  5      5      $ rd   )r   rE   r   r   r   r`   s    r0   	__float__timeval.__float__  s"    U**4;;EFFr2   c                 j    [        [        R                  " U R                  U R                  5      5      $ rd   )complexrE   r   r   r   r`   s    r0   __complex__timeval.__complex__	  s"    u,,T[[$,,GHHr2   c                 ,    [        U R                  5      $ rd   r=   r   r`   s    r0   	__index__timeval.__index__      4;;r2   c                 ,    [        U R                  5      $ rd   longr   r`   s    r0   __long__timeval.__long__      DKK  r2   c                 ,    [        U R                  5      $ rd   r   r`   s    r0   __int__timeval.__int__  r   r2   c                 B    [         R                  " [        U 5      5        g)z8Delay for the amount of time specified by this timeval. Ntimesleepr   r`   s    r0   r   timeval.sleep      

5;r2   )r   r   r   N)rh   ri   rj   rk   c_time_tc_suseconds_t_fields_r9   classmethodr   rJ   r   r   r   r   r   r   rl    r2   r0   r}   r}      sX    8$M*,H! 	 	IGI !  r2   r}   c                   h    \ rS rSrS\4S\4/rSS jr\S 5       r	S r
S rS	 rS
 rS rS rS rSrg)timespeci  r   tv_nsecNc                 ^   [         R                  " U 5        Uc  [        U[        5      (       a1  [        R                  " S5      n[        X-
  R                  5       5      n[        U[
        5      (       a+  [        U5      n[        US   5      n[        US   S-  5      nOSnXl	        X l
        g )Nr   rM   i ʚ;)r   r9   r<   r   r   r   r   r   r=   r   r   )r@   r   nsecr   r   s        r0   r9   timespec.__init__  s    4 <#x(( 11!4S[779:#u%%#Y"Q%j2a5:-.r2   c                     U " 5       n[        5       n[        U[        5      (       d  UR                  S5      n[        R                  U[        U5      [        U5      5      nUS:  a  [        XC5      eU$ r   )r	   r<   r   rw   rP   pmParseHighResIntervalr   r4   )r   r   tspr   r   s        r0   r   timespec.fromInterval,  s`     e(E**w/H..xsU6]SA:''
r2   c                 ^    S[         R                  " U R                  U R                  5      -  $ r   )rE   pmtimespecToRealr   r   r`   s    r0   rJ   timespec.__str__8  s"    ..t{{DLLIIIr2   c                 j    [        [        R                  " U R                  U R                  5      5      $ rd   )r   rE   r   r   r   r`   s    r0   r   timespec.__float__;  s"    U++DKKFGGr2   c                 j    [        [        R                  " U R                  U R                  5      5      $ rd   )r   rE   r   r   r   r`   s    r0   r   timespec.__complex__>  s"    u--dkk4<<HIIr2   c                 ,    [        U R                  5      $ rd   r   r`   s    r0   r   timespec.__index__A  r   r2   c                 ,    [        U R                  5      $ rd   r   r`   s    r0   r   timespec.__long__D  r   r2   c                 ,    [        U R                  5      $ rd   r   r`   s    r0   r   timespec.__int__G  r   r2   c                 B    [         R                  " [        U 5      5        g)z9Delay for the amount of time specified by this timespec. Nr   r`   s    r0   r   timespec.sleepJ  r   r2   )r   r   r   )rh   ri   rj   rk   r   r   r   r9   r   r   rJ   r   r   r   r   r   r   rl   r   r2   r0   r   r     sX    8$F#%H 	 	JHJ !  r2   r   c                   f    \ rS rSrS\4S\4S\4S\4S\4S\4S\4S	\4S
\4S\4S\4/rS rS r	Sr
g)tmiN  tm_sectm_mintm_hourtm_mdaytm_montm_yeartm_wdaytm_ydaytm_isdst	tm_gmtofftm_zonec           	      "   U R                   S-
  nUS:  a  SnU R                  S-   U R                  S-   U R                  U R                  U R
                  U R                  XR                  S-   U R                  /	n[        R                  " U5      $ )NrM   r      l  )r   r   r   r   r   r   r   r   r   r   struct_time)r@   pywdaystlists      r0   r   tm.struct_time[  sy     !A:F,,%t{{Q,,T[[,,*DMM; ''r2   c                 6   [         R                  " S5      n[        R                  " U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  [        U R                  5      [        U R                   5      5      n[#        [        U5      5      n[$        R'                  [)        U5      U5        [        UR*                  R-                  5       5      R/                  5       $ )N    )r&   rN   rE   pmMktimer   r   r   r   r   r   r   r   r   r   r   rR   r   r   rP   pmCtimer   r_   rS   rstrip)r@   rW   secondtimetps       r0   rJ   
tm.__str__f  s     ,,R0T[[$,, $dkk4<< $dllDMM $T^^ 4c$,,6GI V%uV}f-6<<&&()0022r2   r   N)rh   ri   rj   rk   r   r   r	   r   r   rJ   rl   r   r2   r0   r   r   N  sk    5!5!E"E"5!E"E"E"U#f%H%
'H	(3r2   r   c                      \ rS rSrSrS\4S\4S\4S\4S\	4S\
4S	\4S
\4/r\R                  S \R                   S \R"                  S \R$                  S \R&                  S \R(                  S \R*                  S \R,                  S \R.                  S \R0                  S \R2                  S \R4                  S \R6                  S 0rS rSrg)pmAtomValueiw  z|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cpvpc                     U R                   $ rd   )r   xs    r0   <lambda>pmAtomValue.<lambda>  s    qssr2   c                     U R                   $ rd   )r   r   s    r0   r   r     s    r2   c                     U R                   $ rd   )r   r   s    r0   r   r     s    qttr2   c                     U R                   $ rd   )r   r   s    r0   r   r     s    r2   c                     U R                   $ rd   )r   r   s    r0   r   r     s    !##r2   c                     U R                   $ rd   )r   r   s    r0   r   r     s    133r2   c                     U R                   $ rd   )r   r   s    r0   r   r     s    144r2   c                     g rd   r   r   s    r0   r   r         dr2   c                     g rd   r   r   s    r0   r   r     s    Tr2   c                     g rd   r   r   s    r0   r   r     s    $r2   c                     g rd   r   r   s    r0   r   r     s    $r2   c                     g rd   r   r   s    r0   r   r     r  r2   c                     g rd   r   r   s    r0   r   r     s    Dr2   c                     U R                   U   " U 5      nU[        R                  :X  a   [        UR	                  S5      5      nU$ U$ ! [
         a    [        U5      n U$ f = f)Nru   )
_atomDrefDrE   PM_TYPE_STRINGrR   rS   	Exception)r@   typedr_   s      r0   drefpmAtomValue.dref  se    &t,E(((#ELL12 u  #E
#s   A	 	A"!A"r   N)rh   ri   rj   rk   __doc__r   r   r   r   r   r   r	   r
   r   rE   
PM_TYPE_32PM_TYPE_U32
PM_TYPE_64PM_TYPE_U64PM_TYPE_FLOATPM_TYPE_DOUBLEr  PM_TYPE_AGGREGATEPM_TYPE_AGGREGATE_STATICPM_TYPE_EVENTPM_TYPE_HIGHRES_EVENTPM_TYPE_NOSUPPORTPM_TYPE_UNKNOWNr  r  rl   r   r2   r0   r   r   w  s     gx w!ghx x "H ""]##n""^##o%%&&&&))N00>%%--))N''.Jr2   r   c            	           \ rS rSrSr\R                  (       a  S\S4S\S4S\S4S\S4S\S4S	\S4S
\S4/rOS
\S4S	\S4S\S4S\S4S\S4S\S4S\S4/rSS jr	S r
S rSrg)pmUnitsi  z
Compiler-specific bitfields specifying scale and dimension of metric values
Constants for specifying metric units are defined in module pmapi
IRIX => HAVE_BITFIELDS_LTOR, gcc => not so much
dimSpacerz   dimTimedimCount
scaleSpace	scaleTime
scaleCountpadr{   c                     [         R                  " U 5        Xl        X l        X0l        X@l        XPl        X`l        SU l        g r7   )	r   r9   r!  r"  r#  r$  r%  r&  r'  )r@   dimSdimTdimCscaleSscaleTscaleCs          r0   r9   pmUnits.__init__  s5    4   r2   c                     [         R                  " U R                  U R                  U R                  U R
                  U R                  U R                  5      $ rd   )rE   pmUnits_intr!  r"  r#  r$  r%  r&  r`   s    r0   r   pmUnits.__int__  s<      dmm!%$..$//S 	Sr2   c                     [         R                  " S5      n[        R                  XS5      n[	        UR                  5       5      $ )N@   r&   rN   rP   pmUnitsStr_rrR   rS   )r@   unitstrrW   s      r0   rJ   pmUnits.__str__  s5    --b1$$TB76==?##r2   )r#  r!  r"  r'  r&  r$  r%  N)r   r   r   r   r   r   )rh   ri   rj   rk   r  rE   HAVE_BITFIELDS_LTORr   r   r9   r   rJ   rl   r   r2   r0   r   r     s    
   *q)*!5!, %+!5!,E1%' E1%!5!, %+!5!,*q)*,S$r2   r   c                       \ rS rSrSr\R                  (       a  S\S4S\S4S\S-  4/r	S	r
g
S\S4S\S4S\S-  4/r	S	r
g
)pmValueBlocki  zValue 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
vtyper{   vlen   vbufrM   r   N)rh   ri   rj   rk   r  rE   r9  r   r   r   rl   r   r2   r0   r;  r;    sb    
   fa(VR(VaZ(* VR(fa(VaZ(*r2   r;  c                   :    \ rS rSrSrS\" \5      4S\4/rS r	Sr
g)	valueDrefi  zUnion 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lvalc                      SU R                   -  $ )Nz
value=%#lx)rC  r`   s    r0   rJ   valueDref.__str__  s    tyy))r2   r   N)rh   ri   rj   rk   r  r   r;  r   r   rJ   rl   r   r2   r0   rA  rA    s)    
 ./!H*r2   rA  c                   .    \ rS rSrSrS\4S\4/rS rSr	g)pmValuei  z1Structure holding the value of a metric instance instr_   c                 f    [        U R                  5      nS[        U 5      U R                  4-  U-   $ )NzpmValue@%#lx inst=%d )rR   r_   r   rH  )r@   vstrs     r0   rJ   pmValue.__str__  s,    4::&)D/499)EELLr2   r   N)
rh   ri   rj   rk   r  r   rA  r   rJ   rl   r   r2   r0   rG  rG    s!    ;)$&HMr2   rG  c                   \    \ rS rSrSrS\4S\4S\4S\S-  4/rS r	S	 r
\" \
S
S
S
5      rSrg
)
pmValueSeti  a  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vlistrM   c           
      ,   U R                   S:X  a  [        U R                  5      n[        U Vs/ s H  nS[        U R                  U   5      -  PM      sn5      n[        U 5      U R                  U R                  U R                   4nSU-  U-   $ gs  snf )Nr    %sz+pmValueSet@%#lx id=%#lx numval=%d valfmt=%d )rP  rT   rO  rR   rQ  r   rN  )r@   valsirJ  vsets        r0   rJ   pmValueSet.__str__  s~    ;;!%DDADqDJJqM 22DABDdOTYYT[[ID@4G$NN	 Bs   %Bc                 2    [        U R                  S   5      $ r7   )r   _vlistr`   s    r0   
vlist_readpmValueSet.vlist_read  s    t{{1~&&r2   Nr   )rh   ri   rj   rk   r  r   r   rG  r   rJ   r[  propertyrQ  rl   r   r2   r0   rM  rM    sP      5!5!7Q;(*H
' ZtT2Er2   rM  c                 .    U R                   R                  $ rd   )contentsrN  r   s    r0   r   r     s    

r2   c                 .    U R                   R                  $ rd   )r_  rO  r   s    r0   r   r   	      !***;*;r2   c                 .    U R                   R                  $ rd   )r_  rP  r   s    r0   r   r   
  ra  r2   c                 .    U R                   R                  $ rd   )r_  rQ  r   s    r0   r   r     s    )9)9r2   c                   p    \ rS rSrSrS\4S\4S\" \5      S-  4/r	S r
S rS	 rS
 rS rS rS rS rSrg)pmResulti  zStructure 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numpmidrW  rM   c                 >    [         R                  " U 5        SU l        g r7   r   r9   rg  r`   s    r0   r9   pmResult.__init__      4 r2   c           
          [        U R                  5      n[        U Vs/ s H(  nS[        U R                  U   R                  5      -  PM*     sn5      nS[        U 5      U R                  4-  U-   $ s  snf )NrS  zpmResult@%#lx id#=%d rT   rg  rR   rW  r_  r   r@   rU  rV  rJ  s       r0   rJ   pmResult.__str__  sd    T\\"E1EC		! 5 566EF&)D/4<<)HH4OO F   /A2c                 x    [        U R                  [        [        5      5      nX!   R                  R
                  $ z"Return the pmid of vset[vset_idx] r   rW  r   pmValueSetPtrr_  rN  r@   vset_idxvsetptrs      r0   get_pmidpmResult.get_pmid!  ,    tyy'-"89 ))...r2   c                     [        U R                  [        [        [        5      5      5      nX!   R                  R
                  $ z$Return the valfmt of vset[vset_idx] r   rW  r   rM  r_  rP  ru  s      r0   
get_valfmtpmResult.get_valfmt&  1    tyy''**=">? ))000r2   c                     [        U R                  [        [        [        5      5      5      nX!   R                  R
                  $ z$Return the numval of vset[vset_idx] r   rW  r   rM  r_  rO  ru  s      r0   
get_numvalpmResult.get_numval+  r  r2   c                 b    [        U R                  [        [        [        5      5      5      nX!   $ zReturn the vset[vset_idx] r   rW  r   rM  ru  s      r0   get_vsetpmResult.get_vset0  %    tyy''**=">?  r2   c                     [        U R                  U5      R                  R                  [	        [
        5      5      nX2   $ z.Return the vlist[vlist_idx] of vset[vset_idx] r   r  r_  rQ  r   rG  r@   rv  	vlist_idxlistptrs       r0   	get_vlistpmResult.get_vlist5  1    t}}X.77==ww?OP!!r2   c                 8    U R                  X5      R                  $ z7Return the inst for vlist[vlist_idx] of vset[vset_idx] r  rH  r@   rv  r  s      r0   get_instpmResult.get_inst:      ~~h2777r2   rg  N)rh   ri   rj   rk   r  r}   r   r   rM  r   r9   rJ   rx  r~  r  r  r  r  rl   r   r2   r0   re  re    s[    
 g&E"'*-235HP
/
1
1
!
"
8r2   re  c                       \ rS rSrSrS\4S\4S\" \5      S-  4/r	S r
S rS	 rS
 rS rS rS rS rS rS rS rSrg)pmHighResResulti>  zHStructure returned by pmFetchHighRes, uses struct timespec for time
    rf  rg  rW  rM   c                 >    [         R                  " U 5        SU l        g r7   ri  r`   s    r0   r9   pmHighResResult.__init__E  rk  r2   c           
          [        U R                  5      n[        U Vs/ s H(  nS[        U R                  U   R                  5      -  PM*     sn5      nS[        U 5      U R                  4-  U-   $ s  snf )NrS  zpmHighResResult@%#lx id#=%d rm  rn  s       r0   rJ   pmHighResResult.__str__I  se    T\\"E1EC		! 5 566EF-4$,,0OORVVV Frp  c                 .    U R                   R                  $ )z%Return the sec part of the timestamp )rf  r   r`   s    r0   get_secpmHighResResult.get_secN  s    ~~$$$r2   c                 .    U R                   R                  $ )z&Return the nsec part of the timestamp )rf  r   r`   s    r0   get_nsecpmHighResResult.get_nsecR  s    ~~%%%r2   c                     U R                   $ )zReturn the number of pmids r  r`   s    r0   get_numpmidpmHighResResult.get_numpmidV  s    ||r2   c                 x    [        U R                  [        [        5      5      nX!   R                  R
                  $ rr  rs  ru  s      r0   rx  pmHighResResult.get_pmidZ  rz  r2   c                     [        U R                  [        [        [        5      5      5      nX!   R                  R
                  $ r|  r}  ru  s      r0   r~  pmHighResResult.get_valfmt_  r  r2   c                     [        U R                  [        [        [        5      5      5      nX!   R                  R
                  $ r  r  ru  s      r0   r  pmHighResResult.get_numvald  r  r2   c                 b    [        U R                  [        [        [        5      5      5      nX!   $ r  r  ru  s      r0   r  pmHighResResult.get_vseti  r  r2   c                     [        U R                  U5      R                  R                  [	        [
        5      5      nX2   $ r  r  r  s       r0   r  pmHighResResult.get_vlistn  r  r2   c                 8    U R                  X5      R                  $ r  r  r  s      r0   r  pmHighResResult.get_insts  r  r2   r  N)rh   ri   rj   rk   r  r   r   r   rM  r   r9   rJ   r  r  r  rx  r~  r  r  r  r  rl   r   r2   r0   r  r  >  sh    h'E"'*-235HW
%&/
1
1
!
"
8r2   r  c                   @    \ rS rSrSrS\4S\4S\4S\4S\4/rS r	S	r
g
)pmDesciz  z"Structure describing a metric
    rN  typeindomsemunitsc                 P    [        U 5      U R                  U R                  4nSU-  $ )NzpmDesc@%#lx id=%#lx type=%d)r   rN  r  )r@   fieldss     r0   rJ   pmDesc.__str__  s%    D/499dii8,v55r2   r   N)rh   ri   rj   rk   r  r   r   r   r   rJ   rl   r   r2   r0   r  r  z  s9     &!'"	$H
6r2   r  c                 .    U R                   R                  $ rd   )r_  r  r   s    r0   r   r     s    1::>>r2   c                 .    U R                   R                  $ rd   )r_  r  r   s    r0   r   r     s    AJJOOr2   c                 .    U R                   R                  $ rd   )r_  r  r   s    r0   r   r         QZZ%5%5r2   c                 .    U R                   R                  $ rd   )r_  r  r   s    r0   r   r     r  r2   c                      " S S[         5      n[        U [        [        5      5      (       a  U R                  R
                  $ U" 5       nXl        UR                  $ )zwInternal function to extract an indom from a pmdesc

Allow functions requiring an indom to be passed a pmDesc* instead
c                   0    \ rS rSrS\" \5      4S\4/rSrg)get_indom.<locals>.Valuei  rB  rC  r   N)	rh   ri   rj   rk   r   r  r   r   rl   r   r2   r0   Valuer    s    WV_-V$&r2   r  )r   r<   r   r  r_  r  rB  rC  )pmdescr  r_   s      r0   	get_indomr    sI    
& & &'&/**$$$ 
zzr2   c                   d    \ rS rSrSrS\4S\4S\4S\4S\" \5      4/rSr	S	 r
\SS
 j5       rSrg)pmMetricSpeci  z.Structure describing a metric's specification isarchsourcemetricninstrH  Nc                    ^  [        [        U 4S j[        T R                  5      5      5      n[	        T 5      T R
                  T R                  U4nSU-  $ )Nc                 4   > [        TR                  U    5      $ rd   )rR   rH  )r   r@   s    r0   r   &pmMetricSpec.__str__.<locals>.<lambda>  s    3tyy|#4r2   z+pmMetricSpec@%#lx src=%s metric=%s insts=%s)r:   maprT   r  r   r  r  )r@   instsr  s   `  r0   rJ   pmMetricSpec.__str__  sC    S4eDJJ6GHID/4;;UC<vEEr2   c           	         [        U 5      " 5       n[        5       n[        U[        5      (       d  UR	                  S5      n[        U[        5      (       d  UR	                  S5      n[
        R                  " U5      n[
        R                  " U5      n[        R                  XbU[        U5      [        U5      5      nUS:  a  [        X5      eXtl        U$ Nru   r   )r   r	   r<   r   rw   r&   rN   rP   pmParseMetricSpecr   r4   csbuffer)	r   stringr  r  rW   r   cstringcsourcer   s	            r0   
fromStringpmMetricSpec.fromString  s    &%((]]7+F&%((]]7+F--f5--f5))'7*/-vHA:''!r2   r   r   rT  )rh   ri   rj   rk   r  r   r	   r   r   r  rJ   r   r  rl   r   r2   r0   r  r    sZ    85!8$8$% *+	-H
 HF
  r2   r  c                   z    \ rS rSrSrS\4S\4S\4S\\R                  -  4S\\R                  -  4/rS rS	 rS
rg)
pmLogLabeli  z1Label record at the start of every (v2) log file magicpid_tstarthostnametzc                 H    [        U R                  R                  5       5      $ z5Return the hostname from the structure as native str rR   r  rS   r`   s    r0   get_hostnamepmLogLabel.get_hostname      4=='')**r2   c                 H    [        U R                  R                  5       5      $ z5Return the timezone from the structure as native str )rR   r  rS   r`   s    r0   get_timezonepmLogLabel.get_timezone  s    477>>#$$r2   r   N)rh   ri   rj   rk   r  r   r}   r   rE   PM_LOG_MAXHOSTLENPM_TZ_MAXLENr   r  r  rl   r   r2   r0   r  r    sT    ;% % '"Ve&=&==>v 2 223	5H+%r2   r  c                       \ rS rSrSrS\4S\4S\4S\\R                  -  4S\\R                  -  4S\\R                  -  4/rS	 rS
 rS rSrg)pmHighResLogLabeli  z1Label record at the start of every (v3) log file r  r  r  r  timezonezoneinfoc                 H    [        U R                  R                  5       5      $ r  r  r`   s    r0   r  pmHighResLogLabel.get_hostname  r  r2   c                 H    [        U R                  R                  5       5      $ r  )rR   r  rS   r`   s    r0   r  pmHighResLogLabel.get_timezone  r  r2   c                 H    [        U R                  R                  5       5      $ )z5Return the zoneinfo from the structure as native str )rR   r  rS   r`   s    r0   get_zoneinfopmHighResLogLabel.get_zoneinfo  r  r2   r   N)rh   ri   rj   rk   r  r   r   r   rE   PM_MAX_HOSTNAMELENPM_MAX_TIMEZONELENPM_MAX_ZONEINFOLENr   r  r  r  rl   r   r2   r0   r  r    sm    ;% % (#Ve&>&>>?Ve&>&>>?Ve&>&>>?AH+++r2   r  c                   J    \ rS rSrSrS\S4S\S4S\S4S\S4S	\S4/rS
 rSrg)pmLabeli  z*Structure describing label's specificationname   namelenr{   flagsr_   valuelenc                 F    U R                   S-   S-   U R                  -   S-   $ )N:")r  r_   r`   s    r0   rJ   pmLabel.__str__  s#    yy3$tzz1C77r2   r   N)	rh   ri   rj   rk   r  r   r   rJ   rl   r   r2   r0   r  r    sC    4#E1%%#%$UB'	)H
8r2   r  c                 .    U R                   R                  $ rd   )r_  r  r   s    r0   r   r     s    QZZ__r2   c                 .    U R                   R                  $ rd   )r_  r  r   s    r0   r   r     s    

(:(:r2   c                 .    U R                   R                  $ rd   )r_  r  r   s    r0   r   r         ajj&6&6r2   c                 .    U R                   R                  $ rd   )r_  r_   r   s    r0   r   r     r  r2   c                 .    U R                   R                  $ rd   )r_  r	  r   s    r0   r   r     s    )<)<r2   c            
       d    \ rS rSrSrS\4S\4S\4S\S4S\S	4S
\S4S\" \	5      4S\
4/rS rSrg)
pmLabelSeti  z-Structure describing label set specificationsrH  nlabelsjsonjsonlenr  padding   compoundrM   labelshashc                 R    U R                   c  gU R                   R                  5       $ )Nz{})r  rS   r`   s    r0   rJ   pmLabelSet.__str__  s"    99yy!!r2   r   N)rh   ri   rj   rk   r  r   r   r	   r   r  r
   r   rJ   rl   r   r2   r0   r  r    s\    8 E""E2&E2&UA&77+,"$H"r2   r  rM   c                   $   \ rS rSrSrS rS rS rS r\	" \SSS5      r
\	" \SSS5      r\	" \\SS5      rSOS jrS	 r\S
 5       rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S r"S r#S r$S r%S  r&S! r'S" r(S# r)S$ r*S% r+S& r,S' r-S( r.S) r/S* r0S+ r1S, r2S- r3S. r4S/ r5S0 r6S1 r7S2 r8S3 r9S4 r:S5 r;S6 r<S7 r=S8 r>S9 r?S: r@S; rAS< rBS= rCS> rDS? rES@ rFSA rGSB rHSC rISD rJSE rKSF rLSG rMSH rNSI rOSJ rPSK rQSL rRSM rSSNrTg)P	pmOptionsiC  z}Command line option parsing for short and long form arguments
Passed into pmGetOptions, pmGetContextOptions, pmUsageMessage.
c                     U R                   $ rd   )_moder`   s    r0   _R_modepmOptions._R_modeJ      zzr2   c                     U R                   $ rd   )_deltar`   s    r0   _R_deltapmOptions._R_deltaL  s    {{r2   c                     U R                   $ rd   _need_resetr`   s    r0   _R_need_resetpmOptions._R_need_resetN  s    r2   c                     Xl         g rd   r,  )r@   r_   s     r0   _W_need_resetpmOptions._W_need_resetP  s     r2   Nc                 Z   [         R                  " 5         Ub  [         R                  " U5        Ub  [         R                  " U5        US:w  a  [         R                  " U5        O$[         R                  " [         R
                  5        SU l        [         R                  U l        SU l	        g )Nr   rM   F)
rE   pmResetAllOptionspmSetShortOptionspmSetShortUsagepmSetOptionFlagsPM_OPTFLAG_BOUNDARIESr(  PM_MODE_INTERPr#  r-  )r@   short_optionsshort_usager  s       r0   r9   pmOptions.__init__]  s{    !$##M2"!!+.A:""5)""5#>#>?))
 r2   c                 b    [         b(  U R                  (       a  [        R                  " 5         g g g rd   )rP   r-  rE   r4  r`   s    r0   __del__pmOptions.__del__k  s$    $"2"2##% #3r2   c                  ,    [         R                  " 5       $ )z=Cross-platform --daemonize (re-parent to init) option helper )rE   pmServerStartr   r2   r0   	daemonizepmOptions.daemonizeo  s     ""$$r2   c                 ,    [         R                  " 5       $ rd   )rE   pmGetOptionFlagsr`   s    r0   rE  pmOptions.pmGetOptionFlagsw      %%''r2   c                 .    [         R                  " U5      $ rd   )rE   pmSetOptionContext)r@   contexts     r0   rI  pmOptions.pmSetOptionContextz      ''00r2   c                 .    [         R                  " U5      $ rd   )rE   r7  )r@   r  s     r0   r7  pmOptions.pmSetOptionFlags}  s    %%e,,r2   c                 ,    [         R                  " 5       $ rd   )rE   pmGetOptionErrorsr`   s    r0   rP  pmOptions.pmGetOptionErrors  s    &&((r2   c                 ^    [         R                  " 5       S-   n[         R                  " U5      $ NrM   )rE   rP  pmSetOptionErrors)r@   errorss     r0   rT  pmOptions.pmSetOptionErrors  s&    ((*Q.&&v..r2   c                 .    [         R                  " U5      $ rd   )rE   r6  )r@   r;  s     r0   r6  pmOptions.pmSetShortUsage  s    $$[11r2   c                 .    [         R                  " U5      $ rd   )rE   r5  )r@   r:  s     r0   r5  pmOptions.pmSetShortOptions  s    &&}55r2   c                 .    [         R                  " U5      $ )z.Set sample count (converts string to integer) )rE   pmSetOptionSamples)r@   counts     r0   r\  pmOptions.pmSetOptionSamples  s    ''..r2   c                 .    [         R                  " U5      $ )z6Set sampling interval (pmParseHighResInterval string) )rE   pmSetOptionInterval)r@   r   s     r0   r`  pmOptions.pmSetOptionInterval  s    ((22r2   c                 ,    [         R                  " 5       $ )zAfter 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
)rE   pmGetOperandsr`   s    r0   rc  pmOptions.pmGetOperands  s     ""$$r2   c                 .    [         R                  " U5      $ rd   rE   pmGetNonOptionsFromListr@   argvs     r0   rg  !pmOptions.pmGetNonOptionsFromList      ,,T22r2   c                 .    [         R                  " U5      $ rd   rf  rh  s     r0   pmNonOptionsFromListpmOptions.pmNonOptionsFromList  rk  r2   c                 .    [         R                  " U5      $ )ag  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).
)rE   pmSetOptionCallbackr@   funcs     r0   rp  pmOptions.pmSetOptionCallback  s     ((..r2   c                 .    [         R                  " U5      $ )a5  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
)rE   pmSetOverrideCallbackrq  s     r0   ru  pmOptions.pmSetOverrideCallback  s     **400r2   c                 <    Uc  Sn[         R                  " XX4U5      $ )zAdd 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).
rT  )rE   pmSetLongOption)r@   long_opthas_arg	short_optargnamerH   s         r0   rx  pmOptions.pmSetLongOption  s$     I$$X	GTTr2   c                 .    [         R                  " U5      $ )z=Add a new section heading into the long option usage message )rE   pmSetLongOptionHeader)r@   headings     r0   r  pmOptions.pmSetLongOptionHeader  s    **733r2   c                 .    [         R                  " U5      $ )z=Add some descriptive text into the long option usage message )rE   pmSetLongOptionText)r@   texts     r0   r  pmOptions.pmSetLongOptionText  s    ((..r2   c                 ,    [         R                  " 5       $ )z3Add support for -A/--align into PMAPI monitor tool )rE   pmSetLongOptionAlignr`   s    r0   r  pmOptions.pmSetLongOptionAlign      ))++r2   c                 ,    [         R                  " 5       $ )z5Add support for -a/--archive into PMAPI monitor tool )rE   pmSetLongOptionArchiver`   s    r0   r   pmOptions.pmSetLongOptionArchive      ++--r2   c                 ,    [         R                  " 5       $ )z3Add support for -D/--debug into PMAPI monitor tool )rE   pmSetLongOptionDebugr`   s    r0   r  pmOptions.pmSetLongOptionDebug  r  r2   c                     gzUnimplemented Nr   r`   s    r0   pmSetLongOptionGuiMode pmOptions.pmSetLongOptionGuiMode      r2   c                 ,    [         R                  " 5       $ )z2Add support for -h/--host into PMAPI monitor tool )rE   pmSetLongOptionHostr`   s    r0   r  pmOptions.pmSetLongOptionHost      ((**r2   c                 ,    [         R                  " 5       $ )z7Add support for -H/--hostsfile into PMAPI monitor tool )rE   pmSetLongOptionHostsFiler`   s    r0   r  "pmOptions.pmSetLongOptionHostsFile      --//r2   c                 ,    [         R                  " 5       $ )z8Add support for -K/--spec-local into PMAPI monitor tool )rE   pmSetLongOptionSpecLocalr`   s    r0   r  "pmOptions.pmSetLongOptionSpecLocal  r  r2   c                 ,    [         R                  " 5       $ )z8Add support for -L/--local-PMDA into PMAPI monitor tool )rE   pmSetLongOptionLocalPMDAr`   s    r0   r  "pmOptions.pmSetLongOptionLocalPMDA  r  r2   c                 ,    [         R                  " 5       $ )z4Add support for -O/--origin into PMAPI monitor tool )rE   pmSetLongOptionOriginr`   s    r0   r  pmOptions.pmSetLongOptionOrigin      **,,r2   c                     gr  r   r`   s    r0   pmSetLongOptionGuiPort pmOptions.pmSetLongOptionGuiPort  r  r2   c                 ,    [         R                  " 5       $ )z3Add support for -S/--start into PMAPI monitor tool )rE   pmSetLongOptionStartr`   s    r0   r  pmOptions.pmSetLongOptionStart  r  r2   c                 ,    [         R                  " 5       $ )z5Add support for -s/--samples into PMAPI monitor tool )rE   pmSetLongOptionSamplesr`   s    r0   r   pmOptions.pmSetLongOptionSamples  r  r2   c                 ,    [         R                  " 5       $ )z4Add support for -T/--finish into PMAPI monitor tool )rE   pmSetLongOptionFinishr`   s    r0   r  pmOptions.pmSetLongOptionFinish  r  r2   c                 ,    [         R                  " 5       $ )z6Add support for -t/--interval into PMAPI monitor tool )rE   pmSetLongOptionIntervalr`   s    r0   r  !pmOptions.pmSetLongOptionInterval      ,,..r2   c                 ,    [         R                  " 5       $ )z5Add support for -V/--version into PMAPI monitor tool )rE   pmSetLongOptionVersionr`   s    r0   r   pmOptions.pmSetLongOptionVersion  r  r2   c                 ,    [         R                  " 5       $ )z6Add support for -Z/--timezone into PMAPI monitor tool )rE   pmSetLongOptionTimeZoner`   s    r0   r  !pmOptions.pmSetLongOptionTimeZone  r  r2   c                 ,    [         R                  " 5       $ )z6Add support for -z/--hostzone into PMAPI monitor tool )rE   pmSetLongOptionHostZoner`   s    r0   r  !pmOptions.pmSetLongOptionHostZone  r  r2   c                 ,    [         R                  " 5       $ )z2Add support for -?/--help into PMAPI monitor tool )rE   pmSetLongOptionHelpr`   s    r0   r  pmOptions.pmSetLongOptionHelp  r  r2   c                 ,    [         R                  " 5       $ )z7Add support for --archive-list into PMAPI monitor tool )rE   pmSetLongOptionArchiveListr`   s    r0   r  $pmOptions.pmSetLongOptionArchiveList  s    //11r2   c                 ,    [         R                  " 5       $ )z8Add support for --archive-folio into PMAPI monitor tool )rE   pmSetLongOptionArchiveFolior`   s    r0   r  %pmOptions.pmSetLongOptionArchiveFolio  s    0022r2   c                 ,    [         R                  " 5       $ )z4Add support for --container into PMAPI monitor tool )rE   pmSetLongOptionContainerr`   s    r0   r  "pmOptions.pmSetLongOptionContainer  r  r2   c                 ,    [         R                  " 5       $ )z4Add support for --host-list into PMAPI monitor tool )rE   pmSetLongOptionHostListr`   s    r0   r  !pmOptions.pmSetLongOptionHostList#  r  r2   c                 ,    [         R                  " 5       $ rd   )rE   pmGetOptionContextr`   s    r0   r  pmOptions.pmGetOptionContext'      ''))r2   c                 ,    [         R                  " 5       $ rd   )rE   pmGetOptionHostsr`   s    r0   r  pmOptions.pmGetOptionHosts*  rG  r2   c                 ,    [         R                  " 5       $ rd   )rE   pmGetOptionArchivesr`   s    r0   r  pmOptions.pmGetOptionArchives-      ((**r2   c                 ^    [         R                  " 5       nUc  g [        R                  U5      $ rd   )rE   pmGetOptionAlign_optargr}   r   r@   	alignments     r0   pmGetOptionAlignmentpmOptions.pmGetOptionAlignment0  s*    113	##I..r2   c                 ^    [         R                  " 5       nUc  g [        R                  U5      $ rd   )rE   r  r   r   r  s     r0   pmGetOptionHighResAlignment%pmOptions.pmGetOptionHighResAlignment6  s*    113	$$Y//r2   c                 r    [         R                  " 5       nUc  g [        U[         R                  " 5       5      $ rd   )rE   pmGetOptionStart_secr}   pmGetOptionStart_usecr@   r   s     r0   pmGetOptionStartpmOptions.pmGetOptionStart<  s.    ((*;sE779::r2   c                 r    [         R                  " 5       nUc  g [        U[         R                  " 5       5      $ rd   )rE   r  r   pmGetOptionStart_nsecr  s     r0   pmGetOptionHighResStart!pmOptions.pmGetOptionHighResStartB  s.    ((*;U88:;;r2   c                 ,    [         R                  " 5       $ rd   )rE   r  r`   s    r0   pmGetOptionAlignOptarg pmOptions.pmGetOptionAlignOptargH  s    ,,..r2   c                 ,    [         R                  " 5       $ rd   )rE   pmGetOptionFinish_optargr`   s    r0   pmGetOptionFinishOptarg!pmOptions.pmGetOptionFinishOptargK  s    --//r2   c                 r    [         R                  " 5       nUc  g [        U[         R                  " 5       5      $ rd   )rE   pmGetOptionFinish_secr}   pmGetOptionFinish_usecr  s     r0   pmGetOptionFinishpmOptions.pmGetOptionFinishN  .    ))+;sE88:;;r2   c                 r    [         R                  " 5       nUc  g [        U[         R                  " 5       5      $ rd   )rE   r  r   pmGetOptionFinish_nsecr  s     r0   pmGetOptionHighResFinish"pmOptions.pmGetOptionHighResFinishT  .    ))+;U99;<<r2   c                 r    [         R                  " 5       nUc  g [        U[         R                  " 5       5      $ rd   )rE   pmGetOptionOrigin_secr}   pmGetOptionOrigin_usecr  s     r0   pmGetOptionOriginpmOptions.pmGetOptionOriginZ  r  r2   c                 r    [         R                  " 5       nUc  g [        U[         R                  " 5       5      $ rd   )rE   r  r   pmGetOptionOrigin_nsecr  s     r0   pmGetOptionHighResOrigin"pmOptions.pmGetOptionHighResOrigin`  r  r2   c                 r    [         R                  " 5       nUc  g [        U[         R                  " 5       5      $ rd   )rE   pmGetOptionInterval_secr}   pmGetOptionInterval_usecr  s     r0   pmGetOptionIntervalpmOptions.pmGetOptionIntervalf  s.    ++-;sE::<==r2   c                 r    [         R                  " 5       nUc  g [        U[         R                  " 5       5      $ rd   )rE   r
  r   pmGetOptionInterval_nsecr  s     r0   pmGetOptionHighResInterval$pmOptions.pmGetOptionHighResIntervall  s.    ++-;U;;=>>r2   c                 ,    [         R                  " 5       $ rd   )rE   pmGetOptionSamplesr`   s    r0   r  pmOptions.pmGetOptionSamplesr  r  r2   c                 8    [         R                  " 5       S:X  a  ggNr   FT)rE   pmGetOptionHostZoner`   s    r0   r  pmOptions.pmGetOptionHostZoneu  s    $$&!+r2   c                 ,    [         R                  " 5       $ rd   )rE   pmGetOptionTimezoner`   s    r0   r  pmOptions.pmGetOptionTimezonez  r  r2   c                 ,    [         R                  " 5       $ rd   )rE   pmGetOptionContainerr`   s    r0   r  pmOptions.pmGetOptionContainer}      ))++r2   c                 8    [         R                  " 5       S:X  a  ggr  )rE   pmGetOptionLocalPMDAr`   s    r0   r!  pmOptions.pmGetOptionLocalPMDA  s    %%'1,r2   c                 .    [         R                  " U5      $ rd   )rE   pmSetOptionArchive)r@   archives     r0   r$  pmOptions.pmSetOptionArchive  rL  r2   c                 .    [         R                  " U5      $ rd   )rE   pmSetOptionArchiveList)r@   archivess     r0   r(   pmOptions.pmSetOptionArchiveList  s    ++H55r2   c                 .    [         R                  " U5      $ rd   )rE   pmSetOptionArchiveFolio)r@   folios     r0   r,  !pmOptions.pmSetOptionArchiveFolio  s    ,,U33r2   c                 .    [         R                  " U5      $ rd   )rE   pmSetOptionContainer)r@   	containers     r0   r0  pmOptions.pmSetOptionContainer  s    )))44r2   c                 .    [         R                  " U5      $ rd   )rE   pmSetOptionHost)r@   hosts     r0   r4  pmOptions.pmSetOptionHost  s    $$T**r2   c                 .    [         R                  " U5      $ rd   )rE   pmSetOptionHostList)r@   hostss     r0   r8  pmOptions.pmSetOptionHostList  s    ((//r2   c                 .    [         R                  " U5      $ rd   )rE   pmSetOptionSpecLocal)r@   specs     r0   r<  pmOptions.pmSetOptionSpecLocal  s    ))$//r2   c                 ,    [         R                  " 5       $ rd   )rE   pmSetOptionLocalPMDAr`   s    r0   r@  pmOptions.pmSetOptionLocalPMDA  r  r2   )r(  r#  r-  )NNr   )Urh   ri   rj   rk   r  r$  r)  r.  r1  r]  modedelta
need_resetr9   r>  staticmethodrB  rE  rI  r7  rP  rT  r6  r5  r\  r`  rc  rg  rm  rp  ru  rx  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  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r$  r(  r,  r0  r4  r8  r<  r@  rl   r   r2   r0   r!  r!  C  s    ! GT4.DXtT40E-dCJ
!& % %(1-)/26/3%33
/	1	U4/,.,+000-,.-/.//+230/*(+/0;</0<=<=>?*
+,
1645+00,r2   r!  c                   L   \ rS rSrSrS rS rS r\" \SSS5      r	\" \SSS5      r
\" \SSS5      r\R                  S4S jrS	 r\SrS
 j5       r\S 5       rS rS rS rS rSsS jrS rS rS rS rS rS r\S 5       rS r S r!\RD                  4S jr#\RD                  4S jr$StS jr%S r&S r'S r(S  r)S! r*S" r+S# r,\S$ 5       r-S% r.S& r/S' r0S( r1S) r2S* r3S+ r4\S, 5       r5\S- 5       r6\S. 5       r7S/ r8S0 r9S1 r:S2 r;S3 r<\S4 5       r=\S5 5       r>S6 r?S7 r@S8 rAS9 rBS: rCS; rDS< rES= rFS> rGS? rHS@ rISuSA jrJSB rKSC rLSD rMSE rNSF rOSG rPSH rQ\SI 5       rR\StSJ j5       rS\SvSK j5       rT\SL 5       rU\SM 5       rV\SN 5       rW\SO 5       rX\SP 5       rY\SQ 5       rZ\SR 5       r[\SS 5       r\\ST 5       r]\SU 5       r^\SV 5       r_\SW 5       r`\SX 5       ra\SY 5       rb\SZ 5       rc\S[ 5       rd\S\ 5       re\S] 5       rf\S^ 5       rg\S_ 5       rh\S` 5       ri\Sa 5       rj\Sb 5       rk\Sc 5       rl\Sd 5       rm\SwSe j5       rn\Sf 5       ro\Sg 5       rp\Sh 5       rq\Si 5       rr\Sj 5       rs\SxSk j5       rt\Sl 5       ru\Sm 5       rv\\R                  4Sn j5       rx\So 5       rySp rzSqr{g)y	pmContexti  a  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
c                     U R                   $ rd   )_typer`   s    r0   _R_typepmContext._R_type  r&  r2   c                     U R                   $ rd   )_targetr`   s    r0   	_R_targetpmContext._R_target  s    ||r2   c                     U R                   $ rd   )_ctxr`   s    r0   _R_ctxpmContext._R_ctx  rg   r2   Nlocal:c                 (   Xl         X l        [        R                  U l        U(       a'  [        U[        5      (       d  UR                  S5      nOUn[        R                  X5      U l        U R                  S:  a  [        U R                  U/5      eg r  )rI  rM  rE   PM_ERR_NOCONTEXTrQ  r<   r   rw   rP   pmNewContextr4   )r@   r  targetr  s       r0   r9   pmContext.__init__  sp    
**	*VU33]]7+FF''6	99q=		F8,, r2   c                     [         b?  U R                  [        R                  :w  a   [         R	                  U R                  5        g g g rd   )rP   rQ  rE   rV  pmDestroyContextr`   s    r0   r>  pmContext.__del__  s4    $))u/E/E"E##DII. #Fr2   c                 |   Ub  US::  a8  SUl         [        R                  " U5      (       a  [        eUR	                  5       nU[        R
                  :X  a  UR                  5       nXT   nOU[        R                  :X  a  UR                  5       nXt   nO_U[        R                  :X  a  SnOHUR                  5       b%  UR                  5       nXT   n[        R
                  nO[        R                  nSnU " X65      n[        R                  " UR                  UR                  UR                  5      (       a  [        eU$ )aD  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.
Nr   TrT  )rD  rE   pmGetOptionsFromListrp   r  PM_CONTEXT_ARCHIVEr  PM_CONTEXT_HOSTr  PM_CONTEXT_LOCALr  pmSetContextOptionsctxrB  rC  )	r   optionsri  r  rX   r)  r  r9  rJ  s	            r0   fromOptionspmContext.fromOptions  s   " =EQJ!%G))$//  ..0EE,,,224H_Fe+++,,.E\Fe,,,F&&(4224H_F,,E))EF e$ $$W[[',,NNr2   c                    Sn[         R                  " 5       (       aC  [         R                  nU R                  [         R                  5        U R                  5       S   nO[         R                  " 5       (       aC  [         R
                  nU R                  [         R
                  5        U R	                  5       S   nOK[         R                  " 5       (       a1  [         R                  nU R                  [         R                  5        SnU(       d  SU;   aA  [         R                  nU R                  U5        U R                  [         R                  5        OUS:w  aA  [         R
                  nU R                  U5        U R                  [         R
                  5        OA[         R                  nU R                  5         U R                  [         R                  5        SnU[         R                  :X  a:  U(       a3  [        SUR                  S5      5       H  nU R                  U5        M     U R                  5       nU R                  U[         R                   -  5        [         R"                  " 5         X14$ )zEHelper to set connection options and to get context/source for pmfg. Nr   /@;)rE   r  r_  rI  r  r`  r!  ra  r$  r4  r@  filtersplitr<  rE  r7  PM_OPTFLAG_DONEpmEndOptions)rd  r  	speclocalrJ  r=  r  s         r0   set_connect_optionspmContext.set_connect_options  s    $$&&..G&&u'?'?@00215F##%%++G&&u'<'<=--/2F'')),,G&&u'='=>Ff}22**62**5+C+CD3//''/**5+@+@A00,,.**5+A+ABe,,,tY__S%9:,,T2 ; ((*  )>)>!>?r2   c                   ^ [        [        5      " 5       m[        R                  U R                  5      nUS:  a  [        U5      e[        U[        5      (       d  UR                  S5      n[        R                  U[        T5      5      nUS:  a  [        U5      eUS:  a9  [        [        U4S j[        U5      5      5      n[        R                  T5        U$ g)zcPMAPI - Return names of children of the given PMNS node NAME
tuple names = pmGetChildren("kernel")
r   ru   c                 <   > [        TU    R                  5       5      $ rd   rR   rS   r   	offsprings    r0   r   )pmContext.pmGetChildren.<locals>.<lambda>N      IaL,?,?,A(Br2   N)r   r	   rP   pmUseContextrc  r4   r<   r   rw   pmGetChildrenr   r:   r  rT   LIBCfree)r@   r  r   childLrv  s       @r0   rz  pmContext.pmGetChildren@  s     H%'	$$TXX.A:-$&&;;w'D%%dE),<=A:-A:#BE&MRSFIIi   r2   c                 f  ^^ [        [        5      " 5       m[        [        5      " 5       m[        R	                  U R
                  5      nUS:  a  [        U5      e[        U[        5      (       d  UR                  S5      n[        R                  U[        T5      [        T5      5      nUS:  a  [        U5      eUS:  aq  [        [        U4S j[        U5      5      5      n[        [        U4S j[        U5      5      5      n[        R!                  T5        [        R!                  T5        X44$ g)zPMAPI - Return names and status of children of the given metric NAME
(tuple names,tuple status) = pmGetChildrenStatus("kernel")
r   ru   c                 <   > [        TU    R                  5       5      $ rd   rt  ru  s    r0   r   /pmContext.pmGetChildrenStatus.<locals>.<lambda>d  rx  r2   c                     > [        TU    5      $ rd   r=   )r   	childstats    r0   r   r  e  s    s9Q<'8r2   NN)r   r	   r   rP   ry  rc  r4   r<   r   rw   pmGetChildrenStatusr   r:   r  rT   r{  r|  )r@   r  r   r}  statLr  rv  s        @@r0   r  pmContext.pmGetChildrenStatusT  s     H%'	EN$	$$TXX.A:-$&&;;w'D++D,1),<eI>NPA:-A:#BE&MRSF8%-HIEIIi IIi  } r2   c                     [         R                  U R                  5      nUS:  a  [        U5      e[         R	                  5       nUS:  a  [        U5      eU$ )zEPMAPI - Return the namespace location type
loc = pmGetPMNSLocation()
r   )rP   ry  rc  r4   pmGetPMNSLocationr@   r   s     r0   r  pmContext.pmGetPMNSLocationl  sM     $$TXX.A:-))+A:-r2   c                     [         R                  U R                  5      nUS:  a  [        U5      e[	        U[
        5      (       d  UR                  S5      n[         R                  U5      nUS:  a  [        U5      eU$ )zDPMAPI - Load a local namespace
status = pmLoadNameSpace("filename")
r   ru   )rP   ry  rc  r4   r<   r   rw   pmLoadNameSpace)r@   filenamer   s      r0   r  pmContext.pmLoadNameSpacex  sj     $$TXX.A:-(E**w/H''1A:-r2   c                    [         R                  U R                  5      nUS:  a  [        U5      e[	        U[
        [        45      (       a  SnO[        U5      n[        U-  " 5       n[	        U[
        5      (       a  [        UR                  S5      5      US'   Ox[	        U[        5      (       a  [        U5      US'   OT[        U5       HE  u  pg[	        U[        5      (       a  [        U5      XV'   M)  [        UR                  S5      5      XV'   MG     [        U-  " 5       n[        [        U-  [        [        5      /[         R                  l        [         R                  XEU5      nUS:  a  [        X85      eUS:X  aT  X4:w  aO  [!        X5       VV	s/ s H  u  pyU	["        R$                  :X  d  M  UPM     n
nn	[        ["        R&                  U
5      eU$ s  sn	nf )zPMAPI - Lookup pmIDs from a list of metric names nameA

c_uint pmid [] = pmLookupName("MetricName")
c_uint pmid [] = pmLookupName(("MetricName1", "MetricName2", ...))
r   rM   ru   )rP   ry  rc  r4   r<   rR   r   rU   r	   rw   	enumerater   r   r   pmLookupNamer+   ziprE   
PM_ID_NULLPM_ERR_NAME)r@   nameArelaxedr   nnamesrV  r  pmidArN  badLs              r0   r  pmContext.pmLookupName  s{    $$TXX.A:-ec5\**AE
AA eS!!W 56E!Hu%%E!H$U+dE**'~EH'G(<=EH	 ,
 !(-1wv'O$$$Qu5A:&&a<FK-0-> M->\d375;K;K3K ->D M))400Ms   G/Gc                 ^  ^ [         R                  U R                  5      nUS:  a  [        U5      e[	        [
        5      " 5       m[         R                  U[        T5      5      nUS:  a  [        U5      e[        [        U4S j[        U5      5      5      n[        R                  T5        U$ )zfPMAPI - Return list of all metric names having this identical PMID
tuple names = pmNameAll(metric_id)
r   c                 <   > [        TU    R                  5       5      $ rd   rt  r   nameA_ps    r0   r   %pmContext.pmNameAll.<locals>.<lambda>  s    3wqz'8'8':#;r2   )rP   ry  rc  r4   r   r	   	pmNameAllr   r:   r  rT   r{  r|  )r@   rN  r   nameLr  s       @r0   r  pmContext.pmNameAll  s     $$TXX.A:-(#%!!$g7A:-S;U6]KL		'r2   c                 J   [        5       n[        R                  U R                  5      nUS:  a  [	        U5      e[        R                  U[        U5      5      nUS:  a  [	        U5      eUR                  n[        R                  U5        [        UR                  5       5      $ )zIPMAPI - Return a metric name from a PMID
name = pmNameID(self.metric_id)
r   )r	   rP   ry  rc  r4   pmNameIDr   r_   r{  r|  rR   rS   )r@   rN  r  r   rW   s        r0   r  pmContext.pmNameID  sz     z$$TXX.A:-uT{3A:-		$6==?##r2   c                     [         R                  U R                  5      nUS:  a  [        U5      e[        R
                  " X5      nUS:  a  [        U5      eg)ztPMAPI - Scan namespace, depth first, run CALLBACK at each node
status = pmTraversePMNS("kernel", traverse_callback)
r   N)rP   ry  rc  r4   rE   pmnsTraverse)r@   r  callbackr   s       r0   pmTraversePMNSpmContext.pmTraversePMNS  sO     $$TXX.A:-##D3A:- r2   c                     [         R                  U R                  5      nUS:  a  [        U5      e[         R	                  5       nUS:  a  [        U5      eg)z]PMAPI - Unloads a local PMNS, if one was previously loaded
pm.pmUnLoadNameSpace("NameSpace")
r   N)rP   ry  rc  r4   pmUnloadNameSpacer  s     r0   pmUnLoadNameSpacepmContext.pmUnLoadNameSpace  sM     $$TXX.A:-))+A:- r2   c                    [        U[        5      (       d  UR                  S5      n[        U[        5      (       d  UR                  S5      n[        5       n[        R                  X[        U5      5      nUS:w  aR  [        UR                  R                  5       5      n[        R                  U5        [        [        R                  U5      e[        R                  U R                   5      nUS:  a  [        U5      eg)zrPMAPI - Register a derived metric name and definition
pm.pmRegisterDerived("MetricName", "MetricName Expression")
ru   r   N)r<   r   rw   r	   rP   pmRegisterDerivedMetricr   rR   r_   rS   r{  r|  r4   rE   PM_ERR_CONVpmReconnectContextrc  )r@   r  exprr   rW   r  r   s          r0   pmRegisterDerivedpmContext.pmRegisterDerived  s     $&&;;w'D$&&;;w'D//E&MJQ;v||**,-DIIf))400**4884A:- r2   c                     [        U[        5      (       d  UR                  S5      n[        R	                  U5      =p#US:  a  [        U5      e[        R                  U R                  5      nUS:  a  [        U5      eU$ )zePMAPI - Register derived metric names and definitions from a file
pm.pmLoadDerivedConfig("FileName")
ru   r   )r<   r   rw   rP   pmLoadDerivedConfigr4   r  rc  )r@   fnamer   r]  s       r0   r  pmContext.pmLoadDerivedConfig  sm     %''LL)E33E::A:-**4884A:-r2   c                  d    [         R                  5       n U b  [        U R                  5       5      $ g)zvPMAPI - Return an error message if the pmRegisterDerived(3) metric
definition cannot be parsed
pm.pmRegisterDerived()
N)rP   pmDerivedErrStrrR   rS   )rW   s    r0   r  pmContext.pmDerivedErrStr  s,     '')v}}''r2   c                 @   [         R                  U R                  5      nUS:  a  [        U5      e[        R
                  " [        [        5      5      n[        U[        [        5      5      n[        U5      n[         R                  XT5      nUS:  a  [        U5      eU$ )zfPMAPI - Lookup a metric description structure from a pmID

pmDesc* pmdesc = pmLookupDesc(c_uint pmid)
r   )rP   ry  rc  r4   r&   rN   r   r  r   r   r   pmLookupDesc)r@   pmid_pr   descbufdescrN  s         r0   r  pmContext.pmLookupDesc  s|     $$TXX.A:---fVn=GWV_-f~$$T0A:-r2   c                    [         R                  U R                  5      nUS:  a  [        U5      e[	        U[
        5      (       a  [        S-  " 5       nXS'   O8[        [        U5      -  " 5       n[        U5       H  u  pE[        U5      X4'   M     [        R                  " [        U5      [        [        5      -  5      n[        U[        [        5      5      n[         R                  [        U5      X75      nUS:  a  [        U5      e[        [        5      [        U5      -  " 5       n[!        [        U5      5       H  n[#        Xt   5      X'   M     U$ )zPMAPI - Lookup metric description structures from pmIDs

(pmDesc* pmdesc)[] = pmLookupDescs(c_uint pmid[N])
(pmDesc* pmdesc)[] = pmLookupDescs(c_uint pmid)
r   rM   )rP   ry  rc  r4   r<   integer_typesr   rU   r  r&   rN   r   r  r   r   pmLookupDescsrT   r   )	r@   pmids_pr   pmidsrV  rN  descsbufdesclistdescss	            r0   r  pmContext.pmLookupDescs  s    $$TXX.A:-g}--aZNE!Hc'l*-E$W-!$< . ..s5zF6N/JK'&/2%%c%j%BA:- 3u:-0s5z"Ax{+EH #r2   c                 ^   [        5       n[        R                  U R                  5      nUS:  a  [	        U5      e[        R                  [        U5      U[        U5      5      nUS:  a  [	        U5      eUR                  n[        R                  U5        [        UR                  5       5      $ )zlPMAPI - Lookup the description of a metric's instance domain

"instance" = pmLookupInDomText(pmDesc pmdesc)
r   )r	   rP   ry  rc  r4   pmLookupInDomTextr  r   r_   r{  r|  rR   rS   )r@   r  kindbufr   rW   s         r0   r  pmContext.pmLookupInDomText>  s    
 j$$TXX.A:-)))F*;T5:NA:-		#6==?##r2   c                 J   [        5       n[        R                  U R                  5      nUS:  a  [	        U5      e[        R                  X[        U5      5      nUS:  a  [	        U5      eUR                  n[        R                  U5        [        UR                  5       5      $ )zUPMAPI - Lookup the description of a metric from its pmID
"desc" = pmLookupText(pmid)
r   )r	   rP   ry  rc  r4   pmLookupTextr   r_   r{  r|  rR   rS   )r@   rN  r  r  r   r  s         r0   r  pmContext.pmLookupTextO  s|     j$$TXX.A:-$$Ts<A:-yy		#4;;=!!r2   c                   ^^ Uc  Uc  [        [        R                  S5      e[        [        5      " 5       m[        [
        5      " 5       m[        R                  U R                  5      nUS:  a  [        U5      eUc  [        U5      n[        R                  U[        T5      [        T5      5      nUS:  a  [        U5      eUS:  aq  [        [        U4S j[        U5      5      5      n[        [        U4S j[        U5      5      5      n[        R!                  T5        [        R!                  T5        XT4$ SnSnXT4$ )zPMAPI - Lookup the list of instances from an instance domain PMDESCP or indom
([instance1, instance2...] [name1, name2...]) pmGetInDom(pmDesc pmdesc)
Nzinvalid argumentsr   c                 @   > [        TU    R                  SS5      5      $ Nasciiignorert  r  s    r0   r   &pmContext.pmGetInDom.<locals>.<lambda>s      s71:+<+<Wh+O'Pr2   c                     > [        TU    5      $ rd   r  r   instA_ps    r0   r   r  t      s71:r2   )r4   rE   PM_ERR_GENERICr   r   r	   rP   ry  rc  r  
pmGetInDomr   r:   r  rT   r{  r|  )r@   pmdescpr  r   r  instLr  r  s         @@r0   r  pmContext.pmGetInDoma  s    ?u},,.ABB%."(#%$$TXX.A:-=g&E""5%.%.IA:-A:PRWX^R_`aE6fFGEIIgIIg | EE|r2   c                    [         R                  U R                  5      nUS:  a  [        U5      e0 nU R	                  US9u  pEUb  Uc  U$ [        U5      n[        U5       H  nUR                  XG   XW   05        M     U$ )z0helper to return dict of inst:name for an indom r   )r  )rP   ry  rc  r4   r  rU   rT   update)r@   r  r   retDr  r  r  rV  s           r0   pmGetInDomDictpmContext.pmGetInDomDict|  s}    $$TXX.A:-U3=EMKJqAKK58,- r2   c                    [         R                  U R                  5      nUS:  a  [        U5      e[	        U[
        5      (       d  UR                  S5      n[         R                  [        U5      U5      nUS:  a  [        U5      eU$ )zzPMAPI - Lookup the instance id with the given NAME in the indom

c_uint instid = pmLookupInDom(pmDesc pmdesc, "Instance")
r   ru   )	rP   ry  rc  r4   r<   r   rw   pmLookupInDomr  r@   r  r  r   s       r0   r  pmContext.pmLookupInDom  sq    
 $$TXX.A:-$&&;;w'D%%i&7>A:-r2   c                    U[         R                  :X  a  g[        5       n[        R	                  U R
                  5      nUS:  a  [        U5      e[        R                  [        U5      U[        U5      5      nUS:  a  [        U5      eUR                  n[        R                  U5        [        UR                  SS5      5      $ )zxPMAPI - Lookup the text name of an instance in an instance domain

"string" = pmNameInDom(pmDesc pmdesc, c_uint instid)

PM_IN_NULLr   r  r  )rE   r  r	   rP   ry  rc  r4   pmNameInDomr  r   r_   r{  r|  rR   rS   )r@   r  instvalname_pr   rW   s         r0   r  pmContext.pmNameInDom  s    
 e&&&$$TXX.A:-##If$5wfNA:-		&6==(344r2   c                     g)zPMAPI - NOOP - Establish a new PMAPI context (done in constructor)

This is unimplemented. A new context is established when a pmContext
object is created.
Nr   )r@   r  r  s      r0   rW  pmContext.pmNewContext      r2   c                     g)zPMAPI - NOOP - Destroy a PMAPI context (done in destructor)

This is unimplemented. The context is destroyed when the pmContext
object is destroyed.
Nr   r@   handles     r0   r[  pmContext.pmDestroyContext  r  r2   c                     [         R                  U R                  5      nUS:  a  [        U5      e[         R	                  5       nUS:  a  [        U5      eU$ )zVPMAPI - Duplicate the current PMAPI Context

This supports copying a pmContext object
r   )rP   ry  rc  r4   pmDupContextr  s     r0   r  pmContext.pmDupContext  sM    
 $$TXX.A:-$$&A:-r2   c                     g)zPMAPI - 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  s     r0   ry  pmContext.pmUseContext  r  r2   c                  P    [         R                  5       n U S:  a  [        U 5      eU $ )zSPMAPI - Returns the handle of the current PMAPI context
context = pmWhichContext()
r   )rP   pmWhichContextr4   r   s    r0   r  pmContext.pmWhichContext  s(    
 &&(A:-r2   c                    [        U[        5      (       a  Sn[        U-  " 5       nX$S'   ORUb  U(       d  Sn[        [        5      " 5       nO1[	        U5      n[        U-  " 5       n[        U5       H	  u  pVXdU'   M     [        R                  U R                  5      nUS:  a  [        U5      e[        R                  [        U5      X45      nUS:  a  [        U5      eU$ )zuPMAPI - add instances to list that will be collected from indom

status = pmAddProfile(pmDesc pmdesc, c_uint instid)
rM   r   )r<   r=   r   r   rU   r  rP   ry  rc  r4   pmAddProfiler  r@   r  r  numinstinstArX   r_   r   s           r0   r  pmContext.pmAddProfile  s    
 eS!!GW_'E!H]%GEN$E%jGW_'E )% 0$e !1$$TXX.A:-$$Yv%6GA:-r2   c                 j   Ub  U(       d  Sn[        [        5      " 5       nO1[        U5      n[        U-  " 5       n[        U5       H	  u  pVXdU'   M     [        R                  U R                  5      nUS:  a  [        U5      e[        R                  [        U5      X45      nUS:  a  [        U5      eU$ )zPMAPI - delete instances from list to be collected from indom

status = pmDelProfile(pmDesc pmdesc, c_uint inst)
status = pmDelProfile(pmDesc pmdesc, [c_uint inst])
r   )
r   r   rU   r  rP   ry  rc  r4   pmDelProfiler  r  s           r0   r  pmContext.pmDelProfile  s     =GEN$E%jGW_'E )% 0$e !1$$TXX.A:-$$Yv%6GA:-r2   c                     [         R                  U R                  5      nUS:  a  [        U5      eSnUb  [	        U5      nSnUb  US:w  a  [	        U5      n[         R                  XU5      nUS:  a  [        U5      eU$ )z{PMAPI - set interpolation mode for reading archive files
code = pmSetModeHighRes(c_api.PM_MODE_INTERP, timespec, timespec)
r   N)rP   ry  rc  r4   r   pmSetModeHighRes)r@   rB  originr   r   whenrC  s          r0   r  pmContext.pmSetModeHighRes	  s     $$TXX.A:-6?DHMH%E((U;A:-r2   c                     [         R                  U R                  5      nUS:  a  [        U5      eSnUb  [	        U5      n[         R                  XU5      nUS:  a  [        U5      eU$ )zlPMAPI - set interpolation mode for reading archive files
code = pmSetMode(c_api.PM_MODE_INTERP, timeval, 0)
r   N)rP   ry  rc  r4   r   	pmSetMode)r@   rB  timeValrC  r   r  s         r0   r  pmContext.pmSetMode  sf     $$TXX.A:-7#D!!$e4A:-r2   c                 f    [         R                  U R                  5      nUS:  a  [        U5      eU$ )zPMAPI - 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   )rP   r  rc  r4   r  s     r0   r  pmContext.pmReconnectContext*  s.     **4884A:-r2   c                     [         R                  n[        R                  " U5      n[        R                  U R                  X!5      n[        UR                  5       5      $ )zPMAPI - Lookup the hostname for the given context

This method simply returns the hostname for the context belonging to
its pmContext instance object.

"hostname" = pmGetContextHostName()
)	rE   r  r&   rN   rP   pmGetContextHostName_rrc  rR   rS   )r@   buflenbufferrW   s       r0   pmGetContextHostNamepmContext.pmGetContextHostName6  sF     ((,,V4..txxH6==?##r2   c                     [         R                  U R                  5      nUS:  a  [        U5      e[         R	                  5       nUS:  a  [        U5      eU$ )z5PMAPI - Query and set the current reporting timezone r   )rP   ry  rc  r4   pmNewContextZoner  s     r0   r!  pmContext.pmNewContextZoneF  sK    $$TXX.A:-((*A:-r2   c                     [        U [        5      (       d  U R                  S5      n [        R	                  U 5      nUS:  a  [        U5      eU$ )z:PMAPI - Create new zone handle and set reporting timezone ru   r   )r<   r   rw   rP   	pmNewZoner4   )r  r   s     r0   r$  pmContext.pmNewZoneP  sE     "e$$7#B!!"%A:-r2   c                 R    [         R                  U 5      nUS:  a  [        U5      eU$ )z,PMAPI - Sets the current reporting timezone r   )rP   	pmUseZoner4   )	tz_handler   s     r0   r'  pmContext.pmUseZoneZ  s*     !!),A:-r2   c                      [        5       n [        R                  [        U 5      5      nUS:  a  [	        U5      eU R
                  n[        UR                  5       5      $ )z-PMAPI - Query the current reporting timezone r   )r	   rP   pmWhichZoner   r4   r_   rR   rS   )tz_pr   r  s      r0   r+  pmContext.pmWhichZoneb  sJ     z##E$K0A:-ZZ299;r2   c                     [         R                  U R                  5      nUS:  a  [        U5      e[	        5       n[        [        U5      5      n[         R                  [        U5      [        U5      5        U$ )z;PMAPI - convert the date and time for a reporting timezone r   )	rP   ry  rc  r4   r   r   r   pmLocaltimer   r@   secondsr   rW   r   s        r0   r/  pmContext.pmLocaltimel  sY    $$TXX.A:-W&5=%-8r2   c                 :   [         R                  U R                  5      nUS:  a  [        U5      e[        R
                  " S5      n[        [        U5      5      n[         R                  [        U5      U5        [        UR                  R                  5       5      $ )z:PMAPI - format the date and time for a reporting timezone r   r   )rP   ry  rc  r4   r&   rN   r   r   r   r   rR   r_   rS   r0  s        r0   r   pmContext.pmCtimev  so    $$TXX.A:-,,R0W&uV}f-6<<&&())r2   c                    [        [        5      " 5       n[        R                  U R                  5      nUS:  a  [        U5      e[        R                  [        U5      U[        U5      5      nUS:  a  [        U5      eU$ )z[PMAPI - Fetch pmResult from the target source

pmResult* pmresult = pmFetch(c_uint pmid[])
r   )	r   re  rP   ry  rc  r4   pmFetchrU   r   r@   r  result_pr   s       r0   r6  pmContext.pmFetch  sf    
 8$&$$TXX.A:-E
E5?CA:-r2   c                    [        [        5      " 5       n[        R                  U R                  5      nUS:  a  [        U5      e[        R                  [        U5      U[        U5      5      nUS:  a  [        U5      eU$ )zpPMAPI - Fetch pmHighResResult from the target source

pmHighResResult* pmresult = pmFetchHighRes(c_uint pmid[])
r   	r   r  rP   ry  rc  r4   pmFetchHighResrU   r   r7  s       r0   r<  pmContext.pmFetchHighRes  h    
 ?+-$$TXX.A:-&&s5z5%/JA:-r2   c                    [        [        5      " 5       n[        R                  U R                  5      nUS:  a  [        U5      e[        R                  [        U5      U[        U5      5      nUS:  a  [        U5      eU$ )z}PMAPI - Fetch pmHighResResult from the target source (deprecated)

pmHighResResult* pmresult = pmHighResFetch(c_uint pmid[])
r   r;  r7  s       r0   pmHighResFetchpmContext.pmHighResFetch  r>  r2   c                 .    [         R                  U 5        g)zWPMAPI - Free a result previously allocated by pmFetch
pmFreeResult(pmResult* pmresult)
N)rP   pmFreeResultr8  s    r0   rC  pmContext.pmFreeResult  s    
 	H%r2   c                 .    [         R                  U 5        g)zePMAPI - Free a result previously allocated by pmFetch
pmFreeHighResResult(pmHighResResult* pmresult)
N)rP   pmFreeHighResResultrD  s    r0   rG  pmContext.pmFreeHighResResult  s    
 	""8,r2   c                     [        U5      /[        R                  l        [        R	                  U R
                  5      nUS:  a  [        U5      e[        R                  U5      nUS:  a  [        U5      eU$ )z_PMAPI - Set values on target source, inverse of pmFetch
pmresult = pmStore(pmResult* pmresult)
r   )r  rP   pmStorer+   ry  rc  r4   r@   rW   r   s      r0   rJ  pmContext.pmStore  s`     %)L"2$$TXX.A:-'A:-r2   c                     [        U5      /[        R                  l        [        R	                  U R
                  5      nUS:  a  [        U5      e[        R                  U5      nUS:  a  [        U5      eU$ )ztPMAPI - Set values on target source, inverse of pmFetchHighRes
pmresult = pmStoreHighRes(pmHighResResult* pmresult)
r   )r  rP   pmStoreHighResr+   ry  rc  r4   rK  s      r0   rN  pmContext.pmStoreHighRes  sd     ,0<)9&$$TXX.A:-&&v.A:-r2   c                     [        5       n[        R                  U R                  5      nUS:  a  [	        U5      e[        R                  [        U5      5      nUS:  a  [	        U5      eU$ )zMPMAPI - Get the label record from the archive
loglabel = pmGetArchiveLabel()
r   )r  rP   ry  rc  r4   pmGetArchiveLabelr   r@   loglabelr   s      r0   rQ  pmContext.pmGetArchiveLabel  sZ     <$$TXX.A:-))%/:A:-r2   c                     [        5       n[        R                  U R                  5      nUS:  a  [	        U5      e[        R                  [        U5      5      nUS:  a  [	        U5      eU$ )zTPMAPI - Get the label record from the archive
loglabel = pmGetHighResArchiveLabel()
r   )r  rP   ry  rc  r4   pmGetHighResArchiveLabelr   rR  s      r0   rV  "pmContext.pmGetHighResArchiveLabel  s[     %&$$TXX.A:-00xAA:-r2   c                     [        5       n[        R                  U R                  5      nUS:  a  [	        U5      e[        R                  [        U5      5      nUS:  a  [	        U5      eU$ zAPMAPI - Get the last recorded timestamp from the archive
        r   )r}   rP   ry  rc  r4   pmGetArchiveEndr   )r@   r   r   s      r0   rZ  pmContext.pmGetArchiveEnd  sZ     i$$TXX.A:-''c
3A:-
r2   c                     [        5       n[        R                  U R                  5      nUS:  a  [	        U5      e[        R                  [        U5      5      nUS:  a  [	        U5      eU$ rY  )r   rP   ry  rc  r4   pmGetHighResArchiveEndr   )r@   r=  r   s      r0   r]   pmContext.pmGetHighResArchiveEnd  sZ     z$$TXX.A:-..uT{;A:-r2   c                 <  ^^ [        [        5      " 5       m[        [        5      " 5       m[        R	                  U R
                  5      nUS:  a  [        U5      e[        U5      n[        R                  U[        T5      [        T5      5      nUS:  a  [        U5      eUS:  aq  [        [        U4S j[        U5      5      5      n[        [        U4S j[        U5      5      5      n[        R                  T5        [        R                  T5        XT4$ SnSnXT4$ )zPMAPI - Get the instance IDs and names for an instance domain

((instance1, instance2...) (name1, name2...)) pmGetInDom(pmDesc pmdesc)
r   c                 @   > [        TU    R                  SS5      5      $ r  rt  r  s    r0   r   -pmContext.pmGetInDomArchive.<locals>.<lambda>	  r  r2   c                     > [        TU    5      $ rd   r  r  s    r0   r   ra  	  r  r2   N)r   r   r	   rP   ry  rc  r4   r  pmGetInDomArchiver   r:   r  rT   r{  r|  )r@   r  r   r  r  r  r  r  s         @@r0   rc  pmContext.pmGetInDomArchive	  s    
 %."(#%$$TXX.A:-'"))%wwPA:-A:PRWX^R_`aE6fFGEIIgIIg | EE|r2   c                    [         R                  U R                  5      nUS:  a  [        U5      e[	        U[
        5      (       d  UR                  S5      n[         R                  [        U5      U5      nUS:  a  [        U5      eU$ )zPMAPI - Lookup the instance id with the given name in the indom

c_uint instid = pmLookupInDomArchive(pmDesc pmdesc, "Instance")
r   ru   )	rP   ry  rc  r4   r<   r   rw   pmLookupInDomArchiver  r  s       r0   rf  pmContext.pmLookupInDomArchive#	  sq    
 $$TXX.A:-$&&;;w'D,,Yv->EA:-r2   c                 d   [        5       n[        R                  U R                  5      nUS:  a  [	        U5      e[        U5      n[        R                  XR[        U5      5      nUS:  a  [	        U5      eUR                  n[        R                  U5        [        UR                  SS5      5      $ )zPMAPI - Lookup the text name of an instance in an instance domain

"string" = pmNameInDomArchive(pmDesc pmdesc, c_uint instid)
r   r  r  )r	   rP   ry  rc  r4   r  pmNameInDomArchiver   r_   r{  r|  rR   rS   )r@   r  rH  r  r   r  rW   s          r0   ri  pmContext.pmNameInDomArchive2	  s    
 $$TXX.A:-&!**5fFA:-		&6==(344r2   c                     [        [        5      " 5       n[        R                  U R                  5      nUS:  a  [        U5      e[        R                  [        U5      5      nUS:  a  [        U5      eU$ )z]PMAPI - Fetch raw measurements from the target source

pmResult* pmresult = pmFetchArchive()
r   )r   re  rP   ry  rc  r4   pmFetchArchiver   r@   r8  r   s      r0   rl  pmContext.pmFetchArchiveC	  s`    
 8$&$$TXX.A:-&&uX7A:-r2   c                     [        [        5      " 5       n[        R                  U R                  5      nUS:  a  [        U5      e[        R                  [        U5      5      nUS:  a  [        U5      eU$ )zkPMAPI - Fetch raw measurements from the target source

pmHighResResult* pmresult = pmFetchHighResArchive()
r   )r   r  rP   ry  rc  r4   pmFetchHighResArchiver   rm  s      r0   rp  pmContext.pmFetchHighResArchiveQ	  s`    
 ?+-$$TXX.A:---eHo>A:-r2   c                     0 nUbK  UR                   S:  a;  UR                  b.  [        R                  " UR                  R                  5       5      nU$ )zVreturn a dict of a pmLabelSet, i.e. {name: value, ...}
flags arg is currently ignored
r   )r  r  loadsrS   )r@   lsetr  rets       r0   pmlabelset_to_dictpmContext.pmlabelset_to_dict_	  sC     q 0TYY5J**TYY--/0C
r2   c                 :   0 n[         R                  U R                  5      nUS:  a  [        U5      eU R	                  U5      nU R                  5       nU(       a!  UR                  [        R                  U05        U R                  [         R                  U5      5      nU(       a!  UR                  [        R                  U05        UR                  [        R                  :w  aC  U R                  UR                  5      nU(       a!  UR                  [        R                  U05        U R!                  U5      nU(       a!  UR                  [        R"                  U05        U R%                  U5      nU(       a!  UR                  [        R&                  U05        U$ )zPMAPI - Get all labels for a single metric, excluding instance
level labels (use pmGetInstancesLabels for those).
Return dict of {type: {name: value, ...}, ...}
r   )rP   ry  rc  r4   r  pmGetContextLabelsr  rE   PM_LABEL_CONTEXTpmGetDomainLabelspmID_domainPM_LABEL_DOMAINr  PM_INDOM_NULLpmGetInDomLabelsPM_LABEL_INDOMpmGetClusterLabelsPM_LABEL_CLUSTERpmGetItemLabelsPM_LABEL_ITEM)r@   rN  ru  r   r  rt  s         r0   pmLookupLabelspmContext.pmLookupLabelsi	  s4   
 $$TXX.A:-  &&&(JJ..56%%f&8&8&>?JJ--t45::,,,((4D

E00$78&&t,JJ..56##D)JJ++T23
r2   c                 0   0 n[         R                  U R                  5      nUS:  a  [        U5      eU[        R
                  :X  a  U$ [        [        5      " 5       n[         R                  U[        U5      5      nUS:  a  [        U5      e[        U5       H_  nXE   nUR                  c  M  UR                  UR                  [        R                  " UR                  R                  5       5      05        Ma     US:  a  [         R!                  XC5        U$ )zmPMAPI - Get instance level labels for all instances in indom
return a dict {instid: {name: value, ...}, ...}
r   )rP   ry  rc  r4   rE   r~  r   r  pmGetInstancesLabelsr   rT   r  r  rH  rs  rS   pmFreeLabelSets)r@   r  instlabelsDr   r8  rV  rt  s          r0   r  pmContext.pmGetInstancesLabels	  s     $$TXX.A:-E''':&(,,UE(ODA:-vA;Dyy$""DIItzz$)):J:J:L/M#NO  A:""84r2   c                 J   [        [        5      " 5       n[        R                  U R                  5      nUS:  a  [        U5      e[        R                  U[        U5      5      nUS:  a  [        U5      eUS:X  a  0 $ U R                  US   5      nU R                  US5        U$ )zuPMAPI - Get labels of a given metric identifier
On success, this returns a dict of the labels in a single pmLabelSet
r   rM   )
r   r  rP   ry  rc  r4   r  r   rv  r  r@   rN  r8  r   ru  s        r0   r  pmContext.pmGetItemLabels	  s     :&($$TXX.A:-''eHo>A:-Q;I%%hqk2Xq)
r2   c                 J   [        [        5      " 5       n[        R                  U R                  5      nUS:  a  [        U5      e[        R                  U[        U5      5      nUS:  a  [        U5      eUS:X  a  0 $ U R                  US   5      nU R                  US5        U$ )zrPMAPI - Get labels of a given metric cluster
On success, this returns a dict of the labels in a single pmLabelSet
r   rM   )
r   r  rP   ry  rc  r4   r  r   rv  r  r  s        r0   r  pmContext.pmGetClusterLabels	  s     :&($$TXX.A:-**4xAA:-Q;I%%hqk2Xq)
r2   c                 v   0 n[        [        5      " 5       n[        R                  U R                  5      nUS:  a  [        U5      eU[        R                  :X  a  U$ [        R                  U[        U5      5      nUS:  a  [        U5      eUS:  a&  U R                  US   5      nU R                  US5        U$ )zsPMAPI - Get labels of a given instance domain
On success, this returns a dict of the labels in a single pmLabelSet
r   rM   )r   r  rP   ry  rc  r4   rE   r~  r  r   rv  r  )r@   r  indomLabelsDr8  r   s        r0   r  pmContext.pmGetInDomLabels	  s     :&($$TXX.A:-E'''((h@A:-A:228A;?L  1-r2   c                 J   [        [        5      " 5       n[        R                  U R                  5      nUS:  a  [        U5      e[        R                  U[        U5      5      nUS:  a  [        U5      eUS:X  a  0 $ U R                  US   5      nU R                  US5        U$ )zvPMAPI - Get labels of a given performance domain
On success, this returns a dict of the labels in a single pmLabelSet
r   rM   )
r   r  rP   ry  rc  r4   r{  r   rv  r  )r@   domainr8  r   ru  s        r0   r{  pmContext.pmGetDomainLabels	  s     :&($$TXX.A:-))&%/BA:-Q;I%%hqk2Xq)
r2   c                 H   [        [        5      " 5       n[        R                  U R                  5      nUS:  a  [        U5      e[        R                  [        U5      5      nUS:  a  [        U5      eUS:X  a  0 $ U R                  US   5      nU R                  US5        U$ )zoPMAPI - Get labels of the current context
On success, this returns a dict of the labels in a single pmLabelSet
r   rM   )
r   r  rP   ry  rc  r4   ry  r   rv  r  )r@   r8  r   ru  s       r0   ry  pmContext.pmGetContextLabels	  s     :&($$TXX.A:-**5?;A:-Q;I%%hqk2Xq)
r2   c                    [        U [        5      (       d  U /nOU n[        R                  " [        R
                  5      n[        [        U5      -  " 5       n[        U5       H!  u  pE[        UR                  S5      5      X4'   M#     [        R                  U[        U5      U[        U5      5      nUS:  a  [        U5      eUR                  n[        UR                  SS5      5      $ )z3PMAPI - Merges string labels into a string
        ru   r   r  r  )r<   r:   r&   rN   rE   PM_MAXLABELJSONLENr	   rU   r  rw   rP   pmMergeLabelsr4   r_   rR   rS   )r  labelsLr8  arg_arrrV  labelr   rW   s           r0   r  pmContext.pmMergeLabels	  s     &$''hGG..u/G/GHc'l*-!'*HA!%,,w"78GJ +%%gs7|&.H?A:-6==(344r2   c                    [         R                  " [        R                  5      nUc  S n[	        U5      nU c	  SUl        GO[        U [        5      (       d  U /nOI/ nU  HA  n[        U[        5      (       a  UR                  U5        M+  Uc  M0  UR                  U5        MC     [        [        5      [        U5      -  " 5       n[        U5       H)  u  p[        [        U	5      [        [        5      5      Xx'   M+     [        [!        U5      ["        5      n[$        R'                  U[        U5      U[        U5      XB5      n
U
S:  a  [)        U
5      eUR
                  n[+        UR-                  SS5      5      $ )zPMAPI - Merges list of pmLabelSets based on labelSets hierarchy into
a string. Each list element may also be either a list or None.
c                     grS  r   )r   yzs      r0   r   ,pmContext.pmMergeLabelSets.<locals>.<lambda>
  s    qr2   s   {}r   r  r  )r&   rN   rE   r  mergeLabelSetsCB_typer_   r<   r:   extendappendr   r  rU   r  r   r   r	   r
   rP   pmMergeLabelSetsr4   rR   rS   )	labelSetsr  argr8  cb_func
labelSetsLr   r  rV  labelsetr   rW   s               r0   r  pmContext.pmMergeLabelSets
  s1   
 ..u/G/GH(H'1"HNi..'[

"A!!T**"))!,"))!,	 # z*S_<?G(4!%/7:3FG
  5x}h/C,,Wc*ox-0]GJFzFm#6==(344r2   c                     [        U5       HF  n[        [        X   5      [        [        5      5      nU(       d  M0  [
        R                  US5        MH     g)zhPMAPI - Free the pmLabelSets memory. The labelsets argument is
an array of nsets pmLabelSet structures.
rM   N)rT   r   r   r   r  rP   r  )r  nsetsrV  r  s       r0   r  pmContext.pmFreeLabelSets2
  s?    
 uAuY\*GJ,?@Cs&&sA. r2   c                     [        U [        5      (       d  U R                  S5      n [        R	                  U 5      nUc  U$ [        UR                  5       5      $ )z@PMAPI - Return single value from environment or pcp config file ru   )r<   r   rw   rP   pmGetOptionalConfigrR   rS   )variablerW   s     r0   pmGetConfigpmContext.pmGetConfig<
  sJ     (E**w/H++H5>M6==?##r2   c                     [         R                  " [        R                  5      n[        R                  X[        R                  5      n[        UR                  5       5      $ )z4PMAPI - Convert an error code to a readable string  )r&   rN   rE   rO   rP   rQ   rR   rS   )r>   errstrrW   s      r0   pmErrStrpmContext.pmErrStrF
  sC     ,,U-B-BC""41F1FG6==?##r2   c                 ~    [        5       n[        R                  XU[        U5      U5      nUS:  a  [	        U5      eU$ )a'  PMAPI - 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   rP   pmExtractValuer   r4   )rP  rQ  intypeouttypeoutAtomr   s         r0   r  pmContext.pmExtractValueM
  s?     -&&vf',W~w@A:-r2   c           	      @   [        U[        5      (       a  [        5       nSUl        XEl        OUn[        5       n[        R                  U [        U5      [        X#   R                  R                  5      [        U5      [        U5      5      nUS:  a  [        U5      eU$ )zPMAPI - Convert a value to a different scale

pmAtomValue = pmConvScale(c_api.PM_TYPE_FLOAT, pmAtomValue,
                                    pmDesc*, 3, c_api.PM_SPACE_MBYTE)
rM   r   )r<   r=   r   r!  r$  r   rP   pmConvScaler   r_  r  r4   )inTypeinAtomr  
metric_idxoutUnitspmunitsr  r   s           r0   r  pmContext.pmConvScale]
  s     h$$iG G!)G-##FE&M$)$*:*C*C*I*I$J$)'NE'ND A:-r2   c                     [         R                  " S5      n[        R                  XS5      n[	        UR                  5       5      $ )z2PMAPI - Convert units struct to a readable string r4  r5  )r  r7  rW   s      r0   
pmUnitsStrpmContext.pmUnitsStrr
  s7     --b1$$UR86==?##r2   c                     [         R                  " S5      n[        R                  XS5      n[	        UR                  5       5      $ )z3PMAPI - Convert double value to fixed-width string r{   )r&   rN   rP   pmNumberStr_rrR   rS   )r_   numstrrW   s      r0   pmNumberStrpmContext.pmNumberStry
  s7     ,,Q/%%eQ76==?##r2   c                 2    [         R                  XU5      nU$ )z/PMAPI - build a pmID from domain, cluster, item)rP   
pmID_build)r   r   rV  rW   s       r0   r  pmContext.pmID_build
  s     ""1+r2   c                 0    [         R                  U 5      nU$ )z&PMAPI - return domain number from pmID)rP   r|  rN  rW   s     r0   r|  pmContext.pmID_domain
  s     ##D)r2   c                 0    [         R                  U 5      nU$ )z'PMAPI - return cluster number from pmID)rP   pmID_clusterr  s     r0   r  pmContext.pmID_cluster
  s     $$T*r2   c                 0    [         R                  U 5      nU$ )z$PMAPI - return item number from pmID)rP   	pmID_itemr  s     r0   r  pmContext.pmID_item
  s     !!$'r2   c                     [         R                  " S5      n[        R                  XS5      n[	        UR                  5       5      $ )z,PMAPI - Convert a pmID to a readable string r   )r&   rN   rP   	pmIDStr_rrR   rS   )rN  pmidstrrW   s      r0   pmIDStrpmContext.pmIDStr
  s7     --b1!!$46==?##r2   c                 0    [         R                  X5      nU$ )z-PMAPI - build an indom from domain and serial)rP   pmInDom_build)r   srW   s      r0   r  pmContext.pmInDom_build
  s     %%a+r2   c                 0    [         R                  U 5      nU$ )z'PMAPI - return domain number from indom)rP   pmInDom_domainr  rW   s     r0   r  pmContext.pmInDom_domain
       &&u-r2   c                 0    [         R                  U 5      nU$ )z'PMAPI - return serial number from indom)rP   pmInDom_serialr  s     r0   r  pmContext.pmInDom_serial
  r  r2   c                     [         R                  " S5      n[        R                  [	        U 5      US5      n[        UR                  5       5      $ )z`PMAPI - Convert an instance domain ID  to a readable string
"indom" = pmGetInDom(pmDesc pmdesc)
r   )r&   rN   rP   pmInDomStr_rr  rR   rS   )r  indomstrrW   s      r0   
pmInDomStrpmContext.pmInDomStr
  s>    
 ..r2$$Yw%72F6==?##r2   c                     [         R                  " S5      n[        R                  XS5      n[	        UR                  5       5      $ )zgPMAPI - Convert a performance metric type to a readable string
"type" = pmTypeStr(c_api.PM_TYPE_FLOAT)
r   )r&   rN   rP   pmTypeStr_rrR   rS   )r  typestrrW   s      r0   	pmTypeStrpmContext.pmTypeStr
  s7    
 --b1##EB76==?##r2   c                     [         R                  " S5      n[        R                  [	        U 5      XS5      n[        UR                  5       5      $ )z_PMAPI - Convert a value atom to a readable string
"value" = pmAtomStr(atom, c_api.PM_TYPE_U32)
`   )r&   rN   rP   pmAtomStr_rr   rR   rS   )atomr  atomstrrW   s       r0   	pmAtomStrpmContext.pmAtomStr
  s=    
 --b1##E$KD6==?##r2   c                     [         R                  " S5      n[        R                  XS5      n[	        UR                  5       5      $ )zmPMAPI - Convert a performance metric semantic to a readable string
"string" = pmSemStr(c_api.PM_SEM_COUNTER)
r   )r&   rN   rP   
pmSemStr_rrR   rS   )r  semstrrW   s      r0   pmSemStrpmContext.pmSemStr
  s7    
 ,,R0""336==?##r2   c           	      X   [         R                  [        U 5      [        UR                  R
                  U   R                  R                  5      [        UR                  R                  5      [        UR                  R
                  U   R                  R                  U   5      U5        g)zjPMAPI - Print the value of a metric
pmPrintValue(file, value, pmdesc, vset_index, vlist_index, min_width)
N)
rP   pmPrintValuer1   r   r_  rW  rP  r  r   rQ  )r/   rW   ptyperv  r  	min_widths         r0   r  pmContext.pmPrintValue
  sz    
 	M'2!&//"6"6x"@"I"I"P"PQ!%.."5"56!&//"6"6x"@"I"I"O"OPY"Z[%		'r2   c                  P    [         R                  5       n U S:  a  [        U 5      eU $ )z7PMAPI - flush the internal buffer shared with pmprintf r   )rP   pmflushr4   r  s    r0   r
  pmContext.pmflush
  s&     !A:-r2   c                 T    [         R                  " U /UQ76 nUS:  a  [        U5      eg)z=PMAPI - append message to internal buffer for later printing r   N)rP   rv   r4   )fmtr;   r   s      r0   rv   pmContext.pmprintf
  s-     ,t,A:- r2   c                 .    [         R                  U 5        g)zGPMAPI - sort all metric instances in result returned by pmFetchHighRes N)rP   pmSortHighResInstancesrD  s    r0   r   pmContext.pmSortHighResInstances
  s     	%%h/r2   c                 .    [         R                  U 5        g)z@PMAPI - sort all metric instances in result returned by pmFetch N)rP   pmSortInstancesrD  s    r0   r  pmContext.pmSortInstances
  s     	x(r2   c                 0    [         R                  U 5      S4$ )zzPMAPI - parse a textual time interval into a timespec struct
(timespec_ctype, '') = pmParseHighResInterval("time string")
rT  )r   r   r   s    r0   r    pmContext.pmParseHighResInterval
  s    
 %%h/44r2   c                 0    [         R                  U 5      S4$ )zqPMAPI - parse a textual time interval into a timeval struct
(timeval_ctype, '') = pmParseInterval("time string")
rT  )r}   r   r  s    r0   r   pmContext.pmParseInterval   s    
 $$X.33r2   c                 2    [         R                  XU5      S4$ )zyPMAPI - parse a textual metric specification into a struct
(result, '') = pmParseMetricSpec("hinv.ncpu", 0, "localhost")
rT  )r  r  )r  r  r  s      r0   r  pmContext.pmParseMetricSpec  s    
 ''?DDr2   c                    [        U [        [        45      (       d#  [        [        R
                  [        U 5      5      e[        U [        5      (       d  U R                  S5      n [        5       n[        5       n[        5       n[        R                  U [        U5      [        U5      [        U5      5      nUS:  aC  [        UR                  R                  5       5      n[         R#                  U5        [        XE5      eXR                  4$ r  )r<   r   	text_typer4   rE   r  rR   rw   r   r	   r   rP   pmParseUnitsStrr   r_   rS   r{  r|  )r  rW   r   
multiplierr   r  s         r0   r  pmContext.pmParseUnitsStr  s    &5)"455))3v;77&%((]]7+FZ
''fuZ?PRWX^R_`A:v||**,-DIIf%%(())r2   c                 "    U R                  5       $ )zDelay for a specified amount of time (timespec).
Useful for implementing tools that do metric sampling.
Single arg is timespec in tuple returned from pmParseHighResInterval().
r   )r=  s    r0   pmtimespecSleeppmContext.pmtimespecSleep  s     zz|r2   c                 "    U R                  5       $ )zDelay 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"  )r   s    r0   pmtimevalSleeppmContext.pmtimevalSleep&  s     yy{r2   c                  z    [        [        R                  " [        S5      R                  R                  5       5      $ r[   r]   r   r2   r0   r\   pmContext.pmProgname.  s'    8??6<8>>EEGHHr2   c                 `    [         R                  " [        S5      R                  U -  (       a  gg)NpmDebugTF)r   r^   rP   r_   )r  s    r0   r+  pmContext.pmDebug2  s!    <<	*0058r2   c                    US:  a  U(       a  SOSnOWU (       a1  U R                  5       n[        R                  " U5      R                  nO[        R                  " 5       R                  nU(       a  [        R                  O[        R
                  n[        R                  U   nU(       aP  [        US-  5      n[        US-  S-  5      nUS:  a  US-  nU[        U5      -  nU(       a  US[        U5      -   -  nU$ )z:Get current timezone offset string using POSIX convention r   rM         @i  <   +r  )	r  r   	localtimer   altzoner  tznamer=   rR   )rd  set_dstdstr   offsetr  	offset_hr
offset_mins           r0   get_current_tzpmContext.get_current_tz;  s     a<!AC++-C..%..C.."++C!$$--;;s#FVO,IVd]R/0J{CI&HC#j/11r2   c                     U (       a  SS Vs/ s H  oU ;   PM	     sn;  a  gSU ;   a  U R                  S5      S   OU R                  S5      S   nSU ;   a  SOSnSU-   [        U5      -   $ s  snf )zBConvert POSIX timezone offset string to human readable UTC offset T)r0  -zUTC+0r0  rM   r<  UTC)rl  rR   )r  r   r6  signs       r0   posix_tz_to_utc_offset pmContext.posix_tz_to_utc_offsetQ  sr     tz'Jz!Xz'JJ+.(?$Q's@STU@VXos3t|c&k))	 (Ks   A+c                 &   U R                  5       (       aZ  U R                  5       [        R                  S'   [        R                  " 5         [
        R                  U R                  5       5        gU R                  5       (       a;  [
        R                  5       [        R                  S'   [        R                  " 5         g[
        R                  U 5      nU[        R                  S'   [        R                  " 5         [
        R                  U5        g)zSet timezone for a Python tool TZN)
r  r,   environr   tzsetrG  r$  r  r+  r9  )rd  r  s     r0   set_timezonepmContext.set_timezoneZ  s     &&((&::<BJJtJJL ; ; =>((**(446BJJtJJL //8H'BJJtJJL)r2   c                    U [         R                  " S5      -
  nU[        R                  :X  a4  UR                  UR
                  UR                  S-  S-  -   S-  -   S-  nU$ U[        R                  :X  a4  UR                  UR
                  UR                  S-  S-  -   S-  -   S-  nU$ U[        R                  :X  a4  UR                  UR
                  UR                  S-  S-  -   S-  -   S-  nU$ U[        R                  :X  a4  UR                  UR
                  UR                  S-  S-  -   S-  -   S-  nU$ [        S5      e)z5Convert datetime value to seconds of given precision r   g      8@r.  g    .Ag     @@g      ?zUnsupported precision requested)r   fromtimestamprE   PM_TIME_SECmicrosecondsr1  daysPM_TIME_MSECPM_TIME_USECPM_TIME_NSEC
ValueError)r_   	precisiontdttsts       r0   datetime_to_secspmContext.datetime_to_secsj  sI    h,,Q//)))##s{{SXX_v5M'MQX&XX\ccC 
 %,,,##s{{SXX_v5M'MQX&XX\ccC 
 %,,,##s{{SXX_v5M'MQX&XX\__C
 
	 %,,,##s{{SXX_v5M'MQX&XX\ccC 
 >??r2   c                     U(       a  U (       a  [         R                  nSnX44$ [         R                  n[        UR                  UR
                  S-  5      nX44$ )z Get mode and step for pmSetMode N  )rE   PM_MODE_FORWr9  r   r   r   )r%  interpolr   rB  steps        r0   get_mode_steppmContext.get_mode_stepz  sS     7%%DD z ''DHOOX-=-=-DEDzr2   c                 4   [         R                  U R                  5      nUS:  a  [        U5      eU R	                  U5        U R
                  [        R                  :X  a9  [        R                  X#U5      u  pgU R                  XaR                  5       U5        gg)zCommon execution preparation r   N)rP   ry  rc  r4   rE  r  rE   r_  rG  rZ  r  r  )r@   rd  r%  rX  r   r   rB  rY  s           r0   prepare_executepmContext.prepare_execute  sy    $$TXX.A:-'"99000"00HMJD!!$(H(H(JDQ 1r2   rQ  rM  rI  )r   r   )r   r  )   )rM   r  )N)|rh   ri   rj   rk   r  rJ  rN  rR  r]  r  rX  rc  rE   r`  r9   r>  r   re  rE  rp  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  PM_TEXT_ONELINEr  r  r  r  r  r  rW  r[  r  ry  r  r  r  r  r  r  r  r!  r$  r'  r+  r/  r   r6  r<  r@  rC  rG  rJ  rN  rQ  rV  rZ  r]  rc  rf  ri  rl  rp  rv  r  r  r  r  r  r{  ry  r  r  r  r  r  r  r  r  r  r  r|  r  r  r  r  r  r  r  r  r  r  r  r
  rv   r  r  r   r   r  r  r#  r&  r\   r+  r9  r?  rE  rI  rS  rZ  r]  rl   r   r2   r0   rG  rG    s[   4 GT4.DitT2F
64t
,C
 #228 
-/ - -^ ( (\(0
!F$	 	  $   $> .3-B-B $" ',&;&; "$65*  2,$
$         * & & - -"

05" D.""&"( 5 5$  5  5D / / $ $ $ $    ( $ $ $ $  
  
  
  
 $ $  
  
  
 $ $ $ $ $ $ $ $ ' '       0 0 ) ) 5 5 4 4 E E * *     I I    * * * * * */*;*;    
Rr2   rG  c                      \ rS rSrSr " S S\5      r " S S\5      r " S S\5      r\r	 " S	 S
\5      r
 " S S\5      r " S S\5      r\R                  S4S jrS rS rSS jrSS jrS rS r\rSS jrS rS rSrg)
fetchgroupi  a  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                   $    \ rS rSrSrS rS rSrg)fetchgroup.fetchgroup_itemi  z
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.
c                 j    [        [        R                  5      U l        Xl        [        5       U l        gz8Allocate a single instance to receive a fetchgroup item.N)r   rE   PM_ERR_VALUEstspmtyper   r_   )r@   rk  s     r0   r9   #fetchgroup.fetchgroup_item.__init__  s"    U//0DH K$DJr2   c                     U R                   R                  S:  a  [        U R                   R                  5      eU R                  R                  U R                  5      $ )>Retrieve a converted value of a fetchgroup item, if available.r   )rj  r_   r4   r  rk  r`   s    r0   __call__#fetchgroup.fetchgroup_item.__call__  s<    xx~~!DHHNN++::??4;;//r2   )rk  rj  r_   Nrh   ri   rj   rk   r  r9   ro  rl   r   r2   r0   fetchgroup_itemrf    s    		'	0r2   rr  c                   $    \ rS rSrSrS rS rSrg)fetchgroup.fetchgroup_timespeci  z
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.
c                 .    [        5       U l        Xl        g)z<Allocate a single instance to receive a fetchgroup timespec.N)r   r_   rc  r@   rc  s     r0   r9   'fetchgroup.fetchgroup_timespec.__init__  s    !DJHr2   c           
      P   U R                   R                  U R                  R                  5      n[	        U R                  R
                  5      S-  n[        UR                  S-   UR                  S-   UR                  UR                  UR                  UR                  US5      nU$ )zm
Retrieve a converted value of a timespec, if available.  Use
pmLocaltime() to convert to a datetime object.
rV  r   rM   N)rc  r/  r_   r   r=   r   r   r   r   r   r   r   r   r@   r   usdts       r0   ro  'fetchgroup.fetchgroup_timespec.__call__  s|    
 %%djj&7&78BTZZ''(D0B"**T/299Q;

**biiBFBIr2   rc  r_   Nrq  r   r2   r0   fetchgroup_timespecrt        		
		r2   r~  c                   $    \ rS rSrSrS rS rSrg)fetchgroup.fetchgroup_timevali  z
An internal class to receive value for a single timeval.
It may be called as if it were a function object to decode
the timeval, which was set at the most recent
.fetch() call, into a datetime object.
c                 .    [        5       U l        Xl        g)z;Allocate a single instance to receive a fetchgroup timeval.N)r}   r_   rc  rv  s     r0   r9   &fetchgroup.fetchgroup_timeval.__init__  s     DJHr2   c           
      J   U R                   R                  U R                  R                  5      n[	        U R                  R
                  5      n[        UR                  S-   UR                  S-   UR                  UR                  UR                  UR                  US5      nU$ )zl
Retrieve a converted value of a timeval, if available.  Use
pmLocaltime() to convert to a datetime object.
r   rM   N)rc  r/  r_   r   r=   r   r   r   r   r   r   r   r   ry  s       r0   ro  &fetchgroup.fetchgroup_timeval.__call__   sw    
 %%djj&7&78BTZZ''(B"**T/299Q;

**biiBFBIr2   r}  Nrq  r   r2   r0   fetchgroup_timevalr    r  r2   r  c                   $    \ rS rSrSrS rS rSrg)fetchgroup.fetchgroup_indomi  a9  
An internal class to receive value/status for an indom of
items.  It may be called as if it were a function object to
create an list of tuples containing instance-code/-name/value
information.  Each value is a function object that decodes
the embedded pmAtomValue, which was set at the most recent
fetch() call.
c                     [         U-  n[        U-  n[        U-  n[        U-  n[        5       U l        U" 5       U l        Xl        U" 5       U l        U" 5       U l        U" 5       U l	        [        5       U l
        grh  )r   r   r   r	   rj  stssrk  valuesicodesinamesnum)r@   rk  r  stss_tvalues_ticodes_tinames_ts          r0   r9   $fetchgroup.fetchgroup_indom.__init__  sb    S[F"S(H|H#~HwDHDI K"*DK"*DK"*DKxDHr2   c                   ^ ^ / nT R                   R                  S:  a  [        T R                   R                  5      e[        T R                  R                  5       Hd  nS mUR                  T R                  U   T R                  U   (       a  T R                  U   R                  S5      OSUU 4S j" U5      45        Mf     U$ )rn  r   c                     U R                   U   S:  a  [        U R                   U   5      eU R                  U   R                  U R                  5      $ r7   r  r4   r  r  rk  r@   rV  s     r0   
decode_one8fetchgroup.fetchgroup_indom.__call__.<locals>.decode_one,  B    yy|a'#DIIaL11;;q>..t{{;;r2   ru   Nc                    >^  UU U4S j$ )Nc                     > T " TT5      $ rd   r   r  rV  r@   s   r0   r   Hfetchgroup.fetchgroup_indom.__call__.<locals>.<lambda>.<locals>.<lambda>4      z$/Br2   r   rV  r  r@   s   `r0   r   6fetchgroup.fetchgroup_indom.__call__.<locals>.<lambda>4      'Br2   )	rj  r_   r4   rT   r  r  r  r  rS   )r@   vvrV  r  s   `  @r0   ro  $fetchgroup.fetchgroup_indom.__call__&  s    Bxx~~!DHHNN++488>>*< 		4;;q>=A[[^4;;q>009QU DQG	I J + Ir2   )r  r  r  rk  rj  r  r  Nrq  r   r2   r0   fetchgroup_indomr    s    		 	r2   r  c                   $    \ rS rSrSrS rS rSrg)fetchgroup.fetchgroup_eventi8  a3  
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.
c                     [         U-  n[        U-  n[        U-  n[        5       U l        U" 5       U l        Xl        U" 5       U l        U" 5       U l        [        5       U l	        X0l
        grh  )r   r   r   rj  r  rk  timesr  r   r  rc  )r@   rk  r  rc  r  r  
timespec_ts          r0   r9   $fetchgroup.fetchgroup_event.__init__B  sU    S[F"S(H!CJwDHDI K#DJ"*DKxDHHr2   c                 d  ^ ^ / nT R                   R                  S:  a  [        T R                   R                  5      e[        T R                  R                  5       H  nS mT R
                  R                  T R                  U   R                  5      n[        T R                  U   R                  5      S-  n[        UR                  S-   UR                  S-   UR                  UR                  UR                   UR"                  US5      nUR%                  UUU 4S j" U5      45        M     U$ )rn  r   c                     U R                   U   S:  a  [        U R                   U   5      eU R                  U   R                  U R                  5      $ r7   r  r  s     r0   r  8fetchgroup.fetchgroup_event.__call__.<locals>.decode_oneV  r  r2   rV  r   rM   Nc                    >^  UU U4S j$ )Nc                     > T " TT5      $ rd   r   r  s   r0   r   Hfetchgroup.fetchgroup_event.__call__.<locals>.<lambda>.<locals>.<lambda>b  r  r2   r   r  s   `r0   r   6fetchgroup.fetchgroup_event.__call__.<locals>.<lambda>b  r  r2   )rj  r_   r4   rT   r  rc  r/  r  r   r=   r   r   r   r   r   r   r   r   r  )r@   r  rV  r   rz  r{  r  s   `     @r0   ro  $fetchgroup.fetchgroup_event.__call__O  s    Bxx~~!DHHNN++488>>*<
 XX))$**Q-*>*>?A../47bjjoryy{BJJ jj"))RYYDJ 		2CQGI J + Ir2   )rc  r  rk  rj  r  r  r  Nrq  r   r2   r0   fetchgroup_eventr  8  s    			r2   r  c                   $    \ rS rSrSrS rS rSrg)fetchgroup.pmContext_borrowedif  z
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.
c                 (    Xl         X l        X0l        g)z/Override pmContext ctor to eschew pmNewContext.N)rQ  rI  rM  )r@   rc  r  rX  s       r0   r9   &fetchgroup.pmContext_borrowed.__init__m  s     IJ!Lr2   c                 |    [         b5  U R                  [         R                  :w  a  [         R                  U l        ggg)z3Override pmContext ctor to eschew pmDestroyContext.N)rE   rQ  rV  r`   s    r0   r>  %fetchgroup.pmContext_borrowed.__del__u  s/     TYY%2H2H%H!22	 &I r2   r_  N)rh   ri   rj   rk   r  r9   r>  rl   r   r2   r0   pmContext_borrowedr  f  s    		"	3r2   r  rT  c                 d   [        5       U l        / U l        U[        R                  :X  a  Uc  Sn[
        R                  [        U R                  5      XR                  S5      5      nUS:  a  [        U5      e[        R                  [
        R                  U R                  5      X5      U l        g)z%Create a fetchgroup from a pmContext.NrT  ru   r   )r
   pmfgitemsrE   ra  rP   pmCreateFetchGroupr   rw   r4   rd  r  pmGetFetchGroupContextrc  )r@   r  rX  rj  s       r0   r9   fetchgroup.__init__z  s    J	
E***v~F''dii(8%wAWX7*001N1Ntyy1Y16@r2   c                     [         bG  U R                  R                  b0  [         R                  U R                  5      nUS:  a  [	        U5      eU R
                  SS2	 g)z?Destroy the fetchgroup.  Drop references to fetchgroup_* items.Nr   )rP   r  r_   pmDestroyFetchGroupr4   r  r@   rj  s     r0   r>  fetchgroup.__del__  sE    $))//"=,,TYY7CQwCj JJqMr2   c                     U R                   $ )z
Return the private pmContext used by the fetchgroup.
WARNING: mutation of this context by other PMAPI functions
may disrupt fetchgroup functionality.
)rc  r`   s    r0   get_contextfetchgroup.get_context  s     xxr2   Nc                    Uc  [        [        R                  * 5      eUcE  U R                  R	                  U5      nU R                  R                  U5      nUS   R                  n[        R                  U5      n[        R                  U R                  [        U(       a  UR                  S5      OS5      [        U(       a  UR                  S5      OS5      [        U(       a  UR                  S5      OS5      [        UR                  5      [!        U5      [        UR"                  5      5      nUS:  a  [        U5      eU R$                  R'                  U5        U$ )zExtend 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.
Nr   ru   )r4   re   EINVALrc  r  r  r  rd  rr  rP   pmExtendFetchGroup_itemr  r	   rw   r   r_   r   rj  r  r  )	r@   r  mtypescaleinstancer  r  vrj  s	            r0   extend_itemfetchgroup.extend_item  s     >&&=HH))&1EHH**51E!HMME&&u-,,TYYv}}W5TJ8xw7Nu||G44Hagg&eaeen& 7*

!r2   c                    Ub  US:  a  [        [        R                  * 5      eUcE  U R                  R	                  U5      nU R                  R                  U5      nUS   R                  n[        R                  X$5      n[        R                  U R                  [        U(       a  UR                  S5      OS5      [        U(       a  UR                  S5      OS5      [        [        UR                   5      [#        [$        5      5      [        [        UR&                  5      [#        [        5      5      [        [        UR(                  5      [#        [*        5      5      [%        U5      [        [        UR,                  5      [#        [$        5      5      [/        U5      [        UR0                  5      [        UR2                  5      5      nUS:  a  [        U5      eU R4                  R7                  U5        U$ )zExtend 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.
Nr   ru   )r4   re   r  rc  r  r  r  rd  r  rP   pmExtendFetchGroup_indomr  r	   rw   r   r   r  r   r   r  r  r   r  r   r  rj  r  r  )	r@   r  r  r  maxnumr  r  r  rj  s	            r0   extend_indomfetchgroup.extend_indom  sU    >VaZ&&=HH))&1EHH**51E!HMME((7--diiv}}W5TJu||G44H7299-wu~>7299-wx/@A7299-w{/CDEl7277+WU^<VngbffowrvvH 7*

"	r2   c                    [         R                  U R                  5      n[        R	                  U R
                  [        UR                  5      5      nUS:  a  [        U5      eU R                  R                  U5        U$ )z-Extend the fetchgroup with a timespec query. r   )rd  r~  rc  rP   pmExtendFetchGroup_timespecr  r   r_   r4   r  r  r@   r  rj  s      r0   extend_timespecfetchgroup.extend_timespec  s]    **488400GAGG<LM7*

!r2   c                    [         R                  U R                  5      n[        R	                  U R
                  [        UR                  5      5      nUS:  a  [        U5      eU R                  R                  U5        U$ )z,Extend the fetchgroup with a timeval query. r   )rd  r  rc  rP   pmExtendFetchGroup_timevalr  r   r_   r4   r  r  r  s      r0   extend_timevalfetchgroup.extend_timeval  s]    ))$((3//		7177;KL7*

!r2   c                 <   Ub  US:  a  [        [        R                  * 5      eUcE  U R                  R	                  U5      nU R                  R                  U5      nUS   R                  n[        R                  X6U R                  5      n	[        R                  U R                  [        U(       a  UR                  S5      OS5      [        U(       a  UR                  S5      OS5      [        U(       a  UR                  S5      OS5      [        U(       a  UR                  S5      OS5      [        [        U	R                   5      [#        [$        5      5      [        [        U	R&                  5      [#        [(        5      5      [+        U5      [        [        U	R,                  5      [#        [*        5      5      [/        U5      [        U	R0                  5      [        U	R2                  5      5      n
U
S:  a  [        U
5      eU R4                  R7                  U	5        U	$ )zExtend 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.
Nr   ru   )r4   re   r  rc  r  r  r  rd  r  rP   pmExtendFetchGroup_eventr  r	   rw   r   r   r  r   r   r  r   r   r  r   r  rj  r  r  )r@   r  fieldftyper  r  r  r  r  r  rj  s              r0   extend_eventfetchgroup.extend_event  sn    >VaZ&&=HH))%0EHH**51E!HMME((A--diiv}}W5TJ8xw7Nu||G44Hu||G44H7288,gh.?@7299-w{/CDEl7277+WU^<Vngbffowrvv	H 7*

"	r2   c                 f    [         R                  U R                  5      nUS:  a  [        U5      eU$ )z?Fetch all the metrics in this fetchgroup and update all values.r   )rP   pmFetchGroupr  r4   r  s     r0   fetchfetchgroup.fetch  s,    !!$)),7*
r2   c                     [         R                  U R                  5      nU R                  SS2	 US:  a  [	        U5      e/ U l        g)z>Clear all the metrics in this fetchgroup ready to start again.Nr   )rP   pmClearFetchGroupr  r  r4   r  s     r0   clearfetchgroup.clear  s9    &&tyy1JJqM7*
r2   )rc  r  r  )NNNN)NNNd   )NNNNNr  )rh   ri   rj   rk   r  objectrr  r~  r  fetchgroup_timestampr  r  rG  r  rE   r`  r9   r>  r  r  r  r  r  extend_timestampr  r  r  rl   r   r2   r0   rd  rd    s    0& 0(f 0V 2 .'6 'T+6 +\3Y 3( #228 
@68 &:r2   rd  )r  r,   r$   r   re   r  r   mathr   cpmapirE   r&   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ctypes.utilr   rP   platform	libc_namer{  r%   r=   r  r   rR   r  unicoder1   r  r4   rp   PM_SIZEOF_SUSECONDS_Tr   r  PM_SIZEOF_TIME_Tr   r}   r   r   r   r   r;  rA  rG  rM  rt  r]  rN  rO  rP  rQ  re  r  pmIDpmInDomr  	pmDescPtrr  r  r  r  r  r  r  r  r  
pmLabelPtrr  r  r  r_   r	  r  rz  r)   r+   r  r  r  r  r  r  traverseCB_typer  r  r  r  r  r  r  r  r  r  r  rW  r[  r  ry  r  r  r  r  r  r  r  r!  r$  r'  r+  r/  r   r6  r<  r@  rC  rG  rJ  rN  rQ  rZ  rV  r]  rc  rf  ri  rl  rp  r  rQ   r  r  r6  r  r  r|  r  r  r  r  r  r  r  r  r  r   r  r   r   r  r
  rv   r  r  r  r  r  r  r  r{  ry  r  r  r  r  r  r!  rG  r  r  r  r  r  r  r  r  r  r  rd  r   r2   r0   <module>r     s  Xx 
 
        D D J J = = : : $ 
l5!	"<<7*C	L#$ ;;#FMDI$LMI7 I B& &: 	!#M
  A%M
!!#@
AAQH
q H
!!#;
<<3 i 3 j3 y 3 j'3 '3R$% $L($i ($T*9 *	* 	*Mi M3 3< 
#7tTJ  ;T4N  ;T4N 94tL .8y .8`78i 78r 

6Y 
6 FO	14tD	3T4F	5tT4H	5tT4H	 9 @% % +	 +*8i 8 W
4dD$G
:D$M
 6dDI
 6dDI
 <dD$O
 " ".  %   !)7783D+E F   %*   "ggh'(''%.*A'C   # $)    $&   !!&   #+*   #    %1wvG       "GGH,=$>?    !78#45 D(+ %   "*O!<   #(    $&   !).   &+3Xwx?P*Q   '%*   "'/j   # $    &8   $   !& I   #(    %+UGH4E$F   !#    &wx/@A    "   
GGEN#WWX->%?A     %   !' 2   "   %vwx/@A    $    %x0   "'   $)7    #   !   #    %w    %   !#   #    &wu~>   #    &wu~>       "GG$4e<   "'   $)78+<gh>O#P    $)   !&+W   "(0   %*/5)A   & #(   #%        %J       "G   "   &x01   $R[   &v<   ! "6?H5    '&/778;L3MN  %   "'''/BZ:[!\    %   "'''/BZ:[!\   "    ' 12   %)   "'.'?&@   # "8,-  %   ")/":!;    $)    %,Z%8$9   !!&   #*7#3"4   */   ',34E,F+G   ((-   %*1(*;)<   &#(    %+WWU^-D%,WX->%?%A   ! ',   #!' 2   (/':   $$)   !&-u%5   " %   ")'(*;"<!=   ',   $)01I)J(K   % &.   "'/j   #$   #Xu5    %   	77UGK$8%"A    #   	7;!17;3GG    '    ' 0(EB   '   !)8U ;   "   $ff5   #   %h   $    &x   !   #H   #   #Xu5   %   !' 0    &   "(    &   "(   &    &%8   %   $h6   %   &{3UHeL   $   #Xu5   "    (%8H%P   (-   %*2GH4E*1(*;*=   & "'   #+WW-=#*8#4#6    $)    %-uh%,W\-B%C%,X%6%8   !    $: (,   %*1/*B)C   &!%   #*8#4"5    %   "'1D)E!F   &+   #(-wwz7J/K'L   $!&   #(''*2E*F"G   $)   !&+WWZ5H-I%J   ""'   $)77:3F+G#H    #(    %*GGJ4G,H$I   !$)   !&-gj.A&B%C   "$   !(!2E8U K   !%)98XN "'   $+GJ,?$@%$,e5J$,$.     "&   #*:#6">   X, X,DjR jR\/ %*   !&-h&7%I   "(-   %*2   &#(    %-J   !%*   "'/j   #).   &+3Xx+2;+?PU+X   '*/   ',4h,3EN,3H,=,3K,@,1,3EN,2,3FO,3EN,<   ( +0   ',4h(T\,3H,=,3K,@,1,3EN,2,3FO,3EN,<   ( -2 ! ! ).68H-I ! ! *-2 " " */79J.K " " +#    (z   S Sr2   