????

Your IP : 3.19.70.25


Current Path : /lib64/python3.6/site-packages/pcp/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/pcp/__pycache__/mmv.cpython-36.opt-1.pyc

3

4>�f_A�@s\dZddlmZmZddlmZddlZddlmZmZddlm	Z	m
Z
mZmZm
Z
mZmZejejjd��ZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�Zeej_e
e	e	ee�e	ee�e	gej_dej_e
egej_ee�ej_ee
e
gej_dej_eee�egej_dej_eee�ee�gej_dej_eee�egej_dej_eee�ee�gej_dej _eee�e
e	gej _dej!_ee
e
egej!_dej"_ee
e
gej"_dej#_ee
e
egej#_dej$_ee
e
e
egej$_dej%_ee
e
e
gej%_ee�ej&_eee�e
e
gej&_dej'_eee�gej'_dej(_ee
e
e
egej(_Gdd�de)�Z*dS)a�
Wrapper module for libpcp_mmv - PCP Memory Mapped Values library
#
# Copyright (C) 2013-2016,2019 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 instrumenting a python application:

        from pcp import mmv, pmapi
        import cpmapi as pcpapi
        import cmmv as mmvapi

        instances = [
                mmv.mmv_instance(0, "Anvils"),
                mmv.mmv_instance(1, "Rockets"),
                mmv.mmv_instance(2, "Giant_Rubber_Bands")
        ]
        ACME_PRODUCTS_INDOM = 61
        indoms = [
                mmv.mmv_indom(
                    serial = ACME_PRODUCTS_INDOM,
                    shorttext = "Acme products",
                    helptext = "Most popular products produced by the Acme Corporation")
        ]
        indoms[0].set_instances(instances)

        metrics = [
                mmv.mmv_metric(
                    name = "products.count",
                    item = 7,
                    typeof = mmvapi.MMV_TYPE_U64,
                    semantics = mmvapi.MMV_SEM_COUNTER,
                    dimension = pmapi.pmUnits(0,0,1,0,0,pcpapi.PM_COUNT_ONE),
                    indom = ACME_PRODUCTS_INDOM,
                    shorttext = "Acme factory product throughput",
                    helptext =
        "Monotonic increasing counter of products produced in the Acme Corporation
" +
        "factory since starting the Acme production application.  Quality guaranteed."),

                mmv.mmv_metric(
                    name = "products.time",
                    item = 8,
                    typeof = mmvapi.MMV_TYPE_U64,
                    semantics = mmvapi.MMV_SEM_COUNTER,
                    dimension = pmapi.pmUnits(0,1,0,0,pcpapi.PM_TIME_USEC,0),
                    indom = ACME_PRODUCTS_INDOM,
                    shorttext = "Machine time spent producing Acme products")
        ]

        values = mmv.MemoryMappedValues("acme")
        values.add_indoms(indoms)
        values.add_metrics(metrics)

        values.start()
        anvils = values.lookup_mapping("products.count", "Anvils")
        values.set(anvils, 41)
        values.inc(anvils)
        values.stop()
�)�pmUnits�pmAtomValue)�MMV_NAMEMAXN)�	Structure�POINTER)�c_int�c_uint�c_long�c_char�c_char_p�c_double�c_void_pZpcp_mmvc@s,eZdZdZdefdeefgZdd�ZdS)�mmv_instancezX Maps internal to external instance identifiers, within an
        instance domain.
    �internal�externalcCs.tj|�t|t�s|jd�}||_||_dS)Nzutf-8)r�__init__�
isinstance�bytes�encoderr)�self�inst�name�r�/usr/lib64/python3.6/mmv.pyrcs



zmmv_instance.__init__N)	�__name__�
__module__�__qualname__�__doc__rr
r�_fields_rrrrrr\src@sHeZdZdZdefdefdee�fdefdefgZd
dd	�Z	d
d�Z
dS)�	mmv_indomz� Represents an instance domain (for set valued metrics)
        Instance domains have associated instances - integer/string pairs.
        Defines complete indom metadata (instances, count, text and so on)
    �serial�count�	instances�	shorttext�helptext�cCs\tj|�|dk	r(t|t�r(|jd�}|dk	rFt|t�rF|jd�}||_||_||_dS)Nzutf-8)rrrrrr#r$r )rr r#r$rrrrus


zmmv_indom.__init__cCsTt|�|_t|j�}x2t|j�D]$}||j||_||j||_q"W||_dS)z7 Update the instances and counts fields for this indom N)�lenr!r�rangerrr")rr"Zinstance_array�irrr�
set_instancess
zmmv_indom.set_instancesN)r%r%)rrrrrrrrrrr)rrrrrjs



rc	@sReZdZdZdeefdefdefdefdefdefde	fd	e	fgZ
ddd
�ZdS)�
mmv_metricz� Represents an individual metric to be exported by pmdammv
        Defines complete metric metadata (type, semantics, units and so on)
    r�item�typeof�	semantics�	dimension�indomr#r$rr%c		Cs�tj|�t|t�s|jd�}|dk	r<t|t�r<|jd�}|dk	rZt|t�rZ|jd�}||_||_||_||_||_	||_
dS)Nzutf-8)rrrrrr#r$r,r/r+r)	rrr+r,r-r.r/r#r$rrrr�s




zmmv_metric.__init__N)rr%r%)rrrrr
rrrrrrrrrrrr*�s

r*c@s�eZdZdZd3dd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2S)4�MemoryMappedValuesz� Defines a set of PCP Memory Mapped Value (MMV) metrics

        Creates PCP metrics from an instrumented python script
        via pmdammv (Performance Metrics Domain Agent for MMV)
    r�*cCs<t|t�s|jd�}||_||_||_g|_g|_d|_dS)Nzutf-8)	rrr�_name�_cluster�_flags�_metrics�_indoms�_handle)rr�flagsZclusterrrrr�s

zMemoryMappedValues.__init__cCs�t|j�}t|�}xt|�D]}|j|||<qWt|j�}t|�}xt|�D]}|j|||<qRWtj|j|j	|j
||||�|_dS)z� Initialise the underlying library with metrics/instances.
            On completion of this call, we're all visible to pmdammv.
        N)r&r5r*r'r6r�
LIBPCP_MMV�mmv_stats_initr2r3r4r7)rZ
count_metrics�metricsr(Zcount_indoms�indomsrrr�start�s



zMemoryMappedValues.startcCs$|jdk	rtj|j|j�d|_dS)z� Shut down the underlying library with metrics/instances.
            This closes the mmap file preventing any further updates.
        N)r7r9�mmv_stats_stopr2)rrrr�stops
zMemoryMappedValues.stopcCs|j�|j�dS)z: Cleanly stop-if-running and restart MMV export services. N)r?r=)rrrr�restartszMemoryMappedValues.restartcCs|jdkrdSdS)z, Property flagging an active memory mapping Nr�)r7)rrrr�starteds
zMemoryMappedValues.startedcCs||_|j�r|j�dS)z; Make a list of instance domains visible to the MMV export N)r6rBr@)rr<rrr�
add_indomsszMemoryMappedValues.add_indomscCs|jj|�|j|j�dS)z> Make an additional instance domain visible to the MMV export N)r6�appendrC)rr/rrr�	add_indom szMemoryMappedValues.add_indomcCs||_|j�r|j�dS)z2 Make a list of metrics visible to the MMV export N)r5rBr@)rr;rrr�add_metrics%szMemoryMappedValues.add_metricscCs|jj|�|j|j�dS)z5 Make an additional metric visible to the MMV export N)r5rDrF)rZmetricrrr�
add_metric+szMemoryMappedValues.add_metriccCsL|dk	rt|t�r|jd�}|dk	r<t|t�r<|jd�}tj|j||�S)a� Find the memory mapping for a given metric name and instance

            This handle can be used to directly manipulate metric values
            by other interfaces in this module.  This is the *preferred*
            technique for manipulating MMV values.  It is more efficient
            and the alternative (name/inst lookups) is made available as
            a convenience only for situations where performance will not
            be affected by repeated (linear) name/inst lookups.
        Nzutf-8)rrrr9�mmv_lookup_value_descr7)rrrrrr�lookup_mapping1s



z!MemoryMappedValues.lookup_mappingcCstj|j||�dS)z. Increment the mapped metric by a given value N)r9�
mmv_inc_valuer7)r�mapping�valuerrr�addAszMemoryMappedValues.addcCstj|j|d�dS)z$ Increment the mapped metric by one rAN)r9rJr7)rrKrrr�incEszMemoryMappedValues.inccCstj|j||�dS)z( Set the mapped metric to a given value N)r9�
mmv_set_valuer7)rrKrLrrr�setIszMemoryMappedValues.setcCs8|dk	rt|t�r|jd�}tj|j||t|��dS)z/ Set the string mapped metric to a given value Nzutf-8)rrrr9�mmv_set_stringr7r&)rrKrLrrr�
set_stringMs
zMemoryMappedValues.set_stringcCstj|j|dd�S)z� Start a timed interval for the mapped metric
            The opaque handle (mapping) returned is passed to interval_end().
        r)r9�mmv_stats_interval_startr7)rrKrrr�interval_startSsz!MemoryMappedValues.interval_startcCstj|j|�S)zA End a timed interval, the metrics time is increased by interval )r9�mmv_stats_interval_endr7)rrKrrr�interval_endYszMemoryMappedValues.interval_endcCsR|dk	rt|t�r|jd�}|dk	r<t|t�r<|jd�}tj|j|||�dS)z9 Lookup the named metric[instance] and add a value to it Nzutf-8)rrrr9�
mmv_stats_addr7)rrrrLrrr�
lookup_add^s


zMemoryMappedValues.lookup_addcCsP|dk	rt|t�r|jd�}|dk	r<t|t�r<|jd�}tj|j||�dS)z5 Lookup the named metric[instance] and add one to it Nzutf-8)rrrr9�
mmv_stats_incr7)rrrrrr�
lookup_incfs


zMemoryMappedValues.lookup_inccCsR|dk	rt|t�r|jd�}|dk	r<t|t�r<|jd�}tj|j|||�dS)z5 Lookup the named metric[instance] and set its value Nzutf-8)rrrr9�
mmv_stats_setr7)rrrrLrrr�
lookup_setns


zMemoryMappedValues.lookup_setcCsN|dk	rt|t�r|jd�}|dk	r<t|t�r<|jd�}tj|jd||�S)z� Lookup the named metric[instance] and start an interval
            The opaque handle returned is passed to interval_end().
        Nzutf-8)rrrr9rSr7)rrrrrr�lookup_interval_startvs

z(MemoryMappedValues.lookup_interval_startcCsl|dk	rt|t�r|jd�}|dk	r<t|t�r<|jd�}t|t�sP|jd�}tj|j|||t|��dS)z< Lookup the named metric[instance] and set its string value Nzutf-8)rrrr9�mmv_stats_set_strlenr7r&)rrr�srrr�lookup_set_string�s



z$MemoryMappedValues.lookup_set_stringcCsT|dk	rt|t�r|jd�}|dk	r<t|t�r<|jd�}tj|j||||�dS)a Lookup the named metric[instance] and set its value if found
            If instance is not found, fallback to using a second instance
            One example use is: add value to bucketN else use a catch-all
                                bucket such as "other"
        Nzutf-8)rrrr9�mmv_stats_add_fallbackr7)rrrZfallrLrrr�lookup_add_fallback�s


z&MemoryMappedValues.lookup_add_fallbackcCsR|dk	rt|t�r|jd�}|dk	r<t|t�r<|jd�}tj|j|||�dS)z� Lookup the named metric[instance] and increment its value if found
            If instance is not found, fallback to using a second instance
            One sample use is: inc value of BucketA, else inc a catch-all
        Nzutf-8)rrrr9�mmv_stats_inc_fallbackr7)rrrZfallbackrrr�lookup_inc_fallback�s


z&MemoryMappedValues.lookup_inc_fallbackN)rr1)rrrrrr=r?r@rBrCrErFrGrIrMrNrPrRrTrVrXrZr\r]r`rbrdrrrrr0�s0


r0)+rZ	pcp.pmapirrZcmmvrZctypesrrrrr	r
rrr
ZCDLL�utilZfind_libraryr9rrr*r:ZrestypeZargtypesr>rHrJZmmv_inc_atomvaluerOZmmv_set_atomvaluerQrWrYr[rarcrSrUr^�objectr0rrrr�<module>GsV$