1 | /* $Id: PerformanceImpl.h 18252 2009-03-25 12:59:12Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VBox Performance COM class implementation.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2008-2009 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/timer.h>
|
---|
33 | //#endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
34 |
|
---|
35 | #include <list>
|
---|
36 |
|
---|
37 | namespace pm
|
---|
38 | {
|
---|
39 | class Metric;
|
---|
40 | class BaseMetric;
|
---|
41 | class CollectorHAL;
|
---|
42 | }
|
---|
43 |
|
---|
44 | #undef min
|
---|
45 | #undef max
|
---|
46 |
|
---|
47 | /* Each second we obtain new CPU load stats. */
|
---|
48 | #define VBOX_USAGE_SAMPLER_MIN_INTERVAL 1000
|
---|
49 |
|
---|
50 | class Machine;
|
---|
51 | class HostUSBDevice;
|
---|
52 |
|
---|
53 | class ATL_NO_VTABLE PerformanceMetric :
|
---|
54 | public VirtualBoxBaseNEXT,
|
---|
55 | public VirtualBoxSupportTranslation <PerformanceMetric>,
|
---|
56 | public IPerformanceMetric
|
---|
57 | {
|
---|
58 | public:
|
---|
59 |
|
---|
60 | DECLARE_NOT_AGGREGATABLE (PerformanceMetric)
|
---|
61 |
|
---|
62 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
63 |
|
---|
64 | BEGIN_COM_MAP (PerformanceMetric)
|
---|
65 | COM_INTERFACE_ENTRY (IPerformanceMetric)
|
---|
66 | END_COM_MAP()
|
---|
67 |
|
---|
68 | NS_DECL_ISUPPORTS
|
---|
69 |
|
---|
70 | DECLARE_EMPTY_CTOR_DTOR (PerformanceMetric)
|
---|
71 |
|
---|
72 | HRESULT FinalConstruct();
|
---|
73 | void FinalRelease();
|
---|
74 |
|
---|
75 | // public initializer/uninitializer for internal purposes only
|
---|
76 | HRESULT init (pm::Metric *aMetric);
|
---|
77 | HRESULT init (pm::BaseMetric *aMetric);
|
---|
78 | void uninit();
|
---|
79 |
|
---|
80 | // IPerformanceMetric properties
|
---|
81 | STDMETHOD(COMGETTER(MetricName)) (BSTR *aMetricName);
|
---|
82 | STDMETHOD(COMGETTER(Object)) (IUnknown **anObject);
|
---|
83 | STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
|
---|
84 | STDMETHOD(COMGETTER(Period)) (ULONG *aPeriod);
|
---|
85 | STDMETHOD(COMGETTER(Count)) (ULONG *aCount);
|
---|
86 | STDMETHOD(COMGETTER(Unit)) (BSTR *aUnit);
|
---|
87 | STDMETHOD(COMGETTER(MinimumValue)) (LONG *aMinValue);
|
---|
88 | STDMETHOD(COMGETTER(MaximumValue)) (LONG *aMaxValue);
|
---|
89 |
|
---|
90 | // IPerformanceMetric methods
|
---|
91 |
|
---|
92 | // public methods only for internal purposes
|
---|
93 |
|
---|
94 | // public methods for internal purposes only
|
---|
95 | // (ensure there is a caller and a read lock before calling them!)
|
---|
96 |
|
---|
97 | private:
|
---|
98 |
|
---|
99 | struct Data
|
---|
100 | {
|
---|
101 | /* Constructor. */
|
---|
102 | Data()
|
---|
103 | : period(0), count(0), min(0), max(0)
|
---|
104 | {
|
---|
105 | }
|
---|
106 |
|
---|
107 | Bstr name;
|
---|
108 | ComPtr<IUnknown> object;
|
---|
109 | Bstr description;
|
---|
110 | ULONG period;
|
---|
111 | ULONG count;
|
---|
112 | Bstr unit;
|
---|
113 | LONG min;
|
---|
114 | LONG max;
|
---|
115 | };
|
---|
116 |
|
---|
117 | Data m;
|
---|
118 | };
|
---|
119 |
|
---|
120 |
|
---|
121 | class ATL_NO_VTABLE PerformanceCollector :
|
---|
122 | public VirtualBoxBaseNEXT,
|
---|
123 | public VirtualBoxSupportErrorInfoImpl <PerformanceCollector, IPerformanceCollector>,
|
---|
124 | public VirtualBoxSupportTranslation <PerformanceCollector>,
|
---|
125 | public IPerformanceCollector
|
---|
126 | {
|
---|
127 | public:
|
---|
128 |
|
---|
129 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (PerformanceCollector)
|
---|
130 |
|
---|
131 | DECLARE_NOT_AGGREGATABLE (PerformanceCollector)
|
---|
132 |
|
---|
133 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
134 |
|
---|
135 | BEGIN_COM_MAP(PerformanceCollector)
|
---|
136 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
137 | COM_INTERFACE_ENTRY(IPerformanceCollector)
|
---|
138 | END_COM_MAP()
|
---|
139 |
|
---|
140 | NS_DECL_ISUPPORTS
|
---|
141 |
|
---|
142 | DECLARE_EMPTY_CTOR_DTOR (PerformanceCollector)
|
---|
143 |
|
---|
144 | HRESULT FinalConstruct();
|
---|
145 | void FinalRelease();
|
---|
146 |
|
---|
147 | // public initializers/uninitializers only for internal purposes
|
---|
148 | HRESULT init();
|
---|
149 | void uninit();
|
---|
150 |
|
---|
151 | // IPerformanceCollector properties
|
---|
152 | STDMETHOD(COMGETTER(MetricNames)) (ComSafeArrayOut (BSTR, metricNames));
|
---|
153 |
|
---|
154 | // IPerformanceCollector methods
|
---|
155 | STDMETHOD(GetMetrics) (ComSafeArrayIn (IN_BSTR, metricNames),
|
---|
156 | ComSafeArrayIn (IUnknown *, objects),
|
---|
157 | ComSafeArrayOut (IPerformanceMetric *, outMetrics));
|
---|
158 | STDMETHOD(SetupMetrics) (ComSafeArrayIn (IN_BSTR, metricNames),
|
---|
159 | ComSafeArrayIn (IUnknown *, objects),
|
---|
160 | ULONG aPeriod, ULONG aCount,
|
---|
161 | ComSafeArrayOut (IPerformanceMetric *,
|
---|
162 | outMetrics));
|
---|
163 | STDMETHOD(EnableMetrics) (ComSafeArrayIn (IN_BSTR, metricNames),
|
---|
164 | ComSafeArrayIn (IUnknown *, objects),
|
---|
165 | ComSafeArrayOut (IPerformanceMetric *,
|
---|
166 | outMetrics));
|
---|
167 | STDMETHOD(DisableMetrics) (ComSafeArrayIn (IN_BSTR, metricNames),
|
---|
168 | ComSafeArrayIn (IUnknown *, objects),
|
---|
169 | ComSafeArrayOut (IPerformanceMetric *,
|
---|
170 | outMetrics));
|
---|
171 | STDMETHOD(QueryMetricsData) (ComSafeArrayIn (IN_BSTR, metricNames),
|
---|
172 | ComSafeArrayIn (IUnknown *, objects),
|
---|
173 | ComSafeArrayOut (BSTR, outMetricNames),
|
---|
174 | ComSafeArrayOut (IUnknown *, outObjects),
|
---|
175 | ComSafeArrayOut (BSTR, outUnits),
|
---|
176 | ComSafeArrayOut (ULONG, outScales),
|
---|
177 | ComSafeArrayOut (ULONG, outSequenceNumbers),
|
---|
178 | ComSafeArrayOut (ULONG, outDataIndices),
|
---|
179 | ComSafeArrayOut (ULONG, outDataLengths),
|
---|
180 | ComSafeArrayOut (LONG, outData));
|
---|
181 |
|
---|
182 | // public methods only for internal purposes
|
---|
183 |
|
---|
184 | void registerBaseMetric (pm::BaseMetric *baseMetric);
|
---|
185 | void registerMetric (pm::Metric *metric);
|
---|
186 | void unregisterBaseMetricsFor (const ComPtr <IUnknown> &object);
|
---|
187 | void unregisterMetricsFor (const ComPtr <IUnknown> &object);
|
---|
188 |
|
---|
189 | // public methods for internal purposes only
|
---|
190 | // (ensure there is a caller and a read lock before calling them!)
|
---|
191 |
|
---|
192 | pm::CollectorHAL *getHAL() { return m.hal; };
|
---|
193 |
|
---|
194 | // for VirtualBoxSupportErrorInfoImpl
|
---|
195 | static const wchar_t *getComponentName() { return L"PerformanceCollector"; }
|
---|
196 |
|
---|
197 | private:
|
---|
198 | HRESULT toIPerformanceMetric(pm::Metric *src, IPerformanceMetric **dst);
|
---|
199 | HRESULT toIPerformanceMetric(pm::BaseMetric *src, IPerformanceMetric **dst);
|
---|
200 |
|
---|
201 | static void staticSamplerCallback (RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick);
|
---|
202 | void samplerCallback();
|
---|
203 |
|
---|
204 | typedef std::list<pm::Metric*> MetricList;
|
---|
205 | typedef std::list<pm::BaseMetric*> BaseMetricList;
|
---|
206 |
|
---|
207 | enum
|
---|
208 | {
|
---|
209 | MAGIC = 0xABBA1972u
|
---|
210 | };
|
---|
211 |
|
---|
212 | unsigned int mMagic;
|
---|
213 |
|
---|
214 | struct Data
|
---|
215 | {
|
---|
216 | Data() : hal(0) {};
|
---|
217 |
|
---|
218 | BaseMetricList baseMetrics;
|
---|
219 | MetricList metrics;
|
---|
220 | RTTIMERLR sampler;
|
---|
221 | pm::CollectorHAL *hal;
|
---|
222 | };
|
---|
223 |
|
---|
224 | Data m;
|
---|
225 | };
|
---|
226 |
|
---|
227 | #endif //!____H_PERFORMANCEIMPL
|
---|
228 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|