/* $Id: PerformanceImpl.h 106061 2024-09-16 14:03:52Z vboxsync $ */ /** @file * * VBox Performance COM class implementation. */ /* * Copyright (C) 2008-2024 Oracle and/or its affiliates. * * This file is part of VirtualBox base platform packages, as * available from https://www.virtualbox.org. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, in version 3 of the * License. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . * * SPDX-License-Identifier: GPL-3.0-only */ #ifndef MAIN_INCLUDED_PerformanceImpl_h #define MAIN_INCLUDED_PerformanceImpl_h #ifndef RT_WITHOUT_PRAGMA_ONCE # pragma once #endif #include "PerformanceCollectorWrap.h" #include "PerformanceMetricWrap.h" #include #include //#ifdef VBOX_WITH_RESOURCE_USAGE_API #include //#endif /* VBOX_WITH_RESOURCE_USAGE_API */ #include namespace pm { class Metric; class BaseMetric; class CollectorHAL; class CollectorGuest; class CollectorGuestManager; } #undef min #undef max /* Each second we obtain new CPU load stats. */ #define VBOX_USAGE_SAMPLER_MIN_INTERVAL 1000 class ATL_NO_VTABLE PerformanceMetric : public PerformanceMetricWrap { public: DECLARE_COMMON_CLASS_METHODS(PerformanceMetric) HRESULT FinalConstruct(); void FinalRelease(); // public initializer/uninitializer for internal purposes only HRESULT init(pm::Metric *aMetric); HRESULT init(pm::BaseMetric *aMetric); void uninit(); private: // wrapped IPerformanceMetric properties HRESULT getMetricName(com::Utf8Str &aMetricName); HRESULT getObject(ComPtr &aObject); HRESULT getDescription(com::Utf8Str &aDescription); HRESULT getPeriod(ULONG *aPeriod); HRESULT getCount(ULONG *aCount); HRESULT getUnit(com::Utf8Str &aUnit); HRESULT getMinimumValue(LONG *aMinimumValue); HRESULT getMaximumValue(LONG *aMaximumValue); struct Data { /* Constructor. */ Data() : period(0), count(0), min(0), max(0) { } Utf8Str name; ComPtr object; Utf8Str description; ULONG period; ULONG count; Utf8Str unit; LONG min; LONG max; }; Data m; }; class ATL_NO_VTABLE PerformanceCollector : public PerformanceCollectorWrap { public: DECLARE_COMMON_CLASS_METHODS(PerformanceCollector) HRESULT FinalConstruct(); void FinalRelease(); // public initializers/uninitializers only for internal purposes HRESULT init(); void uninit(); // public methods only for internal purposes void registerBaseMetric(pm::BaseMetric *baseMetric); void registerMetric(pm::Metric *metric); void unregisterBaseMetricsFor(const ComPtr &object, const Utf8Str name = "*"); void unregisterMetricsFor(const ComPtr &object, const Utf8Str name = "*"); void registerGuest(pm::CollectorGuest* pGuest); void unregisterGuest(pm::CollectorGuest* pGuest); void suspendSampling(); void resumeSampling(); // public methods for internal purposes only // (ensure there is a caller and a read lock before calling them!) pm::CollectorHAL *getHAL() { return m.hal; }; pm::CollectorGuestManager *getGuestManager() { return m.gm; }; private: // wrapped IPerformanceCollector properties HRESULT getMetricNames(std::vector &aMetricNames); // wrapped IPerformanceCollector methods HRESULT getMetrics(const std::vector &aMetricNames, const std::vector > &aObjects, std::vector > &aMetrics); HRESULT setupMetrics(const std::vector &aMetricNames, const std::vector > &aObjects, ULONG aPeriod, ULONG aCount, std::vector > &aAffectedMetrics); HRESULT enableMetrics(const std::vector &aMetricNames, const std::vector > &aObjects, std::vector > &aAffectedMetrics); HRESULT disableMetrics(const std::vector &aMetricNames, const std::vector > &aObjects, std::vector > &aAffectedMetrics); HRESULT queryMetricsData(const std::vector &aMetricNames, const std::vector > &aObjects, std::vector &aReturnMetricNames, std::vector > &aReturnObjects, std::vector &aReturnUnits, std::vector &aReturnScales, std::vector &aReturnSequenceNumbers, std::vector &aReturnDataIndices, std::vector &aReturnDataLengths, std::vector &aReturnData); HRESULT toIPerformanceMetric(pm::Metric *src, ComPtr &dst); HRESULT toIPerformanceMetric(pm::BaseMetric *src, ComPtr &dst); static DECLCALLBACK(void) staticSamplerCallback(RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick); void samplerCallback(uint64_t iTick); const Utf8Str& getFailedGuestName(); typedef std::list MetricList; typedef std::list BaseMetricList; /** PerformanceMetric::mMagic value. */ #define PERFORMANCE_METRIC_MAGIC UINT32_C(0xABBA1972) uint32_t mMagic; const Utf8Str mUnknownGuest; struct Data { Data() : hal(0) {}; BaseMetricList baseMetrics; MetricList metrics; RTTIMERLR sampler; pm::CollectorHAL *hal; pm::CollectorGuestManager *gm; }; Data m; }; #endif /* !MAIN_INCLUDED_PerformanceImpl_h */ /* vi: set tabstop=4 shiftwidth=4 expandtab: */