Performance.h revision e8e40640deaea2e9002e1bf9cf4944e2590c6e7a
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync * VBox Performance Classes declaration.
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync * Copyright (C) 2008 Sun Microsystems, Inc.
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.
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync * additional information or have any questions.
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) {};
83c86878d483df62ca8db465c671995984838338vboxsync SubMetric(const char *name, const char *description)
83c86878d483df62ca8db465c671995984838338vboxsync const char *getDescription() { return mDescription; };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync const char *mName;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync /* Collector Hardware Abstraction Layer *********************************/
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync typedef std::pair<RTPROCESS, HintFlags> ProcessFlagsPair;
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync inline bool processEqual(ProcessFlagsPair pair, RTPROCESS process)
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { findProcess(process).second |= COLLECT_CPU_LOAD; }
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { findProcess(process).second |= COLLECT_RAM_USAGE; }
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { return (findProcess(process).second & COLLECT_CPU_LOAD) != 0; }
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { return (findProcess(process).second & COLLECT_RAM_USAGE) != 0; }
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync void getProcesses(std::vector<RTPROCESS>& processes) const
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync for (ProcessList::const_iterator it = mProcesses.begin(); it != mProcesses.end(); it++)
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync std::bind2nd(std::ptr_fun(processEqual), process));
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync /* Not found -- add new */
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync mProcesses.push_back(ProcessFlagsPair(process, COLLECT_NONE));
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync virtual int preCollect(const CollectorHints& hints) { return VINF_SUCCESS; }
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync virtual int getHostCpuLoad(ULONG *user, ULONG *kernel, ULONG *idle);
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync virtual int getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available) = 0;
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync virtual int getProcessCpuLoad(RTPROCESS process, ULONG *user, ULONG *kernel);
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync virtual int getProcessMemoryUsage(RTPROCESS process, ULONG *used) = 0;
040c9969cc5574339d5f1fa2c95c73da095c151bvboxsync virtual int getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle);
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)
e8a568d25b577fb2ce7213b11c63f71eca1f84c2vboxsync : mHAL(hal), mPeriod(0), mLength(0), mName(name), mObject(object), mLastSampleTaken(0), mEnabled(false) {};
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync virtual void preCollect(CollectorHints& hints) = 0;
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync bool associatedWith(ComPtr<IUnknown> object) { return mObject == object; };
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync const char *mName;
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) {};
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getMaxValue() { return PM_CPU_LOAD_MULTIPLIER; };
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) {};
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync HostCpuMhz(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *mhz)
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync : BaseMetric(hal, "CPU/MHz", object), mMHz(mhz) {};
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync HostRamUsage(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *total, SubMetric *used, SubMetric *available)
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync : BaseMetric(hal, "RAM/Usage", object), mTotal(total), mUsed(used), mAvailable(available) {};
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) {};
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getMaxValue() { return PM_CPU_LOAD_MULTIPLIER; };
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) {};
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync MachineRamUsage(CollectorHAL *hal, ComPtr<IUnknown> object, RTPROCESS process, SubMetric *used)
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync : BaseMetric(hal, "RAM/Usage", object), mProcess(process), mUsed(used) {};
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(); };
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync /* Filter Class *********************************************************/
e8e40640deaea2e9002e1bf9cf4944e2590c6e7avboxsync static bool patternMatch(const char *pszPat, const char *pszName,
e8e40640deaea2e9002e1bf9cf4944e2590c6e7avboxsync bool fSeenColon = false);
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync bool match(const ComPtr<IUnknown> object, const std::string &name) const;
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync typedef std::pair<const ComPtr<IUnknown>, const std::string> FilterElement;
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync void processMetricList(const std::string &name, const ComPtr<IUnknown> object);