Performance.h revision e8e40640deaea2e9002e1bf9cf4944e2590c6e7a
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync/* $Id$ */
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync/** @file
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync *
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync * VBox Performance Classes declaration.
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync */
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync/*
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync * Copyright (C) 2008 Sun Microsystems, Inc.
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync *
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 *
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.
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync */
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync#include <iprt/types.h>
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync#include <VBox/com/defs.h>
391cf11262671da62bcc02db361038e7ffbab8f7vboxsync#include <VBox/com/ptr.h>
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync#include <algorithm>
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync#include <list>
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync#include <string>
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync#include <vector>
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
615105a2b89b7dd89a76504e6a9b8e099704c0d9vboxsyncnamespace pm
615105a2b89b7dd89a76504e6a9b8e099704c0d9vboxsync{
391cf11262671da62bcc02db361038e7ffbab8f7vboxsync /* CPU load is measured in 1/1000 of per cent. */
391cf11262671da62bcc02db361038e7ffbab8f7vboxsync const uint64_t PM_CPU_LOAD_MULTIPLIER = UINT64_C(100000);
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync /* Sub Metrics **********************************************************/
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class CircularBuffer
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync CircularBuffer() : mData(0), mLength(0), mEnd(0), mWrapped(false) {};
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync void init(ULONG length);
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG length();
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync void put(ULONG value);
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync void copyTo(ULONG *data);
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync private:
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG *mData;
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG mLength;
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG mEnd;
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync bool mWrapped;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class SubMetric : public CircularBuffer
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
83c86878d483df62ca8db465c671995984838338vboxsync SubMetric(const char *name, const char *description)
83c86878d483df62ca8db465c671995984838338vboxsync : mName(name), mDescription(description) {};
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync void query(ULONG *data);
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync const char *getName() { return mName; };
83c86878d483df62ca8db465c671995984838338vboxsync const char *getDescription() { return mDescription; };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync private:
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync const char *mName;
83c86878d483df62ca8db465c671995984838338vboxsync const char *mDescription;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync /* Collector Hardware Abstraction Layer *********************************/
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync enum {
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync COLLECT_NONE = 0x0,
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync COLLECT_CPU_LOAD = 0x1,
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync COLLECT_RAM_USAGE = 0x2
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync };
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync typedef int HintFlags;
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync typedef std::pair<RTPROCESS, HintFlags> ProcessFlagsPair;
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync inline bool processEqual(ProcessFlagsPair pair, RTPROCESS process)
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync {
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync return pair.first == process;
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync }
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync class CollectorHints
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync {
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync public:
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync typedef std::list<ProcessFlagsPair> ProcessList;
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync CollectorHints() : mHostFlags(COLLECT_NONE) {}
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync void collectHostCpuLoad()
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { mHostFlags |= COLLECT_CPU_LOAD; }
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync void collectHostRamUsage()
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { mHostFlags |= COLLECT_RAM_USAGE; }
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync void collectProcessCpuLoad(RTPROCESS process)
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { findProcess(process).second |= COLLECT_CPU_LOAD; }
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync void collectProcessRamUsage(RTPROCESS process)
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { findProcess(process).second |= COLLECT_RAM_USAGE; }
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync bool isHostCpuLoadCollected() const
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { return (mHostFlags & COLLECT_CPU_LOAD) != 0; }
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync bool isHostRamUsageCollected() const
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { return (mHostFlags & COLLECT_RAM_USAGE) != 0; }
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync bool isProcessCpuLoadCollected(RTPROCESS process)
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { return (findProcess(process).second & COLLECT_CPU_LOAD) != 0; }
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync bool isProcessRamUsageCollected(RTPROCESS process)
e120ca0501a41ca43369b7ba984f4db2f720bdc8vboxsync { return (findProcess(process).second & COLLECT_RAM_USAGE) != 0; }
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync void getProcesses(std::vector<RTPROCESS>& processes) const
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync {
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync processes.clear();
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync processes.reserve(mProcesses.size());
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync for (ProcessList::const_iterator it = mProcesses.begin(); it != mProcesses.end(); it++)
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync processes.push_back(it->first);
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync }
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync const ProcessList& getProcessFlags() const
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync {
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync return mProcesses;
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync }
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync private:
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync HintFlags mHostFlags;
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync ProcessList mProcesses;
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync ProcessFlagsPair& findProcess(RTPROCESS process)
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync {
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync ProcessList::iterator it;
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync it = std::find_if(mProcesses.begin(),
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync mProcesses.end(),
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync std::bind2nd(std::ptr_fun(processEqual), process));
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync if (it != mProcesses.end())
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync return *it;
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync /* Not found -- add new */
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync mProcesses.push_back(ProcessFlagsPair(process, COLLECT_NONE));
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync return mProcesses.back();
4dee4a4f4ff664b16f478e200e0d231407a2b097vboxsync }
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync };
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class CollectorHAL
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
4ffdae046e05f397b6552d5489685f5802bbd249vboxsync virtual ~CollectorHAL() { };
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync virtual int preCollect(const CollectorHints& hints) { return VINF_SUCCESS; }
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync virtual int getHostCpuLoad(ULONG *user, ULONG *kernel, ULONG *idle);
a793a1290646210f7c65639476ca920f8ab20eb4vboxsync virtual int getHostCpuMHz(ULONG *mhz);
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;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
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 };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync extern CollectorHAL *createHAL();
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync /* Base Metrics *********************************************************/
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class BaseMetric
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
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) {};
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync virtual void init(ULONG period, ULONG length) = 0;
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync virtual void preCollect(CollectorHints& hints) = 0;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync virtual void collect() = 0;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync virtual const char *getUnit() = 0;
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync virtual ULONG getMinValue() = 0;
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync virtual ULONG getMaxValue() = 0;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync bool collectorBeat(uint64_t nowAt);
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync void enable() { mEnabled = true; };
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync void disable() { mEnabled = false; };
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync bool isEnabled() { return mEnabled; };
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getPeriod() { return mPeriod; };
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getLength() { return mLength; };
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync const char *getName() { return mName; };
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync ComPtr<IUnknown> getObject() { return mObject; };
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync bool associatedWith(ComPtr<IUnknown> object) { return mObject == object; };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync protected:
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync CollectorHAL *mHAL;
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG mPeriod;
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG mLength;
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync const char *mName;
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync ComPtr<IUnknown> mObject;
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync uint64_t mLastSampleTaken;
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync bool mEnabled;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync };
615105a2b89b7dd89a76504e6a9b8e099704c0d9vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class HostCpuLoad : public BaseMetric
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
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 void init(ULONG period, ULONG length);
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync void collect();
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync const char *getUnit() { return "%"; };
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getMinValue() { return 0; };
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getMaxValue() { return PM_CPU_LOAD_MULTIPLIER; };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync protected:
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync SubMetric *mUser;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync SubMetric *mKernel;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync SubMetric *mIdle;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync };
615105a2b89b7dd89a76504e6a9b8e099704c0d9vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class HostCpuLoadRaw : public HostCpuLoad
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
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) {};
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync void preCollect(CollectorHints& hints);
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync void collect();
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync private:
040c9969cc5574339d5f1fa2c95c73da095c151bvboxsync uint64_t mUserPrev;
040c9969cc5574339d5f1fa2c95c73da095c151bvboxsync uint64_t mKernelPrev;
040c9969cc5574339d5f1fa2c95c73da095c151bvboxsync uint64_t mIdlePrev;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class HostCpuMhz : public BaseMetric
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync HostCpuMhz(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *mhz)
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync : BaseMetric(hal, "CPU/MHz", object), mMHz(mhz) {};
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync void init(ULONG period, ULONG length);
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync void preCollect(CollectorHints& hints) {}
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync void collect();
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync const char *getUnit() { return "MHz"; };
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getMinValue() { return 0; };
e8a568d25b577fb2ce7213b11c63f71eca1f84c2vboxsync ULONG getMaxValue() { return INT32_MAX; };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync private:
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync SubMetric *mMHz;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync };
615105a2b89b7dd89a76504e6a9b8e099704c0d9vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class HostRamUsage : public BaseMetric
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
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) {};
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync void init(ULONG period, ULONG length);
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync void preCollect(CollectorHints& hints);
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync void collect();
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync const char *getUnit() { return "kB"; };
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getMinValue() { return 0; };
e8a568d25b577fb2ce7213b11c63f71eca1f84c2vboxsync ULONG getMaxValue() { return INT32_MAX; };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync private:
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync SubMetric *mTotal;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync SubMetric *mUsed;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync SubMetric *mAvailable;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync };
615105a2b89b7dd89a76504e6a9b8e099704c0d9vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class MachineCpuLoad : public BaseMetric
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
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) {};
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync void init(ULONG period, ULONG length);
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync void collect();
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync const char *getUnit() { return "%"; };
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getMinValue() { return 0; };
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getMaxValue() { return PM_CPU_LOAD_MULTIPLIER; };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync protected:
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync RTPROCESS mProcess;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync SubMetric *mUser;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync SubMetric *mKernel;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync };
615105a2b89b7dd89a76504e6a9b8e099704c0d9vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class MachineCpuLoadRaw : public MachineCpuLoad
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
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) {};
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync void preCollect(CollectorHints& hints);
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync void collect();
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync private:
040c9969cc5574339d5f1fa2c95c73da095c151bvboxsync uint64_t mHostTotalPrev;
040c9969cc5574339d5f1fa2c95c73da095c151bvboxsync uint64_t mProcessUserPrev;
040c9969cc5574339d5f1fa2c95c73da095c151bvboxsync uint64_t mProcessKernelPrev;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class MachineRamUsage : public BaseMetric
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync MachineRamUsage(CollectorHAL *hal, ComPtr<IUnknown> object, RTPROCESS process, SubMetric *used)
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync : BaseMetric(hal, "RAM/Usage", object), mProcess(process), mUsed(used) {};
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync void init(ULONG period, ULONG length);
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync void preCollect(CollectorHints& hints);
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync void collect();
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync const char *getUnit() { return "kB"; };
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync ULONG getMinValue() { return 0; };
e8a568d25b577fb2ce7213b11c63f71eca1f84c2vboxsync ULONG getMaxValue() { return INT32_MAX; };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync private:
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync RTPROCESS mProcess;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync SubMetric *mUsed;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync /* Aggregate Functions **************************************************/
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class Aggregate
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync virtual ULONG compute(ULONG *data, ULONG length) = 0;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync virtual const char *getName() = 0;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class AggregateAvg : public Aggregate
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync virtual ULONG compute(ULONG *data, ULONG length);
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync virtual const char *getName();
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class AggregateMin : public Aggregate
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync virtual ULONG compute(ULONG *data, ULONG length);
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync virtual const char *getName();
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class AggregateMax : public Aggregate
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync virtual ULONG compute(ULONG *data, ULONG length);
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync virtual const char *getName();
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync /* Metric Class *********************************************************/
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync class Metric
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync public:
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync Metric(BaseMetric *baseMetric, SubMetric *subMetric, Aggregate *aggregate) :
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync mName(subMetric->getName()), mBaseMetric(baseMetric), mSubMetric(subMetric), mAggregate(aggregate)
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync if (mAggregate)
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync mName += ":";
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync mName += mAggregate->getName();
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync }
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync }
615105a2b89b7dd89a76504e6a9b8e099704c0d9vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync ~Metric()
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync {
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync delete mAggregate;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync }
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync bool associatedWith(ComPtr<IUnknown> object) { return getObject() == object; };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync const char *getName() { return mName.c_str(); };
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync ComPtr<IUnknown> getObject() { return mBaseMetric->getObject(); };
83c86878d483df62ca8db465c671995984838338vboxsync const char *getDescription()
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 ULONG getLength()
83c86878d483df62ca8db465c671995984838338vboxsync { return mAggregate ? 1 : mBaseMetric->getLength(); };
5413a6a2dab50ebebc702aa2ae7d8059dcd09c9cvboxsync void query(ULONG **data, ULONG *count);
615105a2b89b7dd89a76504e6a9b8e099704c0d9vboxsync
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync private:
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync std::string mName;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync BaseMetric *mBaseMetric;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync SubMetric *mSubMetric;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync Aggregate *mAggregate;
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync
1f277e5b999f572b1ef1fe4ef593c603ea463be3vboxsync /* Filter Class *********************************************************/
391cf11262671da62bcc02db361038e7ffbab8f7vboxsync
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync class Filter
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync {
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync public:
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync Filter(ComSafeArrayIn(INPTR BSTR, metricNames),
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync ComSafeArrayIn(IUnknown * , objects));
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;
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync private:
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync typedef std::pair<const ComPtr<IUnknown>, const std::string> FilterElement;
30f7bd6bf198ae0489df375e5a17cb086acb30fbvboxsync typedef std::list<FilterElement> ElementList;
30f7bd6bf198ae0489df375e5a17cb086acb30fbvboxsync
30f7bd6bf198ae0489df375e5a17cb086acb30fbvboxsync ElementList mElements;
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync
6c5e2fff0e3fdfc7c3f3fb2e7b7ec8ebb2223cecvboxsync void processMetricList(const std::string &name, const ComPtr<IUnknown> object);
f2fedb6cbb946e9dd6d418b1472373395e2ac34fvboxsync };
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync}
05c28d9d4557bed6e320dfee1acca69408bc3c15vboxsync