Performance.h revision 1439977563a6d2143201766a0d7c61e50a5acf75
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync * VBox Performance Classes declaration.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2008 Sun Microsystems, Inc.
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync * available from http://www.virtualbox.org. This file is free software;
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync * you can redistribute it and/or modify it under the terms of the GNU
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync * General Public License (GPL) as published by the Free Software
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync * additional information or have any questions.
9986f9bfdcb0055fdb79bbd158f4912ccc3a5751vboxsync#include <functional> /* For std::fun_ptr in testcase */
9986f9bfdcb0055fdb79bbd158f4912ccc3a5751vboxsync /* CPU load is measured in 1/1000 of per cent. */
9986f9bfdcb0055fdb79bbd158f4912ccc3a5751vboxsync const uint64_t PM_CPU_LOAD_MULTIPLIER = UINT64_C(100000);
9986f9bfdcb0055fdb79bbd158f4912ccc3a5751vboxsync /* Sub Metrics **********************************************************/
9986f9bfdcb0055fdb79bbd158f4912ccc3a5751vboxsync CircularBuffer() : mData(0), mLength(0), mEnd(0), mWrapped(false) {};
9986f9bfdcb0055fdb79bbd158f4912ccc3a5751vboxsync ULONG getSequenceNumber() { return mSequenceNumber; }
9986f9bfdcb0055fdb79bbd158f4912ccc3a5751vboxsync SubMetric(const char *name, const char *description)
f7c0f913c4c22ee18059ff97055442566d0f14a1vboxsync const char *getDescription() { return mDescription; };
f7c0f913c4c22ee18059ff97055442566d0f14a1vboxsync const char *mName;
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync /* Collector Hardware Abstraction Layer *********************************/
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync typedef std::pair<RTPROCESS, HintFlags> ProcessFlagsPair;
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync { findProcess(process).second |= COLLECT_CPU_LOAD; }
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync { findProcess(process).second |= COLLECT_RAM_USAGE; }
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync { return (findProcess(process).second & COLLECT_CPU_LOAD) != 0; }
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync { return (findProcess(process).second & COLLECT_RAM_USAGE) != 0; }
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync void getProcesses(std::vector<RTPROCESS>& processes) const
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync for (ProcessList::const_iterator it = mProcesses.begin(); it != mProcesses.end(); it++)
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync for (it = mProcesses.begin(); it != mProcesses.end(); it++)
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync /* Not found -- add new */
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync mProcesses.push_back(ProcessFlagsPair(process, COLLECT_NONE));
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync virtual int preCollect(const CollectorHints& /* hints */) { return VINF_SUCCESS; }
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync /** Returns averaged CPU usage in 1/1000th per cent across all host's CPUs. */
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync virtual int getHostCpuLoad(ULONG *user, ULONG *kernel, ULONG *idle);
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync /** Returns the average frequency in MHz across all host's CPUs. */
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync /** Returns the amount of physical memory in kilobytes. */
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync virtual int getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available) = 0;
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync /** Returns CPU usage in 1/1000th per cent by a particular process. */
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync virtual int getProcessCpuLoad(RTPROCESS process, ULONG *user, ULONG *kernel);
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync /** Returns the amount of memory used by a process in kilobytes. */
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync virtual int getProcessMemoryUsage(RTPROCESS process, ULONG *used) = 0;
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync /** Returns CPU usage counters in platform-specific units. */
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync virtual int getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle);
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync /** Returns process' CPU usage counter in platform-specific units. */
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total);
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync /* Base Metrics *********************************************************/
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync BaseMetric(CollectorHAL *hal, const char *name, ComPtr<IUnknown> object)
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync : mHAL(hal), mPeriod(0), mLength(0), mName(name), mObject(object), mLastSampleTaken(0), mEnabled(false) {};
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync virtual void preCollect(CollectorHints& hints) = 0;
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync bool associatedWith(ComPtr<IUnknown> object) { return mObject == object; };
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync const char *mName;
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync HostCpuLoad(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync : BaseMetric(hal, "CPU/Load", object), mUser(user), mKernel(kernel), mIdle(idle) {};
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync ~HostCpuLoad() { delete mUser; delete mKernel; delete mIdle; };
2c1d8cd8efdd4c486ff681135035d24111b03af8vboxsync ULONG getMaxValue() { return PM_CPU_LOAD_MULTIPLIER; };
2c1d8cd8efdd4c486ff681135035d24111b03af8vboxsync ULONG getScale() { return PM_CPU_LOAD_MULTIPLIER / 100; }
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync HostCpuLoadRaw(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync : HostCpuLoad(hal, object, user, kernel, idle), mUserPrev(0), mKernelPrev(0), mIdlePrev(0) {};
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync HostCpuMhz(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *mhz)
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync : BaseMetric(hal, "CPU/MHz", object), mMHz(mhz) {};
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync HostRamUsage(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *total, SubMetric *used, SubMetric *available)
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync : BaseMetric(hal, "RAM/Usage", object), mTotal(total), mUsed(used), mAvailable(available) {};
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync ~HostRamUsage() { delete mTotal; delete mUsed; delete mAvailable; };
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync MachineCpuLoad(CollectorHAL *hal, ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel)
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync : BaseMetric(hal, "CPU/Load", object), mProcess(process), mUser(user), mKernel(kernel) {};
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync ~MachineCpuLoad() { delete mUser; delete mKernel; };
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync ULONG getMaxValue() { return PM_CPU_LOAD_MULTIPLIER; };
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync ULONG getScale() { return PM_CPU_LOAD_MULTIPLIER / 100; }
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync MachineCpuLoadRaw(CollectorHAL *hal, ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel)
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync : MachineCpuLoad(hal, object, process, user, kernel), mHostTotalPrev(0), mProcessUserPrev(0), mProcessKernelPrev(0) {};
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync MachineRamUsage(CollectorHAL *hal, ComPtr<IUnknown> object, RTPROCESS process, SubMetric *used)
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync : BaseMetric(hal, "RAM/Usage", object), mProcess(process), mUsed(used) {};
885b661364d7f51d087003dccaccb6d24610f654vboxsync GuestCpuLoad(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
885b661364d7f51d087003dccaccb6d24610f654vboxsync : BaseMetric(hal, "CPU/Load", object), mUser(user), mKernel(kernel), mIdle(idle) {};
885b661364d7f51d087003dccaccb6d24610f654vboxsync ~GuestCpuLoad() { delete mUser; delete mKernel; delete mIdle; };
885b661364d7f51d087003dccaccb6d24610f654vboxsync ULONG getMaxValue() { return PM_CPU_LOAD_MULTIPLIER; };
885b661364d7f51d087003dccaccb6d24610f654vboxsync ULONG getScale() { return PM_CPU_LOAD_MULTIPLIER / 100; }
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync GuestRamUsage(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *total, SubMetric *free, SubMetric *balloon, SubMetric *cache, SubMetric *pagedtotal, SubMetric *pagedfree)
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync : BaseMetric(hal, "RAM/Usage", object), mTotal(total), mFree(free), mBallooned(balloon), mCache(cache), mPagedTotal(pagedtotal), mPagedFree(pagedfree) {};
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync ~GuestRamUsage() { delete mTotal; delete mFree; delete mBallooned; delete mCache; delete mPagedTotal; delete mPagedFree; };
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync SubMetric *mTotal, *mFree, *mBallooned, *mCache, *mPagedTotal, *mPagedFree;
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync GuestSystemUsage(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *processes, SubMetric *threads)
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync : BaseMetric(hal, "System/Usage", object), mProcesses(processes), mThreads(threads) {};
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync ~GuestSystemUsage() { delete mProcesses; delete mThreads; };
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync /* Aggregate Functions **************************************************/
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync virtual ULONG compute(ULONG *data, ULONG length) = 0;
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync /* Metric Class *********************************************************/
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync Metric(BaseMetric *baseMetric, SubMetric *subMetric, Aggregate *aggregate) :
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync mName(subMetric->getName()), mBaseMetric(baseMetric), mSubMetric(subMetric), mAggregate(aggregate)
d5bf937d132098565e18a0d1fc408fb777c5e5b6vboxsync bool associatedWith(ComPtr<IUnknown> object) { return getObject() == object; };
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync ComPtr<IUnknown> getObject() { return mBaseMetric->getObject(); };
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync { return mAggregate ? "" : mSubMetric->getDescription(); };
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync const char *getUnit() { return mBaseMetric->getUnit(); };
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync ULONG getMinValue() { return mBaseMetric->getMinValue(); };
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync ULONG getMaxValue() { return mBaseMetric->getMaxValue(); };
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync ULONG getPeriod() { return mBaseMetric->getPeriod(); };
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync { return mAggregate ? 1 : mBaseMetric->getLength(); };
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync ULONG getScale() { return mBaseMetric->getScale(); }
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync void query(ULONG **data, ULONG *count, ULONG *sequenceNumber);
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync /* Filter Class *********************************************************/
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync static bool patternMatch(const char *pszPat, const char *pszName,
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync bool fSeenColon = false);
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync bool match(const ComPtr<IUnknown> object, const iprt::MiniString &name) const;
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync typedef std::pair<const ComPtr<IUnknown>, const iprt::MiniString> FilterElement;
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync void processMetricList(const com::Utf8Str &name, const ComPtr<IUnknown> object);
d84b6107a8e797f41ac2d55bed97b02c91c742e8vboxsync/* vi: set tabstop=4 shiftwidth=4 expandtab: */