VirtualBox

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

Last change on this file since 10779 was 10779, checked in by vboxsync, 16 years ago

Locking. Enabled tests in tstAPI.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1/* $Id: PerformanceImpl.h 10779 2008-07-21 14:29:29Z vboxsync $ */
2
3/** @file
4 *
5 * VBox Performance COM Classes declaration.
6 */
7
8/*
9 * Copyright (C) 2008 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#ifndef ____H_PERFORMANCEIMPL
25#define ____H_PERFORMANCEIMPL
26
27#include "VirtualBoxBase.h"
28
29#include <VBox/com/com.h>
30#include <VBox/com/array.h>
31//#ifdef VBOX_WITH_RESOURCE_USAGE_API
32//#include <iprt/system.h>
33#include <iprt/timer.h>
34//#endif /* VBOX_WITH_RESOURCE_USAGE_API */
35
36#include <list>
37#include <set>
38
39#include "Performance.h"
40
41/* Each second we obtain new CPU load stats. */
42#define VBOX_USAGE_SAMPLER_MIN_INTERVAL 1000
43
44class Machine;
45class HostUSBDevice;
46
47class ATL_NO_VTABLE PerformanceMetric :
48 public VirtualBoxBaseNEXT,
49 public VirtualBoxSupportTranslation <PerformanceMetric>,
50 public IPerformanceMetric
51{
52public:
53
54 DECLARE_NOT_AGGREGATABLE (PerformanceMetric)
55
56 DECLARE_PROTECT_FINAL_CONSTRUCT()
57
58 BEGIN_COM_MAP (PerformanceMetric)
59 COM_INTERFACE_ENTRY (IPerformanceMetric)
60 END_COM_MAP()
61
62 NS_DECL_ISUPPORTS
63
64 DECLARE_EMPTY_CTOR_DTOR (PerformanceMetric)
65
66 HRESULT FinalConstruct();
67 void FinalRelease();
68
69 // public initializer/uninitializer for internal purposes only
70 HRESULT init (pm::Metric *aMetric);
71 void uninit();
72
73 // IPerformanceMetric properties
74 STDMETHOD(COMGETTER(MetricName)) (BSTR *aMetricName);
75 STDMETHOD(COMGETTER(Object)) (IUnknown **anObject);
76 STDMETHOD(COMGETTER(Period)) (ULONG *aPeriod);
77 STDMETHOD(COMGETTER(Count)) (ULONG *aCount);
78 STDMETHOD(COMGETTER(Unit)) (BSTR *aUnit);
79 STDMETHOD(COMGETTER(MinimumValue)) (LONG *aMinValue);
80 STDMETHOD(COMGETTER(MaximumValue)) (LONG *aMaxValue);
81
82 // IPerformanceMetric methods
83
84 // public methods only for internal purposes
85
86 // public methods for internal purposes only
87 // (ensure there is a caller and a read lock before calling them!)
88
89private:
90
91 struct Data
92 {
93 /* Constructor. */
94 Data() : period(0), count(0), min(0), max(0) { }
95
96 Bstr name;
97 ComPtr<IUnknown> object;
98 ULONG period;
99 ULONG count;
100 Bstr unit;
101 LONG min;
102 LONG max;
103 };
104
105 Data m;
106};
107
108
109#if 0
110class ATL_NO_VTABLE PerformanceData :
111 public VirtualBoxBaseNEXT,
112 public VirtualBoxSupportTranslation <PerformanceData>,
113 public IPerformanceData
114{
115private:
116
117 struct Data
118 {
119 /* Constructor. */
120 Data() { }
121
122 bool operator== (const Data &that) const
123 {
124 return this == &that;
125 }
126 };
127
128public:
129
130 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (PerformanceData)
131
132 DECLARE_NOT_AGGREGATABLE (PerformanceData)
133
134 DECLARE_PROTECT_FINAL_CONSTRUCT()
135
136 BEGIN_COM_MAP(PerformanceData)
137 COM_INTERFACE_ENTRY (ISupportErrorInfo)
138 COM_INTERFACE_ENTRY (IPerformanceData)
139 END_COM_MAP()
140
141 NS_DECL_ISUPPORTS
142
143 DECLARE_EMPTY_CTOR_DTOR (PerformanceData)
144
145 HRESULT FinalConstruct();
146 void FinalRelease();
147
148 // public initializer/uninitializer for internal purposes only
149 HRESULT init (cosnt BSTR aMetricName, IUnknown *anObject,
150 ULONG *data, ULONG aLength);
151 void uninit();
152
153 // IPerformanceData properties
154 STDMETHOD(COMGETTER(MetricName)) (BSTR *aMetricName);
155 STDMETHOD(COMGETTER(Object)) (IUnknown **anObject);
156 STDMETHOD(COMGETTER(Values)) (ComSafeArrayOut (LONG, values));
157
158 // IPerformanceData methods
159
160 // public methods only for internal purposes
161
162private:
163
164 Bstr mMetricName;
165 IUnknown *mObject;
166 ULONG *mData;
167 ULONG mLength;
168};
169#endif
170
171class ATL_NO_VTABLE PerformanceCollector :
172 public VirtualBoxBaseNEXT,
173 public VirtualBoxSupportErrorInfoImpl <PerformanceCollector, IPerformanceCollector>,
174 public VirtualBoxSupportTranslation <PerformanceCollector>,
175 public IPerformanceCollector
176{
177public:
178
179 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (PerformanceCollector)
180
181 DECLARE_NOT_AGGREGATABLE (PerformanceCollector)
182
183 DECLARE_PROTECT_FINAL_CONSTRUCT()
184
185 BEGIN_COM_MAP(PerformanceCollector)
186 COM_INTERFACE_ENTRY(ISupportErrorInfo)
187 COM_INTERFACE_ENTRY(IPerformanceCollector)
188 END_COM_MAP()
189
190 NS_DECL_ISUPPORTS
191
192 DECLARE_EMPTY_CTOR_DTOR (PerformanceCollector)
193
194 HRESULT FinalConstruct();
195 void FinalRelease();
196
197 // public initializers/uninitializers only for internal purposes
198 HRESULT init();
199 void uninit();
200
201 // IPerformanceCollector properties
202 STDMETHOD(COMGETTER(MetricNames)) (ComSafeArrayOut (BSTR, metricNames));
203
204 // IPerformanceCollector methods
205 STDMETHOD(GetMetrics) (ComSafeArrayIn (INPTR BSTR, metricNames),
206 ComSafeArrayIn (IUnknown *, objects),
207 ComSafeArrayOut (IPerformanceMetric *, outMetrics));
208 STDMETHOD(SetupMetrics) (ComSafeArrayIn (INPTR BSTR, metricNames),
209 ComSafeArrayIn (IUnknown *, objects),
210 ULONG aPeriod, ULONG aCount);
211 STDMETHOD(EnableMetrics) (ComSafeArrayIn (INPTR BSTR, metricNames),
212 ComSafeArrayIn (IUnknown *, objects));
213 STDMETHOD(DisableMetrics) (ComSafeArrayIn (INPTR BSTR, metricNames),
214 ComSafeArrayIn (IUnknown *, objects));
215 STDMETHOD(QueryMetricsData) (ComSafeArrayIn (INPTR BSTR, metricNames),
216 ComSafeArrayIn (IUnknown *, objects),
217 ComSafeArrayOut (BSTR, outMetricNames),
218 ComSafeArrayOut (IUnknown *, outObjects),
219 ComSafeArrayOut (ULONG, outDataIndices),
220 ComSafeArrayOut (ULONG, outDataLengths),
221 ComSafeArrayOut (LONG, outData));
222
223 // public methods only for internal purposes
224
225 void registerBaseMetric (pm::BaseMetric *baseMetric);
226 void registerMetric (pm::Metric *metric);
227 void unregisterBaseMetricsFor (const ComPtr <IUnknown> &object);
228 void unregisterMetricsFor (const ComPtr <IUnknown> &object);
229
230 // public methods for internal purposes only
231 // (ensure there is a caller and a read lock before calling them!)
232
233 pm::MetricFactory *getMetricFactory() { return m.factory; };
234
235 // for VirtualBoxSupportErrorInfoImpl
236 static const wchar_t *getComponentName() { return L"PerformanceCollector"; }
237
238private:
239
240 static void staticSamplerCallback (PRTTIMER pTimer, void *pvUser, uint64_t iTick);
241 void samplerCallback();
242
243 typedef std::list<pm::Metric*> MetricList;
244 typedef std::list<pm::BaseMetric*> BaseMetricList;
245
246 enum
247 {
248 MAGIC = 0xABBA1972u
249 };
250
251 unsigned int mMagic;
252
253 struct Data
254 {
255 Data() : factory(0) {};
256
257 BaseMetricList baseMetrics;
258 MetricList metrics;
259 PRTTIMER sampler;
260 pm::MetricFactory *factory;
261 };
262
263 Data m;
264};
265
266#endif //!____H_PERFORMANCEIMPL
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