Performance.h revision 561574402775590253d11504354bfe21d80e4858
6c6531128b39093daeac902a8705c0bdf15b31ccvboxsync * VirtualBox Main - Performance Classes declaration.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2008 Oracle Corporation
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync * available from http://www.virtualbox.org. This file is free software;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync * you can redistribute it and/or modify it under the terms of the GNU
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync * General Public License (GPL) as published by the Free Software
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
02a759adb419d49bc2d50a196143c4f517510413vboxsync#include <functional> /* For std::fun_ptr in testcase */
c2a7eba496481419a88aba56bbed51f7c8194926vboxsync/* Forward decl. */
391cf11262671da62bcc02db361038e7ffbab8f7vboxsync /* CPU load is measured in 1/1000 of per cent. */
391cf11262671da62bcc02db361038e7ffbab8f7vboxsync const uint64_t PM_CPU_LOAD_MULTIPLIER = UINT64_C(100000);
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync /* Sub Metrics **********************************************************/
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync CircularBuffer() : mData(0), mLength(0), mEnd(0), mWrapped(false) {};
a2ee3f493c9808b3f1902dcda6d9449672ffaec9vboxsync ~CircularBuffer() { if (mData) RTMemFree(mData); };
49207a1552ff3752904e36b9269f08fe643ba871vboxsync ULONG getSequenceNumber() { return mSequenceNumber; }
83c86878d483df62ca8db465c671995984838338vboxsync SubMetric(const char *name, const char *description)
83c86878d483df62ca8db465c671995984838338vboxsync const char *getDescription() { return mDescription; };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync const char *mName;
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync typedef std::pair<RTPROCESS, HintFlags> ProcessFlagsPair;
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { findProcess(process).second |= COLLECT_CPU_LOAD; }
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { findProcess(process).second |= COLLECT_RAM_USAGE; }
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync { findProcess(process).second |= COLLECT_GUEST_STATS; }
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync { return (mHostFlags & COLLECT_GUEST_STATS) != 0; }
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { return (findProcess(process).second & COLLECT_CPU_LOAD) != 0; }
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { return (findProcess(process).second & COLLECT_RAM_USAGE) != 0; }
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync { return (findProcess(process).second & COLLECT_GUEST_STATS) != 0; }
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync void getProcesses(std::vector<RTPROCESS>& processes) const
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync for (ProcessList::const_iterator it = mProcesses.begin(); it != mProcesses.end(); it++)
054466641bb642a73b66938a9fb851bad1147749vboxsync for (it = mProcesses.begin(); it != mProcesses.end(); it++)
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync /* Not found -- add new */
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync mProcesses.push_back(ProcessFlagsPair(process, COLLECT_NONE));
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync /* Guest Collector Classes *********************************/
7a3d722456f70226ebc994df685bd736e4324d04vboxsync * WARNING! The bits in the following masks must correspond to parameters
7a3d722456f70226ebc994df685bd736e4324d04vboxsync * of CollectorGuest::updateStats().
7a3d722456f70226ebc994df685bd736e4324d04vboxsync typedef enum
7a3d722456f70226ebc994df685bd736e4324d04vboxsync GUESTSTATMASK_CPUUSER|GUESTSTATMASK_CPUKERNEL|GUESTSTATMASK_CPUIDLE;
7a3d722456f70226ebc994df685bd736e4324d04vboxsync GUESTSTATMASK_MEMTOTAL|GUESTSTATMASK_MEMFREE|GUESTSTATMASK_MEMBALLOON|
561574402775590253d11504354bfe21d80e4858vboxsync const ULONG GUESTSTATS_ALL = GUESTSTATS_CPULOAD|GUESTSTATS_RAMUSAGE|GUESTSTATS_VMMRAM;
561574402775590253d11504354bfe21d80e4858vboxsync void setGuest(CollectorGuest *aGuest) { mCGuest = aGuest; };
561574402775590253d11504354bfe21d80e4858vboxsync virtual void debugPrint(void *aObject, const char *aFunction, const char *aText) = 0;
561574402775590253d11504354bfe21d80e4858vboxsync void debugPrint(void *aObject, const char *aFunction, const char *aText);
561574402775590253d11504354bfe21d80e4858vboxsync void debugPrint(void *aObject, const char *aFunction, const char *aText);
561574402775590253d11504354bfe21d80e4858vboxsync void debugPrint(void *aObject, const char *aFunction, const char *aText);
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync CollectorGuest(Machine *machine, RTPROCESS process);
561574402775590253d11504354bfe21d80e4858vboxsync bool isValid(ULONG mask) { return (mValid & mask) == mask; };
7a3d722456f70226ebc994df685bd736e4324d04vboxsync void updateStats(ULONG aValidStats, ULONG aCpuUser,
561574402775590253d11504354bfe21d80e4858vboxsync int enqueueRequest(CollectorGuestRequest *aRequest);
561574402775590253d11504354bfe21d80e4858vboxsync const com::Utf8Str& getVMName() const { return mMachineName; };
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync typedef std::list<CollectorGuest*> CollectorGuestList;
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync CollectorGuest *getVMMStatsProvider() { return mVMMStatsProvider; };
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync void preCollect(CollectorHints& hints, uint64_t iTick);
561574402775590253d11504354bfe21d80e4858vboxsync int enqueueRequest(CollectorGuestRequest *aRequest);
561574402775590253d11504354bfe21d80e4858vboxsync CollectorGuest *getBlockedGuest() { return mGuestBeingCalled; };
561574402775590253d11504354bfe21d80e4858vboxsync static DECLCALLBACK(int) requestProcessingThread(RTTHREAD aThread, void *pvUser);
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync /* Collector Hardware Abstraction Layer *********************************/
1965d3323263fc938e3bbf02aa83f6d7d53a7d98vboxsync virtual int preCollect(const CollectorHints& /* hints */, uint64_t /* iTick */) { return VINF_SUCCESS; }
79e36c53917758fe8e3623fe9de2e21336431147vboxsync /** Returns averaged CPU usage in 1/1000th per cent across all host's CPUs. */
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync virtual int getHostCpuLoad(ULONG *user, ULONG *kernel, ULONG *idle);
79e36c53917758fe8e3623fe9de2e21336431147vboxsync /** Returns the average frequency in MHz across all host's CPUs. */
79e36c53917758fe8e3623fe9de2e21336431147vboxsync /** Returns the amount of physical memory in kilobytes. */
cb893baebb2af3f4fc9cd613a24d5a25e6687a6cvboxsync virtual int getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available);
79e36c53917758fe8e3623fe9de2e21336431147vboxsync /** Returns CPU usage in 1/1000th per cent by a particular process. */
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync virtual int getProcessCpuLoad(RTPROCESS process, ULONG *user, ULONG *kernel);
79e36c53917758fe8e3623fe9de2e21336431147vboxsync /** Returns the amount of memory used by a process in kilobytes. */
cb893baebb2af3f4fc9cd613a24d5a25e6687a6cvboxsync virtual int getProcessMemoryUsage(RTPROCESS process, ULONG *used);
79e36c53917758fe8e3623fe9de2e21336431147vboxsync /** Returns CPU usage counters in platform-specific units. */
040c9969cc5574339d5f1fa2c95c73da095c151bvboxsync virtual int getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle);
79e36c53917758fe8e3623fe9de2e21336431147vboxsync /** Returns process' CPU usage counter in platform-specific units. */
040c9969cc5574339d5f1fa2c95c73da095c151bvboxsync virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total);
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync /* Base Metrics *********************************************************/
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync BaseMetric(CollectorHAL *hal, const char *name, ComPtr<IUnknown> object)
a05b4948186b031cbd8c3b7c6cfe973d69039016vboxsync : mPeriod(0), mLength(0), mHAL(hal), mName(name), mObject(object),
a05b4948186b031cbd8c3b7c6cfe973d69039016vboxsync mLastSampleTaken(0), mEnabled(false), mUnregistered(false) {};
cbf5a4260109bea05e1492f0b375b11a738cfb1dvboxsync virtual void preCollect(CollectorHints& hints, uint64_t iTick) = 0;
561574402775590253d11504354bfe21d80e4858vboxsync virtual int enable() { mEnabled = true; return S_OK; };
561574402775590253d11504354bfe21d80e4858vboxsync virtual int disable() { mEnabled = false; return S_OK; };
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync bool associatedWith(ComPtr<IUnknown> object) { return mObject == object; };
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync const char *mName;
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync BaseGuestMetric(CollectorGuest *cguest, const char *name, ComPtr<IUnknown> object)
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync : BaseMetric(NULL, name, object), mCGuest(cguest) {};
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync HostCpuLoad(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync : BaseMetric(hal, "CPU/Load", object), mUser(user), mKernel(kernel), mIdle(idle) {};
088a45b35631115e7729fdc57a56f49faf0c2a43vboxsync ~HostCpuLoad() { delete mUser; delete mKernel; delete mIdle; };
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getMaxValue() { return PM_CPU_LOAD_MULTIPLIER; };
49207a1552ff3752904e36b9269f08fe643ba871vboxsync ULONG getScale() { return PM_CPU_LOAD_MULTIPLIER / 100; }
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync HostCpuLoadRaw(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync : HostCpuLoad(hal, object, user, kernel, idle), mUserPrev(0), mKernelPrev(0), mIdlePrev(0) {};
cbf5a4260109bea05e1492f0b375b11a738cfb1dvboxsync void preCollect(CollectorHints& hints, uint64_t iTick);
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync HostCpuMhz(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *mhz)
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync : BaseMetric(hal, "CPU/MHz", object), mMHz(mhz) {};
cbf5a4260109bea05e1492f0b375b11a738cfb1dvboxsync void preCollect(CollectorHints& /* hints */, uint64_t /* iTick */) {}
e11c3cb1ab3034f15eaccc2a6fdb998b6752a429vboxsync HostRamUsage(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *total, SubMetric *used, SubMetric *available)
8374dfdfc4d7fdfcfbaeec4c65fbf856212d4c32vboxsync : BaseMetric(hal, "RAM/Usage", object), mTotal(total), mUsed(used), mAvailable(available) {};
8374dfdfc4d7fdfcfbaeec4c65fbf856212d4c32vboxsync ~HostRamUsage() { delete mTotal; delete mUsed; delete mAvailable; };
cbf5a4260109bea05e1492f0b375b11a738cfb1dvboxsync void preCollect(CollectorHints& hints, uint64_t iTick);
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync HostRamVmm(CollectorGuestManager *gm, ComPtr<IUnknown> object, SubMetric *allocVMM, SubMetric *freeVMM, SubMetric *balloonVMM, SubMetric *sharedVMM)
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync : BaseMetric(NULL, "RAM/VMM", object), mCollectorGuestManager(gm),
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync mAllocVMM(allocVMM), mFreeVMM(freeVMM), mBalloonVMM(balloonVMM), mSharedVMM(sharedVMM),
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync mAllocCurrent(0), mFreeCurrent(0), mBalloonedCurrent(0), mSharedCurrent(0) {};
8374dfdfc4d7fdfcfbaeec4c65fbf856212d4c32vboxsync ~HostRamVmm() { delete mAllocVMM; delete mFreeVMM; delete mBalloonVMM; delete mSharedVMM; };
8374dfdfc4d7fdfcfbaeec4c65fbf856212d4c32vboxsync void preCollect(CollectorHints& hints, uint64_t iTick);
561574402775590253d11504354bfe21d80e4858vboxsync#endif /* VBOX_COLLECTOR_TEST_CASE */
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync MachineCpuLoad(CollectorHAL *hal, ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel)
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync : BaseMetric(hal, "CPU/Load", object), mProcess(process), mUser(user), mKernel(kernel) {};
088a45b35631115e7729fdc57a56f49faf0c2a43vboxsync ~MachineCpuLoad() { delete mUser; delete mKernel; };
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getMaxValue() { return PM_CPU_LOAD_MULTIPLIER; };
49207a1552ff3752904e36b9269f08fe643ba871vboxsync ULONG getScale() { return PM_CPU_LOAD_MULTIPLIER / 100; }
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync MachineCpuLoadRaw(CollectorHAL *hal, ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel)
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync : MachineCpuLoad(hal, object, process, user, kernel), mHostTotalPrev(0), mProcessUserPrev(0), mProcessKernelPrev(0) {};
cbf5a4260109bea05e1492f0b375b11a738cfb1dvboxsync void preCollect(CollectorHints& hints, uint64_t iTick);
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync MachineRamUsage(CollectorHAL *hal, ComPtr<IUnknown> object, RTPROCESS process, SubMetric *used)
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync : BaseMetric(hal, "RAM/Usage", object), mProcess(process), mUsed(used) {};
cbf5a4260109bea05e1492f0b375b11a738cfb1dvboxsync void preCollect(CollectorHints& hints, uint64_t iTick);
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync GuestCpuLoad(CollectorGuest *cguest, ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync : BaseGuestMetric(cguest, "Guest/CPU/Load", object), mUser(user), mKernel(kernel), mIdle(idle) {};
1439977563a6d2143201766a0d7c61e50a5acf75vboxsync ~GuestCpuLoad() { delete mUser; delete mKernel; delete mIdle; };
cbf5a4260109bea05e1492f0b375b11a738cfb1dvboxsync void preCollect(CollectorHints& hints, uint64_t iTick);
1439977563a6d2143201766a0d7c61e50a5acf75vboxsync ULONG getMaxValue() { return PM_CPU_LOAD_MULTIPLIER; };
1439977563a6d2143201766a0d7c61e50a5acf75vboxsync ULONG getScale() { return PM_CPU_LOAD_MULTIPLIER / 100; }
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync GuestRamUsage(CollectorGuest *cguest, ComPtr<IUnknown> object, SubMetric *total, SubMetric *free, SubMetric *balloon, SubMetric *shared, SubMetric *cache, SubMetric *pagedtotal)
0b6e534f55fcb5870df42b58ae354ad5fdbda66avboxsync : BaseGuestMetric(cguest, "Guest/RAM/Usage", object), mTotal(total), mFree(free), mBallooned(balloon), mCache(cache), mPagedTotal(pagedtotal), mShared(shared) {};
cc04399629ac806e92deeb3006dc1d507a608901vboxsync ~GuestRamUsage() { delete mTotal; delete mFree; delete mBallooned; delete mShared; delete mCache; delete mPagedTotal; };
cbf5a4260109bea05e1492f0b375b11a738cfb1dvboxsync void preCollect(CollectorHints& hints, uint64_t iTick);
cc04399629ac806e92deeb3006dc1d507a608901vboxsync SubMetric *mTotal, *mFree, *mBallooned, *mCache, *mPagedTotal, *mShared;
561574402775590253d11504354bfe21d80e4858vboxsync#endif /* VBOX_COLLECTOR_TEST_CASE */
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync /* Aggregate Functions **************************************************/
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync virtual ULONG compute(ULONG *data, ULONG length) = 0;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync /* Metric Class *********************************************************/
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync Metric(BaseMetric *baseMetric, SubMetric *subMetric, Aggregate *aggregate) :
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync mName(subMetric->getName()), mBaseMetric(baseMetric), mSubMetric(subMetric), mAggregate(aggregate)
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync bool associatedWith(ComPtr<IUnknown> object) { return getObject() == object; };
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync ComPtr<IUnknown> getObject() { return mBaseMetric->getObject(); };
83c86878d483df62ca8db465c671995984838338vboxsync { return mAggregate ? "" : mSubMetric->getDescription(); };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync const char *getUnit() { return mBaseMetric->getUnit(); };
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getMinValue() { return mBaseMetric->getMinValue(); };
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getMaxValue() { return mBaseMetric->getMaxValue(); };
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getPeriod() { return mBaseMetric->getPeriod(); };
83c86878d483df62ca8db465c671995984838338vboxsync { return mAggregate ? 1 : mBaseMetric->getLength(); };
49207a1552ff3752904e36b9269f08fe643ba871vboxsync ULONG getScale() { return mBaseMetric->getScale(); }
49207a1552ff3752904e36b9269f08fe643ba871vboxsync void query(ULONG **data, ULONG *count, ULONG *sequenceNumber);
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync /* Filter Class *********************************************************/
e8e40640deaea2e9002e1bf9cf4944e2590c6e7avboxsync static bool patternMatch(const char *pszPat, const char *pszName,
e8e40640deaea2e9002e1bf9cf4944e2590c6e7avboxsync bool fSeenColon = false);
6c6531128b39093daeac902a8705c0bdf15b31ccvboxsync bool match(const ComPtr<IUnknown> object, const RTCString &name) const;
6c6531128b39093daeac902a8705c0bdf15b31ccvboxsync typedef std::pair<const ComPtr<IUnknown>, const RTCString> FilterElement;
fe06619ae576367ff3568e6abd99fb8ad28cc73avboxsync void processMetricList(const com::Utf8Str &name, const ComPtr<IUnknown> object);
cb893baebb2af3f4fc9cd613a24d5a25e6687a6cvboxsync#endif /* ___performance_h */
f6adf1a86574758258baa232172c965aed0d848dvboxsync/* vi: set tabstop=4 shiftwidth=4 expandtab: */