VirtualBox

Changeset 20897 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Jun 24, 2009 3:54:41 PM (16 years ago)
Author:
vboxsync
Message:

Python: cleanup, refactoring, don't fail on timed wait requests on Darwin, just return, shell improvments

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/vboxapi.py

    r20818 r20897  
    3333from VirtualBox_constants import VirtualBoxReflectionInfo
    3434
     35class PerfCollector:
     36    """ This class provides a wrapper over IPerformanceCollector in order to
     37    get more 'pythonic' interface.
     38
     39    To begin collection of metrics use setup() method.
     40
     41    To get collected data use query() method.
     42
     43    It is possible to disable metric collection without changing collection
     44    parameters with disable() method. The enable() method resumes metric
     45    collection.
     46    """
     47
     48    def __init__(self, vb):
     49        """ Initializes the instance.
     50
     51        Pass an instance of IVirtualBox as parameter.
     52        """
     53        self.collector = vb.performanceCollector
     54
     55    def setup(self, names, objects, period, nsamples):
     56        """ Discards all previously collected values for the specified
     57        metrics, sets the period of collection and the number of retained
     58        samples, enables collection.
     59        """
     60        self.collector.setupMetrics(names, objects, period, nsamples)
     61
     62    def enable(self, names, objects):
     63        """ Resumes metric collection for the specified metrics.
     64        """
     65        self.collector.enableMetrics(names, objects)
     66
     67    def disable(self, names, objects):
     68        """ Suspends metric collection for the specified metrics.
     69        """
     70        self.collector.disableMetrics(names, objects)
     71
     72    def query(self, names, objects):
     73        """ Retrieves collected metric values as well as some auxiliary
     74        information. Returns an array of dictionaries, one dictionary per
     75        metric. Each dictionary contains the following entries:
     76        'name': metric name
     77        'object': managed object this metric associated with
     78        'unit': unit of measurement
     79        'scale': divide 'values' by this number to get float numbers
     80        'values': collected data
     81        'values_as_string': pre-processed values ready for 'print' statement
     82        """
     83        (values, names_out, objects_out, units, scales, sequence_numbers,
     84            indices, lengths) = self.collector.queryMetricsData(names, objects)
     85        out = []
     86        for i in xrange(0, len(names_out)):
     87            scale = int(scales[i])
     88            if scale != 1:
     89                fmt = '%.2f%s'
     90            else:
     91                fmt = '%d %s'
     92            out.append({
     93                'name':str(names_out[i]),
     94                'object':str(objects_out[i]),
     95                'unit':str(units[i]),
     96                'scale':scale,
     97                'values':[int(values[j]) for j in xrange(int(indices[i]), int(indices[i])+int(lengths[i]))],
     98                'values_as_string':'['+', '.join([fmt % (int(values[j])/scale, units[i]) for j in xrange(int(indices[i]), int(indices[i])+int(lengths[i]))])+']'
     99            })
     100        return out
     101
    35102class PlatformMSCOM:
    36103    # Class to fake access to constants in style of foo.bar.boo
     
    191258        if rc >= WAIT_OBJECT_0 and rc < WAIT_OBJECT_0+len(self.handles):
    192259            # is it possible?
    193             print "how come?"
    194260            pass
    195261        elif rc==WAIT_OBJECT_0 + len(self.handles):
     
    210276        pythoncom.CoUninitialize()
    211277        pass
     278
     279    def getPerfCollector(self, vbox):
     280        # MS COM cannot invoke performance collector methods yet
     281        return None
     282
    212283
    213284class PlatformXPCOM:
     
    265336        import xpcom
    266337        xpcom._xpcom.DeinitCOM()
     338
     339    def getPerfCollector(self, vbox):
     340        return PerfCollector(vbox)
    267341
    268342class PlatformWEBSERVICE:
     
    286360
    287361    def getVirtualBox(self):
    288         return self.wsmgr.logon(self.user, self.password)
     362        self.vbox = self.wsmgr.logon(self.user, self.password)
    289363
    290364    def getConstants(self):
     
    310384
    311385    def waitForEvents(self, timeout):
    312         # Webservices cannot do that
     386        # Webservices cannot do that yet
    313387        pass
    314388
    315389    def deinit(self):
    316         # should we do something about it?
    317         pass
     390        try:
     391            if self.vbox is not None:
     392                self.wsmg.logoff(self.vbox)
     393                self.vbox = None
     394        except:
     395            pass
     396
     397    def getPerfCollector(self, vbox):
     398        return PerfCollector(vbox)   
    318399
    319400class SessionManager:
     
    338419            self.type = self.platform.getType()
    339420            self.remote = self.platform.getRemote()
     421            self.style = style           
    340422        except Exception,e:
    341423            print "init exception: ",e
     
    350432
    351433    def __del__(self):
    352         deinit(self)
     434        self.deinit()
    353435
    354436    def deinit(self):
    355437        if hasattr(self, "vbox"):
    356438            del self.vbox
     439            self.vbox = None
    357440        if hasattr(self, "platform"):
    358441            self.platform.deinit()
     442             self.platform = None
    359443
    360444    def initPerThread(self):
     
    377461    def waitForEvents(self, timeout):
    378462        return self.platform.waitForEvents(timeout)
     463
     464    def getPerfCollector(self, vbox):
     465        return self.platform.getPerfCollector(vbox)       
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r20896 r20897  
    43264326
    43274327    <attribute name="CPUCount" type="unsigned long">
    4328       <desc>Number of virtual CPUs in the VM. In the current version of the product, this is always 1.</desc>
     4328      <desc>Number of virtual CPUs in the VM.</desc>
    43294329    </attribute>
    43304330
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette