VirtualBox

Changeset 43949 in vbox


Ignore:
Timestamp:
Nov 23, 2012 1:43:19 PM (12 years ago)
Author:
vboxsync
Message:

Main/Metics: VM disk usage metric (#6345)

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/MachineImpl.h

    r43915 r43949  
    944944
    945945#ifdef VBOX_WITH_RESOURCE_USAGE_API
     946    void getDiskList(MediaList &list);
    946947    void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
    947948
  • trunk/src/VBox/Main/include/Performance.h

    r43933 r43949  
    3232#include <vector>
    3333#include <queue>
     34
     35#include "MediumImpl.h"
    3436
    3537/* Forward decl. */
     
    693695
    694696#ifndef VBOX_COLLECTOR_TEST_CASE
     697    typedef std::list<ComObjPtr<Medium> > MediaList;
     698    class MachineDiskUsage : public BaseMetric
     699    {
     700    public:
     701        MachineDiskUsage(CollectorHAL *hal, ComPtr<IUnknown> object, MediaList &disks, SubMetric *used)
     702        : BaseMetric(hal, "Disk/Usage", object), mDisks(disks), mUsed(used) {};
     703        ~MachineDiskUsage() { delete mUsed; };
     704
     705        void init(ULONG period, ULONG length);
     706        void preCollect(CollectorHints& hints, uint64_t iTick);
     707        void collect();
     708        const char *getUnit() { return "mB"; };
     709        ULONG getMinValue() { return 0; };
     710        ULONG getMaxValue() { return INT32_MAX; };
     711        ULONG getScale() { return 1; }
     712    private:
     713        MediaList   mDisks;
     714        SubMetric *mUsed;
     715    };
     716
    695717    /*
    696718     * Although MachineNetRate is measured for VM, not for the guest, it is
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r43915 r43949  
    1146111461#ifdef VBOX_WITH_RESOURCE_USAGE_API
    1146211462
     11463void Machine::getDiskList(MediaList &list)
     11464{
     11465    for (MediaData::AttachmentList::const_iterator it = mMediaData->mAttachments.begin();
     11466         it != mMediaData->mAttachments.end();
     11467         ++it)
     11468    {
     11469        MediumAttachment* pAttach = *it;
     11470        /* just in case */
     11471        AssertStmt(pAttach, continue);
     11472
     11473        AutoCaller localAutoCallerA(pAttach);
     11474        if (FAILED(localAutoCallerA.rc())) continue;
     11475
     11476        AutoReadLock local_alockA(pAttach COMMA_LOCKVAL_SRC_POS);
     11477
     11478        if (pAttach->getType() == DeviceType_HardDisk)
     11479            list.push_back(pAttach->getMedium());
     11480    }
     11481}
     11482
    1146311483void Machine::registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid)
    1146411484{
     
    1147411494    pm::SubMetric *ramUsageUsed  = new pm::SubMetric("RAM/Usage/Used",
    1147511495        "Size of resident portion of VM process in memory.");
     11496    pm::SubMetric *diskUsageUsed  = new pm::SubMetric("Disk/Usage/Used",
     11497        "Actual size of all VM disks combined.");
    1147611498    pm::SubMetric *machineNetRx = new pm::SubMetric("Net/Rate/Rx",
    1147711499        "Network receive rate.");
     
    1148511507                                                       ramUsageUsed);
    1148611508    aCollector->registerBaseMetric(ramUsage);
     11509    MediaList disks;
     11510    getDiskList(disks);
     11511    pm::BaseMetric *diskUsage = new pm::MachineDiskUsage(hal, aMachine, disks,
     11512                                                         diskUsageUsed);
     11513    aCollector->registerBaseMetric(diskUsage);
    1148711514
    1148811515    aCollector->registerMetric(new pm::Metric(cpuLoad, cpuLoadUser, 0));
     
    1150711534                                              new pm::AggregateMin()));
    1150811535    aCollector->registerMetric(new pm::Metric(ramUsage, ramUsageUsed,
     11536                                              new pm::AggregateMax()));
     11537
     11538    aCollector->registerMetric(new pm::Metric(diskUsage, diskUsageUsed, 0));
     11539    aCollector->registerMetric(new pm::Metric(diskUsage, diskUsageUsed,
     11540                                              new pm::AggregateAvg()));
     11541    aCollector->registerMetric(new pm::Metric(diskUsage, diskUsageUsed,
     11542                                              new pm::AggregateMin()));
     11543    aCollector->registerMetric(new pm::Metric(diskUsage, diskUsageUsed,
    1150911544                                              new pm::AggregateMax()));
    1151011545
  • trunk/src/VBox/Main/src-server/Performance.cpp

    r43908 r43949  
    2525#include "VirtualBoxImpl.h"
    2626#include "MachineImpl.h"
     27#include "MediumImpl.h"
     28#include "AutoCaller.h"
    2729#endif
    2830#include "Performance.h"
     
    10061008
    10071009#ifndef VBOX_COLLECTOR_TEST_CASE
     1010void MachineDiskUsage::init(ULONG period, ULONG length)
     1011{
     1012    mPeriod = period;
     1013    mLength = length;
     1014    mUsed->init(mLength);
     1015}
     1016
     1017void MachineDiskUsage::preCollect(CollectorHints& /* hints */, uint64_t /* iTick */)
     1018{
     1019}
     1020
     1021void MachineDiskUsage::collect()
     1022{
     1023    ULONG used = 0;
     1024
     1025    for (MediaList::iterator it = mDisks.begin(); it != mDisks.end(); ++it)
     1026    {
     1027        ComObjPtr<Medium> pMedium = *it;
     1028
     1029        /* just in case */
     1030        AssertStmt(!pMedium.isNull(), continue);
     1031
     1032        AutoCaller localAutoCaller(pMedium);
     1033        if (FAILED(localAutoCaller.rc())) continue;
     1034
     1035        AutoReadLock local_alock(pMedium COMMA_LOCKVAL_SRC_POS);
     1036
     1037        used += pMedium->getSize() / (1024 * 1024);
     1038    }
     1039
     1040    mUsed->put(used);
     1041}
     1042
    10081043void MachineNetRate::init(ULONG period, ULONG length)
    10091044{
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