1 | /* $Id: PerformanceImpl.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VBox Performance COM class implementation.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2008-2024 Oracle and/or its affiliates.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox base platform packages, as
|
---|
12 | * available from https://www.virtualbox.org.
|
---|
13 | *
|
---|
14 | * This program is free software; you can redistribute it and/or
|
---|
15 | * modify it under the terms of the GNU General Public License
|
---|
16 | * as published by the Free Software Foundation, in version 3 of the
|
---|
17 | * License.
|
---|
18 | *
|
---|
19 | * This program is distributed in the hope that it will be useful, but
|
---|
20 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
22 | * General Public License for more details.
|
---|
23 | *
|
---|
24 | * You should have received a copy of the GNU General Public License
|
---|
25 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
26 | *
|
---|
27 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef MAIN_INCLUDED_PerformanceImpl_h
|
---|
31 | #define MAIN_INCLUDED_PerformanceImpl_h
|
---|
32 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
33 | # pragma once
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | #include "PerformanceCollectorWrap.h"
|
---|
37 | #include "PerformanceMetricWrap.h"
|
---|
38 |
|
---|
39 | #include <VBox/com/com.h>
|
---|
40 | #include <VBox/com/array.h>
|
---|
41 | //#ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
42 | #include <iprt/timer.h>
|
---|
43 | //#endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
44 |
|
---|
45 | #include <list>
|
---|
46 |
|
---|
47 | namespace pm
|
---|
48 | {
|
---|
49 | class Metric;
|
---|
50 | class BaseMetric;
|
---|
51 | class CollectorHAL;
|
---|
52 | class CollectorGuest;
|
---|
53 | class CollectorGuestManager;
|
---|
54 | }
|
---|
55 |
|
---|
56 | #undef min
|
---|
57 | #undef max
|
---|
58 |
|
---|
59 | /* Each second we obtain new CPU load stats. */
|
---|
60 | #define VBOX_USAGE_SAMPLER_MIN_INTERVAL 1000
|
---|
61 |
|
---|
62 | class ATL_NO_VTABLE PerformanceMetric :
|
---|
63 | public PerformanceMetricWrap
|
---|
64 | {
|
---|
65 | public:
|
---|
66 |
|
---|
67 | DECLARE_COMMON_CLASS_METHODS(PerformanceMetric)
|
---|
68 |
|
---|
69 | HRESULT FinalConstruct();
|
---|
70 | void FinalRelease();
|
---|
71 |
|
---|
72 | // public initializer/uninitializer for internal purposes only
|
---|
73 | HRESULT init(pm::Metric *aMetric);
|
---|
74 | HRESULT init(pm::BaseMetric *aMetric);
|
---|
75 | void uninit();
|
---|
76 |
|
---|
77 | private:
|
---|
78 |
|
---|
79 | // wrapped IPerformanceMetric properties
|
---|
80 | HRESULT getMetricName(com::Utf8Str &aMetricName);
|
---|
81 | HRESULT getObject(ComPtr<IUnknown> &aObject);
|
---|
82 | HRESULT getDescription(com::Utf8Str &aDescription);
|
---|
83 | HRESULT getPeriod(ULONG *aPeriod);
|
---|
84 | HRESULT getCount(ULONG *aCount);
|
---|
85 | HRESULT getUnit(com::Utf8Str &aUnit);
|
---|
86 | HRESULT getMinimumValue(LONG *aMinimumValue);
|
---|
87 | HRESULT getMaximumValue(LONG *aMaximumValue);
|
---|
88 |
|
---|
89 | struct Data
|
---|
90 | {
|
---|
91 | /* Constructor. */
|
---|
92 | Data()
|
---|
93 | : period(0), count(0), min(0), max(0)
|
---|
94 | {
|
---|
95 | }
|
---|
96 |
|
---|
97 | Utf8Str name;
|
---|
98 | ComPtr<IUnknown> object;
|
---|
99 | Utf8Str description;
|
---|
100 | ULONG period;
|
---|
101 | ULONG count;
|
---|
102 | Utf8Str unit;
|
---|
103 | LONG min;
|
---|
104 | LONG max;
|
---|
105 | };
|
---|
106 |
|
---|
107 | Data m;
|
---|
108 | };
|
---|
109 |
|
---|
110 |
|
---|
111 | class ATL_NO_VTABLE PerformanceCollector :
|
---|
112 | public PerformanceCollectorWrap
|
---|
113 | {
|
---|
114 | public:
|
---|
115 |
|
---|
116 | DECLARE_COMMON_CLASS_METHODS(PerformanceCollector)
|
---|
117 |
|
---|
118 | HRESULT FinalConstruct();
|
---|
119 | void FinalRelease();
|
---|
120 |
|
---|
121 | // public initializers/uninitializers only for internal purposes
|
---|
122 | HRESULT init();
|
---|
123 | void uninit();
|
---|
124 |
|
---|
125 | // public methods only for internal purposes
|
---|
126 |
|
---|
127 | void registerBaseMetric(pm::BaseMetric *baseMetric);
|
---|
128 | void registerMetric(pm::Metric *metric);
|
---|
129 | void unregisterBaseMetricsFor(const ComPtr<IUnknown> &object, const Utf8Str name = "*");
|
---|
130 | void unregisterMetricsFor(const ComPtr<IUnknown> &object, const Utf8Str name = "*");
|
---|
131 | void registerGuest(pm::CollectorGuest* pGuest);
|
---|
132 | void unregisterGuest(pm::CollectorGuest* pGuest);
|
---|
133 |
|
---|
134 | void suspendSampling();
|
---|
135 | void resumeSampling();
|
---|
136 |
|
---|
137 | // public methods for internal purposes only
|
---|
138 | // (ensure there is a caller and a read lock before calling them!)
|
---|
139 |
|
---|
140 | pm::CollectorHAL *getHAL() { return m.hal; };
|
---|
141 | pm::CollectorGuestManager *getGuestManager() { return m.gm; };
|
---|
142 |
|
---|
143 | private:
|
---|
144 |
|
---|
145 | // wrapped IPerformanceCollector properties
|
---|
146 | HRESULT getMetricNames(std::vector<com::Utf8Str> &aMetricNames);
|
---|
147 |
|
---|
148 | // wrapped IPerformanceCollector methods
|
---|
149 | HRESULT getMetrics(const std::vector<com::Utf8Str> &aMetricNames,
|
---|
150 | const std::vector<ComPtr<IUnknown> > &aObjects,
|
---|
151 | std::vector<ComPtr<IPerformanceMetric> > &aMetrics);
|
---|
152 | HRESULT setupMetrics(const std::vector<com::Utf8Str> &aMetricNames,
|
---|
153 | const std::vector<ComPtr<IUnknown> > &aObjects,
|
---|
154 | ULONG aPeriod,
|
---|
155 | ULONG aCount,
|
---|
156 | std::vector<ComPtr<IPerformanceMetric> > &aAffectedMetrics);
|
---|
157 | HRESULT enableMetrics(const std::vector<com::Utf8Str> &aMetricNames,
|
---|
158 | const std::vector<ComPtr<IUnknown> > &aObjects,
|
---|
159 | std::vector<ComPtr<IPerformanceMetric> > &aAffectedMetrics);
|
---|
160 | HRESULT disableMetrics(const std::vector<com::Utf8Str> &aMetricNames,
|
---|
161 | const std::vector<ComPtr<IUnknown> > &aObjects,
|
---|
162 | std::vector<ComPtr<IPerformanceMetric> > &aAffectedMetrics);
|
---|
163 | HRESULT queryMetricsData(const std::vector<com::Utf8Str> &aMetricNames,
|
---|
164 | const std::vector<ComPtr<IUnknown> > &aObjects,
|
---|
165 | std::vector<com::Utf8Str> &aReturnMetricNames,
|
---|
166 | std::vector<ComPtr<IUnknown> > &aReturnObjects,
|
---|
167 | std::vector<com::Utf8Str> &aReturnUnits,
|
---|
168 | std::vector<ULONG> &aReturnScales,
|
---|
169 | std::vector<ULONG> &aReturnSequenceNumbers,
|
---|
170 | std::vector<ULONG> &aReturnDataIndices,
|
---|
171 | std::vector<ULONG> &aReturnDataLengths,
|
---|
172 | std::vector<LONG> &aReturnData);
|
---|
173 |
|
---|
174 |
|
---|
175 | HRESULT toIPerformanceMetric(pm::Metric *src, ComPtr<IPerformanceMetric> &dst);
|
---|
176 | HRESULT toIPerformanceMetric(pm::BaseMetric *src, ComPtr<IPerformanceMetric> &dst);
|
---|
177 |
|
---|
178 | static DECLCALLBACK(void) staticSamplerCallback(RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick);
|
---|
179 | void samplerCallback(uint64_t iTick);
|
---|
180 |
|
---|
181 | const Utf8Str& getFailedGuestName();
|
---|
182 |
|
---|
183 | typedef std::list<pm::Metric*> MetricList;
|
---|
184 | typedef std::list<pm::BaseMetric*> BaseMetricList;
|
---|
185 |
|
---|
186 | /** PerformanceMetric::mMagic value. */
|
---|
187 | #define PERFORMANCE_METRIC_MAGIC UINT32_C(0xABBA1972)
|
---|
188 | uint32_t mMagic;
|
---|
189 | const Utf8Str mUnknownGuest;
|
---|
190 |
|
---|
191 | struct Data
|
---|
192 | {
|
---|
193 | Data() : hal(0) {};
|
---|
194 |
|
---|
195 | BaseMetricList baseMetrics;
|
---|
196 | MetricList metrics;
|
---|
197 | RTTIMERLR sampler;
|
---|
198 | pm::CollectorHAL *hal;
|
---|
199 | pm::CollectorGuestManager *gm;
|
---|
200 | };
|
---|
201 |
|
---|
202 | Data m;
|
---|
203 | };
|
---|
204 |
|
---|
205 | #endif /* !MAIN_INCLUDED_PerformanceImpl_h */
|
---|
206 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|