VirtualBox

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

Last change on this file since 10713 was 10713, checked in by vboxsync, 17 years ago

Perf API: aggregators, data collection, Host RAM metrics, Linux RAM metrics, and more

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
1/* $Id: PerformanceImpl.h 10713 2008-07-16 20:28:43Z 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.215389.xyz. 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{
52private:
53
54 struct Data
55 {
56 /* Constructor. */
57 Data() { }
58
59 bool operator== (const Data &that) const
60 {
61 return this == &that;
62 }
63 };
64
65public:
66
67 DECLARE_NOT_AGGREGATABLE (PerformanceMetric)
68
69 DECLARE_PROTECT_FINAL_CONSTRUCT()
70
71 BEGIN_COM_MAP (PerformanceMetric)
72 COM_INTERFACE_ENTRY (IPerformanceMetric)
73 END_COM_MAP()
74
75 NS_DECL_ISUPPORTS
76
77 DECLARE_EMPTY_CTOR_DTOR (PerformanceMetric)
78
79 HRESULT FinalConstruct();
80 void FinalRelease();
81
82 // public initializer/uninitializer for internal purposes only
83 HRESULT init (pm::Metric *aMetric);
84 void uninit();
85
86 // IPerformanceMetric properties
87 STDMETHOD(COMGETTER(MetricName)) (BSTR *aMetricName);
88 STDMETHOD(COMGETTER(Object)) (IUnknown **anObject);
89 STDMETHOD(COMGETTER(Period)) (unsigned long *aPeriod);
90 STDMETHOD(COMGETTER(Count)) (unsigned long *aCount);
91 STDMETHOD(COMGETTER(Unit)) (BSTR *aUnit);
92 STDMETHOD(COMGETTER(MinValue)) (long *aMinValue);
93 STDMETHOD(COMGETTER(MaxValue)) (long *aMaxValue);
94
95 // IPerformanceMetric methods
96
97 // public methods only for internal purposes
98
99 // public methods for internal purposes only
100 // (ensure there is a caller and a read lock before calling them!)
101
102private:
103
104 pm::Metric *mMetric;
105};
106
107
108#if 0
109class ATL_NO_VTABLE PerformanceData :
110 public VirtualBoxBaseNEXT,
111 public VirtualBoxSupportTranslation <PerformanceData>,
112 public IPerformanceData
113{
114private:
115
116 struct Data
117 {
118 /* Constructor. */
119 Data() { }
120
121 bool operator== (const Data &that) const
122 {
123 return this == &that;
124 }
125 };
126
127public:
128
129 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (PerformanceData)
130
131 DECLARE_NOT_AGGREGATABLE (PerformanceData)
132
133 DECLARE_PROTECT_FINAL_CONSTRUCT()
134
135 BEGIN_COM_MAP(PerformanceData)
136 COM_INTERFACE_ENTRY (ISupportErrorInfo)
137 COM_INTERFACE_ENTRY (IPerformanceData)
138 END_COM_MAP()
139
140 NS_DECL_ISUPPORTS
141
142 DECLARE_EMPTY_CTOR_DTOR (PerformanceData)
143
144 HRESULT FinalConstruct();
145 void FinalRelease();
146
147 // public initializer/uninitializer for internal purposes only
148 HRESULT init (cosnt BSTR aMetricName, IUnknown *anObject,
149 ULONG *data, ULONG aLength);
150 void uninit();
151
152 // IPerformanceData properties
153 STDMETHOD(COMGETTER(MetricName)) (BSTR *aMetricName);
154 STDMETHOD(COMGETTER(Object)) (IUnknown **anObject);
155 STDMETHOD(COMGETTER(Values)) (ComSafeArrayOut (LONG, values));
156
157 // IPerformanceData methods
158
159 // public methods only for internal purposes
160
161private:
162
163 Bstr mMetricName;
164 IUnknown *mObject;
165 ULONG *mData;
166 ULONG mLength;
167};
168#endif
169
170class ATL_NO_VTABLE PerformanceCollector :
171 public VirtualBoxBaseNEXT,
172 public VirtualBoxSupportErrorInfoImpl <PerformanceCollector, IPerformanceCollector>,
173 public VirtualBoxSupportTranslation <PerformanceCollector>,
174 public IPerformanceCollector
175{
176public:
177
178 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (PerformanceCollector)
179
180 DECLARE_NOT_AGGREGATABLE (PerformanceCollector)
181
182 DECLARE_PROTECT_FINAL_CONSTRUCT()
183
184 BEGIN_COM_MAP(PerformanceCollector)
185 COM_INTERFACE_ENTRY(ISupportErrorInfo)
186 COM_INTERFACE_ENTRY(IPerformanceCollector)
187 END_COM_MAP()
188
189 NS_DECL_ISUPPORTS
190
191 DECLARE_EMPTY_CTOR_DTOR (PerformanceCollector)
192
193 HRESULT FinalConstruct();
194 void FinalRelease();
195
196 // public initializers/uninitializers only for internal purposes
197 HRESULT init();
198 void uninit();
199
200 // IPerformanceCollector properties
201 STDMETHOD(COMGETTER(MetricNames)) (ComSafeArrayOut (BSTR, metricNames));
202
203 // IPerformanceCollector methods
204 STDMETHOD(GetMetrics) (ComSafeArrayIn (const BSTR, metricNames),
205 ComSafeArrayIn (IUnknown *, objects),
206 ComSafeArrayOut (IPerformanceMetric *, metrics));
207 STDMETHOD(SetupMetrics) (ComSafeArrayIn (INPTR BSTR, metricNames),
208 ComSafeArrayIn (IUnknown *, objects),
209 ULONG aPeriod, ULONG aCount);
210 STDMETHOD(EnableMetrics) (ComSafeArrayIn (const BSTR, metricNames),
211 ComSafeArrayIn (IUnknown *, objects));
212 STDMETHOD(DisableMetrics) (ComSafeArrayIn (const BSTR, metricNames),
213 ComSafeArrayIn (IUnknown *, objects));
214 STDMETHOD(QueryMetricsData) (ComSafeArrayIn (const BSTR, metricNames),
215 ComSafeArrayIn (IUnknown *, objects),
216 ComSafeArrayOut (BSTR, outMetricNames),
217 ComSafeArrayOut (IUnknown *, outObjects),
218 ComSafeArrayOut (ULONG, outDataIndices),
219 ComSafeArrayOut (ULONG, outDataLengths),
220 ComSafeArrayOut (LONG, outData));
221
222 // public methods only for internal purposes
223
224 void registerBaseMetric (pm::BaseMetric *baseMetric);
225 void registerMetric (pm::Metric *metric);
226 void unregisterBaseMetricsFor (const ComPtr <IUnknown> &object);
227 void unregisterMetricsFor (const ComPtr <IUnknown> &object);
228
229 // public methods for internal purposes only
230 // (ensure there is a caller and a read lock before calling them!)
231 //
232 pm::MetricFactory *getMetricFactory() { return m.mFactory; };
233
234 // for VirtualBoxSupportErrorInfoImpl
235 static const wchar_t *getComponentName() { return L"PerformanceCollector"; }
236
237private:
238
239 static void staticSamplerCallback (PRTTIMER pTimer, void *pvUser, uint64_t iTick);
240 void samplerCallback();
241
242 typedef std::list<pm::Metric*> MetricList;
243 typedef std::list<pm::BaseMetric*> BaseMetricList;
244
245 enum
246 {
247 MAGIC = 0xABBA1972u
248 };
249
250 unsigned int mMagic;
251
252 struct Data {
253 Data() : mFactory(0) {};
254
255 BaseMetricList mBaseMetrics;
256 MetricList mMetrics;
257 PRTTIMER mSampler;
258 pm::MetricFactory *mFactory;
259 } m;
260};
261
262#endif //!____H_PERFORMANCEIMPL
Note: See TracBrowser for help on using the repository browser.

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