.t_c@sdZddlTddlZddlZddlZddlZddlmZddlmZdefdYZ 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\eZdZdZdZdZeedZeedZ edZ 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;eZdZdZdZdZdZdZRS(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.pyRs 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|jS(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|ts|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.pytgetStats   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 statEquals (RRRRR#R$R*R,(((s=/usr/lib/python2.7/site-packages/vdo/statistics/StatStruct.pyR!s    t StatStructcBsVeZdZiZdZdZdZdZdZdZ ddZ 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     _>