VirtualBox

source: vbox/trunk/src/VBox/Main/include/PerformanceImpl.h@ 86506

Last change on this file since 86506 was 82968, checked in by vboxsync, 4 years ago

Copyright year updates by scm.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use