ó .Åt_c@s¦dZddlTddlZddlZddlZddlZddlmZddlmZdefd„ƒYZ defd „ƒYZ d efd „ƒYZ dS( 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" : , "sample" : } 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(R R"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(R tstatNametstatstname((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*(R totherR'((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 RR7RRIRLRSR$(((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyR-Às     ( Rtctypest collectionstfcntlRtsysRRtobjectRR!R-(((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyts     _>