????
Your IP : 3.138.200.26
3
4>�f�5�@s<dZddlmZmZmZmZddlmZmZddl Z ddl m
Z
mZmZm
Z
mZe je jjd��Zdej_dej_eej_eeegej_eej_eegej_eej_eegej_eej_eeeeeegej_e
ej_ee
egej_eej_e
egej_eej_egej_eej_dej_eej_e
gej_eej_e
gej_eej _e
eeeeegej _eej!_ee
egej!_eej"_e
e
e
gej"_eej#_e
e
gej#_eej$_ee
gej$_eej%_eegej%_eej&_ee�gej&_eej'_dej'_eej(_eeee
gej(_eej)_eeee
e
gej)_Gdd�de*�Z+Gd d
�d
e,�Z-dS)a�Wrapper module for libpcp_import - Performace Co-Pilot Log Import API
#
# Copyright (C) 2012-2021 Red Hat.
#
# 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.
#
# Example use of this module for creating a PCP archive:
import math
import time
import pmapi
from pcp import pmi
# Create a new archive
log = pmi.pmiLogImport("loadtest")
log.pmiSetHostname("www.abc.com")
log.pmiSetTimezone("EST-10")
# Add a metric with an instance domain
domain = 60 # Linux kernel
pmid = log.pmiID(domain, 2, 0)
indom = log.pmiInDom(domain, 2)
units = log.pmiUnits(0, 0, 0, 0, 0, 0)
log.pmiAddMetric("kernel.all.load", pmid, pmapi.PM_TYPE_FLOAT,
indom, pmapi.PM_SEM_INSTANT, units)
log.pmiAddInstance(indom, "1 minute", 1)
log.pmiAddInstance(indom, "5 minute", 5)
log.pmiAddInstance(indom, "15 minute", 15)
# Create a record with a timestamp
log.pmiPutValue("kernel.all.load", "1 minute", "%f" % 0.01)
log.pmiPutValue("kernel.all.load", "5 minute", "%f" % 0.05)
log.pmiPutValue("kernel.all.load", "15 minute", "%f" % 0.15)
timetuple = math.modf(time.time())
useconds = int(timetuple[0] * 1000000)
seconds = int(timetuple[1])
log.pmiWrite(seconds, useconds)
del log
�)�pmID�pmInDom�pmUnits�pmResult)�
pmiErrSymDict�PMI_MAXERRMSGLENN)�cast�c_int�c_uint�c_char_p�POINTERZ
pcp_importcs0eZdZdZ�fdd�Zdd�Zdd�Z�ZS)�pmiErrz4
Encapsulation for PMI interface error code
csBtt|�j|�t|�|_|r8t|dt�r8|d|_nd|_dS)Nr)�superr
�__init__�list�args�
isinstance�int�code)�selfr)� __class__��/usr/lib64/python3.6/pmi.pyr�s
zpmiErr.__init__cCsRy(t|j}tjt�}tj|j|t�}Wntk
rDd}}YnXd||fS)N�z%s %s)rr�ctypesZcreate_string_bufferr�
LIBPCP_IMPORT�pmiErrStr_r�KeyError)rZerror_symbolZerror_stringrrr�__str__�s
zpmiErr.__str__cCs|jS)N)r)rrrr�errno�szpmiErr.errno)�__name__�
__module__�__qualname__�__doc__rrr�
__classcell__rr)rrr
�s
r
c@s�eZdZdZdd�Zdd�Zeeddd�Zeeddd�Zd0dd �Z d
d�Z
dd
�Zdd�Ze
dd��Ze
dd��Ze
dd��Ze
dd��Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Ze
d,d-��Zd.d/�ZdS)1�pmiLogImportzqDefines a PCP Log Import archive context
This is used to create a PCP archive from an external source
cCs|jS)z Property for archive path )�_path)rrrr� read_path�szpmiLogImport.read_pathcCs|jS)z! Property for log import context )�_ctx)rrrr�read_ctx�szpmiLogImport.read_ctxNrcCsDt|t�s|jd�}||_tjt|�|�|_|jdkr@t|j��dS)Nzutf-8r) r�bytes�encoder&r�pmiStartrr(r
)r�pathZinheritrrrr�s
zpmiLogImport.__init__cCs"trtj|j�tj�d|_dS)N����)r�
pmiUseContextr(�pmiEnd)rrrr�__del__�szpmiLogImport.__del__cCsRtj|j�}|dkrt|��t|t�s0|jd�}tjt|��}|dkrNt|��|S)z8PMI - set the source host name for a Log Import archive rzutf-8) rr0r(r
rr*r+�pmiSetHostnamer)rZhostname�statusrrrr3�s
zpmiLogImport.pmiSetHostnamecCsRtj|j�}|dkrt|��t|t�s0|jd�}tjt|��}|dkrNt|��|S)z?PMI - set the source timezone for a Log Import archive
rzutf-8) rr0r(r
rr*r+�pmiSetTimezoner)rZtimezoner4rrrr5�s
zpmiLogImport.pmiSetTimezonecCstj|||�S)z7PMI - construct a pmID data structure (helper routine) )r�pmiID)�domain�cluster�itemrrrr6�szpmiLogImport.pmiIDcCstj||�S)z7PMI - construct a pmID data structure (helper routine) )r�
pmiCluster)r7r8rrrr:�szpmiLogImport.pmiClustercCstj||�S)z:PMI - construct a pmInDom data structure (helper routine) )r�pmiInDom)r7�serialrrrr;�szpmiLogImport.pmiInDomcCstj||||||�S)z;PMI - construct a pmiUnits data structure (helper routine) )r�pmiUnits)Z dim_spaceZdim_timeZ dim_countZscale_spaceZ
scale_timeZscale_countrrrr=�s
zpmiLogImport.pmiUnitscCs\tj|j�}|dkrt|��t|t�s0|jd�}tjt|�|||||�}|dkrXt|��|S)z:PMI - add a new metric definition to a Log Import context rzutf-8) rr0r(r
rr*r+�pmiAddMetricr)r�nameZpmid�typed�indomZsemZunitsr4rrrr>s
zpmiLogImport.pmiAddMetriccCsVtj|j�}|dkrt|��t|t�s0|jd�}tj|t|�|�}|dkrRt|��|S)z@PMI - add element to an instance domain in a Log Import context rzutf-8) rr0r(r
rr*r+�pmiAddInstancer)rrA�instanceZinstidr4rrrrBs
zpmiLogImport.pmiAddInstancecCs�tj|j�}|dkrt|��t|t�s0|jd�}d}|dk rXt|t�sP|jd�}t|�}t|t�sl|jd�}tjt|�|t|��}|dkr�t|��|S)z-PMI - add a value for a metric-instance pair rzutf-8N) rr0r(r
rr*r+r�pmiPutValue)rr?�inst�valuer4rCrrrrDs"
zpmiLogImport.pmiPutValuecCs|tj|j�}|dkrt|��t|t�s0|jd�}d}|dk rXt|t�sP|jd�}t|�}tjt|�|�}|dkrxt|��|S)z1PMI - define a handle for a metric-instance pair rzutf-8N) rr0r(r
rr*r+r�pmiGetHandle)rr?rEr4rCrrrrG.s
zpmiLogImport.pmiGetHandlecCsTtj|j�}|dkrt|��t|t�s0|jd�}tj|t|��}|dkrPt|��|S)z:PMI - add a value for a metric-instance pair via a handle rzutf-8) rr0r(r
rr*r+�pmiPutValueHandler)rZhandlerFr4rrrrH?s
zpmiLogImport.pmiPutValueHandlecCs<tj|j�}|dkrt|��tj||�}|dkr8t|��|S)z)PMI - flush data to a Log Import archive r)rr0r(r
�pmiWrite)rZsecZusecr4rrrrIKszpmiLogImport.pmiWritecCs8tj|j�}|dkrt|��tj�}|dkr4t|��|S)z4PMI - write a <mark> record to a Log Import archive r)rr0r(r
�
pmiPutMark)rr4rrrrJUszpmiLogImport.pmiPutMarkcCsDtj|j�}|dkrt|��tjt|tt���}|dkr@t|��|S)z0PMI - add a data record to a Log Import archive r)rr0r(r
�pmiPutResultrrr)r�resultr4rrr�
put_result_szpmiLogImport.put_resultcCsXtj|j�}|dkrt|��t|t�s0|jd�}tj|||t|��}|dkrTt|��|S)z0PMI - add a text record to a Log Import archive rzutf-8) rr0r(r
rr*r+�
pmiPutTextr)r�typ�cls�ident�contentr4rrrrNis
zpmiLogImport.pmiPutTextcCsrtj|j�}|dkrt|��t|t�s0|jd�}t|t�sD|jd�}tj|||t|�t|��}|dkrnt|��|S)z1PMI - add a label record to a Log Import archive rzutf-8) rr0r(r
rr*r+�pmiPutLabelr)rrOrQrEr?rRr4rrrrSus
zpmiLogImport.pmiPutLabelcCstj�dS)z8PMI - dump the current Log Import contexts (diagnostic) N)r�pmiDumprrrrrT�szpmiLogImport.pmiDumpcCs>tj|j�}|dkrt|��tj�}d|_|dkr:t|��|S)z<PMI - close current context and finish a Log Import archive rr.r/)rr0r(r
r1)rr4rrrr1�szpmiLogImport.pmiEnd)r)r r!r"r#r'r)�propertyr-Zctxrr2r3r5�staticmethodr6r:r;r=r>rBrDrGrHrIrJrMrNrSrTr1rrrrr%�s2
r%).r#Z pcp.pmapirrrrZcpmirrrrr r
rrZCDLL�utilZfind_libraryrrTZrestypeZargtypesr6r:r;r=rr,r0r1r3r5r>rBrDrGrHrIrKrJrNrS� Exceptionr
�objectr%rrrr�<module>3sd