VirtualBox

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

Last change on this file since 72436 was 69500, checked in by vboxsync, 7 years ago

*: scm --update-copyright-year

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette