Sindbad~EG File Manager

Current Path : /lib/python3.6/site-packages/vdo/statistics/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/vdo/statistics/__pycache__/StatStruct.cpython-36.pyc

3

x?ag�(�@s�dZddlmZddlmZddlmZddlmZddlTddlZddlZddl	Z	ddl
Z
dd	lmZdd
lmZGdd�de
�ZGd
d�de
�ZGdd�de�ZdS)z�
  StatStruct -- classes for sampling statistics from a VDO via ioctls

  $Id: //eng/vdo-releases/aluminum/src/python/vdo/statistics/StatStruct.py#1 $
�)�absolute_import)�division)�print_function)�unicode_literals)�*N�)�Field)�LabeledValuec@sPeZdZdZdd�Zdd�Zdd�Zedd	d
��Zeddd��Z	ed
d��Z
dS)�SampleszD
  An object which represents a collection of samples from a VDO.
  cs"�d|_�fdd�|D�|_dS)a�
    Create a new set of samples by sampling a VDO device.

    :param assays:    The types of samples to take
    :param devices:   The device to sample (a dictionary containing
                      the user-supplied name and the name to use for sampling)
    :param mustBeVDO: If set to False, errors resulting from the device not
                      being a VDO will be suppressed
    �usercs"g|]}|jtjj�d���qS)�sample)r�os�path�basename)�.0�assay)�device�� /usr/lib/python3.6/StatStruct.py�
<listcomp>6sz$Samples.__init__.<locals>.<listcomp>N)r�samples)�self�assaysr�	mustBeVDOr)rr�__init__+s


zSamples.__init__cCs|jS)z\
    Get the name of the device which was sampled.

    :return: The name of the device
    )r)rrrr�	getDevice9szSamples.getDevicecCs|jS)zS
    Get the list of samples for the device.

    :return: The list of samples
    )r)rrrr�
getSamplesAszSamples.getSamplesTcCslyt|||�Stk
rf}z>|d}|jdkrF|rBtdj|���dStdj||���WYdd}~XnXdS)a�
    Assay a device.

    :param assays:    The types of samples to take
    :param devices:   The device to sample (a dictionary containing
                      the user-supplied name and the name to use for sampling)
    :param mustBeVDO: If set to False, errors resulting from the device not
                      being a VDO will be suppressed

    :return: The results of the assays or None if the device is not a VDO and
             mustBeVDO is set to False
    r�zDevice {0} is not a VDONzError sampling device {0}: {1})r
�IOError�errno�	Exception�format)rrrZioerrrrrIs
z
Samples.assaycstd��fdd�|D��S)a�
    Assay a list of devices.

    :param assays:    The types of samples to take
    :param devices:   The devices to sample (a list of dictionaries containing
                      the user-supplied name and the name to use for sampling)
    :param mustBeVDO: If set to False, errors resulting from the device not
                      being a VDO will be suppressed

    :return: The results of the assays or None if the device is not a VDO and
             mustBeVDO is set to False
    Ncsg|]}tj�|���qSr)r
r)rr)rrrrrosz(Samples.assayDevices.<locals>.<listcomp>)�filter)rZdevicesrr)rrr�assayDevicesaszSamples.assayDevicescCs
||d�S)a�
    Returns a dictionary used for sampling purposes.

    The dictionary is structured as:
      { "user"   : <user-specified name>,
        "sample" : <sample name> }

    The user-specified name is used for display purposes.
    The sample name is used to perform the actual sampling.
    The two names may be identical.

    :param user:    user-specified name
    :param sample:  the name to use for sampling

    :return:  A sampling dictionary.
    )rrr)rrrrr�samplingDevicerszSamples.samplingDeviceN)T)T)�__name__�
__module__�__qualname__�__doc__rrr�staticmethodrr#r$rrrrr
'sr
c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�SamplezB
  An object which represents a single sample (ioctl) of a VDO.
  cCs||_||_dS)z�
    Create a new sample.

    :param statStruct: The structure representing the type of this sample
    :param sample:     The sampled values
    N)�
statStructr)rr+rrrrr�szSample.__init__cCs|jS)z�
    Get the object representing the type of this sample.

    :return: The StatStruct which represents the type of this sample
    )r+)rrrr�getType�szSample.getTypecCs|jj|j�S)z
    Get the sampled values as a collection of LabeledValues.

    :return: A LabeledValue representing the sampled values
    )r+�labeledr)rrrrr-�szSample.labeledcCsDt|t�s|j|S|j}x|dd�D]}||}q(W||dS)a
    Get the value of a named statistic.

    :param statName:     The name of the statistic, either as a string, or as
                         a list of strings, one for each level of the sample
                         hierarchy

    :return: The value of the named statistic
    Nr���r.)�
isinstance�listr)r�statName�stats�namerrr�getStat�s


zSample.getStatcCs|j|�|j|�kS)ad
    Check whether the value of a given statistic is the same in this sample
    and some other sample.

    :param other: The other sample
    :param statName: The name of the statistic as would be specified to
                     getStat()

    :return: True if the value of the named statistic is the same in this and
             the other sample
    )r4)r�otherr1rrr�	statEqual�szSample.statEqualN)	r%r&r'r(rr,r-r4r6rrrrr*�s
r*csVeZdZdZiZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
ddd�Z�ZS)�
StatStructz�
  Base class for objects representing a VDO statistics structure. This object
  can be used to sample a VDO via an ioctl and convert the result from the
  C format in the ioctl to a Sample object.
  cs�|jdd�}|dkr|dnd|_|jdd�|_|jdd�|_|jdd�|_||_tt|�j||j	�f|�t
�|_x|D]}||j|j<qzWdS)a�
    Create a new statistics structure.

    :param name:     The name of statistics structure
    :param fields:   A list of Field objects specifying the format of the C
                     structure returned by the ioctl
    :param **kwargs: Keyword args which may be:
                       labelPrefix: The prefix to prepend to the label for
                                    each field in this structure
                       ioctl:       The value of the ioctl to use for sampling
                                    a VDO
                       Field:       Any of the keyword arguments for the Field
                                    base class
    �labelPrefixN� ��ioctl�procFile�procRoot)
�popr8r;r<r=�fields�superr7r�
_getCClass�dict�fieldsByNamer3)rr3r?�kwargsr8�field)�	__class__rrr�s
zStatStruct.__init__cCsRt|�jd}|jj|�}|sNdd�|jD�}tt|�tfd|i�}||j|<|S)z�
    Get the Structure class which represents the C struct for a StatStruct
    or Field. If the Structure class hasn't yet been made for the given type,
    it will be created.

    :return: The class defined by the specified set of Fields
    z.ccSsg|]}|jr|j|jf�qSr)ZinStructr3�cType)rrErrrr�sz)StatStruct._getCClass.<locals>.<listcomp>Z_fields_)�typer%�cClasses�getr?�strZ	Structure)rZ	classNamerGZ	fieldListrrrrA�s
zStatStruct._getCClassc	CsH|j�}tjjd|j||j�}t|d��}|j|�WdQRX|j|�S)z�
    Get a sample from a VDO via an ioctl.

    :param name: The name of the proc directory from which to read

    :return: The sample
    z/proc�rbN)	rGr
r�joinr=r<�open�readinto�_extract)rr3r2ZprocPath�fdrrrr�s
zStatStruct.samplecCs2t�}x |jD]}|j||�||j<qWt||�S)z�
    Extract the sampled values from the return of an ioctl call.

    :param stats: The structure returned from an ioctl

    :return: The sample as a Sample
    )rBr?�
extractSampler3r*)rr2rrErrrrP
szStatStruct._extractcs^t|�j|�}�jdkr2||kr2�fdd�|D�St�}x �jD]}|j|��||j<q@W|S)z
    :inherit:
    rcsg|]}�j|���qSr)rR)r�s)rrrrsz,StatStruct.extractSample.<locals>.<listcomp>)�getattrr3ZlengthrBr?rR)rr2�parentZmyStatsrrEr)rrrRszStatStruct.extractSamplecCs|j|j||�S)a
    Get the value of one of the fields at the current level of the C structure
    from the ioctl.

    :param stats:     The current level of the C structure
    :param fieldName: The name of the field to get

    :return: The value of the specified field
    )rCrR)rr2Z	fieldNamerrr�getSampleValue(s
zStatStruct.getSampleValuer:csV��j7���j}t�t�r4��fdd��D�}n��fdd��jD�}tj||�S)z
    :inherit:
    csg|]}�j|���qSr)r-)rrS)�prefixrrrr<sz&StatStruct.labeled.<locals>.<listcomp>cs$g|]}|jr|j�|j���qSr)Zdisplayr-r3)rrE)rWrrrr?s)r8�labelr/r0r?r	Zmake)rrrWrXZ
labeledFieldsr)rWrrrr-4s



zStatStruct.labeled)r:)
r%r&r'r(rIrrArrPrRrVr-�
__classcell__rr)rFrr7�s
r7)r(Z
__future__rrrrZctypes�collectionsZfcntlr
�sysrr	�objectr
r*r7rrrr�<module>s_>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists