HEX
Server: Apache
System: Linux msm5694.mjhst.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: camjab_ssh (1000)
PHP: 5.3.29
Disabled: NONE
Upload Files
File: //lib/python2.7/site-packages/vdo/statistics/StatStruct.pyo
ó
.Åt_c@s¦dZddlTddlZddlZddlZddlZddlmZddlmZdefd„ƒYZ	defd	„ƒYZ
d
efd„ƒYZdS(s˜
  StatStruct -- classes for sampling statistics from a VDO via ioctls

  $Id: //eng/vdo-releases/magnesium/src/python/vdo/statistics/StatStruct.py#2 $
iÿÿÿÿ(t*N(tField(tLabeledValuetSamplescBs\eZdZd„Zd„Zd„Zeed„ƒZeed„ƒZ	ed„ƒZ
RS(sD
  An object which represents a collection of samples from a VDO.
  cCsF|d|_g|D]%}|jtjj|dƒƒ^q|_dS(s‡
    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
    tusertsampleN(tdeviceRtostpathtbasenametsamples(tselftassaysRt	mustBeVDOtassay((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyt__init__'s

cCs|jS(s\
    Get the name of the device which was sampled.

    :return: The name of the device
    (R(R((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyt	getDevice5scCs|jS(sS
    Get the list of samples for the device.

    :return: The list of samples
    (R
(R((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyt
getSamples=scCsyt|||ƒSWnftk
r|}|d}|jdkra|r]tdj|ƒƒ‚ndStdj||ƒƒ‚nXdS(s×
    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
    RisDevice {0} is not a VDOsError sampling device {0}: {1}N(RtIOErrorterrnot	ExceptiontformattNone(RRR
tioeR((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyREs
cCs/tdg|D]}tj|||ƒ^q
ƒS(së
    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
    N(tfilterRRR(RtdevicesR
R((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pytassayDevices]s	cCsi|d6|d6S(sÈ
    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((RR((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pytsamplingDevicens(t__name__t
__module__t__doc__RRRtstaticmethodtTrueRRR(((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyR#s			tSamplecBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(sB
  An object which represents a single sample (ioctl) of a VDO.
  cCs||_||_dS(s“
    Create a new sample.

    :param statStruct: The structure representing the type of this sample
    :param sample:     The sampled values
    N(t
statStructR(RR"R((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyR†s	cCs|jS(s„
    Get the object representing the type of this sample.

    :return: The StatStruct which represents the type of this sample
    (R"(R((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pytgetTypescCs|jj|jƒS(s
    Get the sampled values as a collection of LabeledValues.

    :return: A LabeledValue representing the sampled values
    (R"tlabeledR(R((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyR$˜scCsNt|tƒs|j|S|j}x|d D]}||}q.W||dS(s
    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
    iÿÿÿÿ(t
isinstancetlistR(RtstatNametstatstname((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pytgetStat s
	cCs|j|ƒ|j|ƒkS(sd
    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
    (R*(RtotherR'((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyt	statEqual²s(RRRRR#R$R*R,(((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyR!‚s	
			t
StatStructcBsVeZdZiZd„Zd„Zd„Zd„Zd„Zd„Z	dd„Z
RS(	sÈ
  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.
  cKsÌ|jddƒ}|dkr(|dnd|_|jddƒ|_|jddƒ|_|jddƒ|_||_tt|ƒj	||j
ƒ|tƒ|_x|D]}||j|j
<q®WdS(s—
    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
    tlabelPrefixt ttioctltprocFiletprocRootN(tpopRR.R1R2R3tfieldstsuperR-Rt
_getCClasstdicttfieldsByNameR)(RR)R5tkwargsR.tfield((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyRÌs	"
cCsŒt|ƒjd}|jj|ƒ}|sˆg|jD]!}|jr5|j|jf^q5}t|tfi|d6ƒ}||j|<n|S(sõ
    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
    s.ct_fields_(	ttypeRtcClassestgetR5tinStructR)tcTypet	Structure(Rt	classNameRAR;t	fieldList((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyR7æs!cCs_|jƒ}tjjd|j||jƒ}t|dƒ}|j|ƒWdQX|j|ƒS(sŒ
    Get a sample from a VDO via an ioctl.

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

    :return: The sample
    s/proctrbN(	RARRtjoinR3R2topentreadintot_extract(RR)R(tprocPathtfd((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyRøs
!cCsCtƒ}x*|jD]}|j||ƒ||j<qWt||ƒS(s£
    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
    (R8R5t
extractSampleR)R!(RR(RR;((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyRIs	cCst||j|ƒ}|jdkrS||krSg|D]}|j||ƒ^q7Stƒ}x*|jD]}|j||ƒ||j<qfW|S(s
    :inherit:
    i(tgetattrR)tlengthRLR8R5(RR(tparenttmyStatstsRR;((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyRLs#	cCs|j|j||ƒS(s
    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
    (R9RL(RR(t	fieldName((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pytgetSampleValue$s
R0cCs™||j7}||j}t|tƒrQg|D]}|j||ƒ^q0}n8g|jD](}|jr[|j||j|ƒ^q[}tj	||ƒS(s
    :inherit:
    (
R.tlabelR%R&R$R5tdisplayR)Rtmake(RRtprefixRTRQt
labeledFieldsR;((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyR$0s

(5(RRRR>RR7RRIRLRSR$(((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyR-Às				
		(RtctypestcollectionstfcntlRtsysRRtobjectRR!R-(((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyt<module>s
_>