VirtualBox

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

Last change on this file since 26044 was 26044, checked in by vboxsync, 15 years ago

Main: move Host::Get{DVD|Floppy}Drives implementation into implementation methods to eliminate useless conversions in mountMedium()

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1/* $Id: PerformanceImpl.h 26044 2010-01-26 12:21:34Z 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
37namespace 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
50class HostUSBDevice;
51
52class ATL_NO_VTABLE PerformanceMetric :
53 public VirtualBoxBase,
54 public VirtualBoxSupportTranslation<PerformanceMetric>,
55 VBOX_SCRIPTABLE_IMPL(IPerformanceMetric)
56{
57public:
58
59 DECLARE_NOT_AGGREGATABLE (PerformanceMetric)
60
61 DECLARE_PROTECT_FINAL_CONSTRUCT()
62
63 BEGIN_COM_MAP (PerformanceMetric)
64 COM_INTERFACE_ENTRY (IPerformanceMetric)
65 COM_INTERFACE_ENTRY (IDispatch)
66 END_COM_MAP()
67
68 DECLARE_EMPTY_CTOR_DTOR (PerformanceMetric)
69
70 HRESULT FinalConstruct();
71 void FinalRelease();
72
73 // public initializer/uninitializer for internal purposes only
74 HRESULT init (pm::Metric *aMetric);
75 HRESULT init (pm::BaseMetric *aMetric);
76 void uninit();
77
78 // IPerformanceMetric properties
79 STDMETHOD(COMGETTER(MetricName)) (BSTR *aMetricName);
80 STDMETHOD(COMGETTER(Object)) (IUnknown **anObject);
81 STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
82 STDMETHOD(COMGETTER(Period)) (ULONG *aPeriod);
83 STDMETHOD(COMGETTER(Count)) (ULONG *aCount);
84 STDMETHOD(COMGETTER(Unit)) (BSTR *aUnit);
85 STDMETHOD(COMGETTER(MinimumValue)) (LONG *aMinValue);
86 STDMETHOD(COMGETTER(MaximumValue)) (LONG *aMaxValue);
87
88 // IPerformanceMetric methods
89
90 // public methods only for internal purposes
91
92 // public methods for internal purposes only
93 // (ensure there is a caller and a read lock before calling them!)
94
95private:
96
97 struct Data
98 {
99 /* Constructor. */
100 Data()
101 : period(0), count(0), min(0), max(0)
102 {
103 }
104
105 Bstr name;
106 ComPtr<IUnknown> object;
107 Bstr description;
108 ULONG period;
109 ULONG count;
110 Bstr unit;
111 LONG min;
112 LONG max;
113 };
114
115 Data m;
116};
117
118
119class ATL_NO_VTABLE PerformanceCollector :
120 public VirtualBoxBase,
121 public VirtualBoxSupportErrorInfoImpl<PerformanceCollector, IPerformanceCollector>,
122 public VirtualBoxSupportTranslation<PerformanceCollector>,
123 VBOX_SCRIPTABLE_IMPL(IPerformanceCollector)
124{
125public:
126
127 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (PerformanceCollector)
128
129 DECLARE_NOT_AGGREGATABLE (PerformanceCollector)
130
131 DECLARE_PROTECT_FINAL_CONSTRUCT()
132
133 BEGIN_COM_MAP(PerformanceCollector)
134 COM_INTERFACE_ENTRY(ISupportErrorInfo)
135 COM_INTERFACE_ENTRY(IPerformanceCollector)
136 COM_INTERFACE_ENTRY(IDispatch)
137 END_COM_MAP()
138
139 DECLARE_EMPTY_CTOR_DTOR (PerformanceCollector)
140
141 HRESULT FinalConstruct();
142 void FinalRelease();
143
144 // public initializers/uninitializers only for internal purposes
145 HRESULT init();
146 void uninit();
147
148 // IPerformanceCollector properties
149 STDMETHOD(COMGETTER(MetricNames)) (ComSafeArrayOut (BSTR, metricNames));
150
151 // IPerformanceCollector methods
152 STDMETHOD(GetMetrics) (ComSafeArrayIn (IN_BSTR, metricNames),
153 ComSafeArrayIn (IUnknown *, objects),
154 ComSafeArrayOut (IPerformanceMetric *, outMetrics));
155 STDMETHOD(SetupMetrics) (ComSafeArrayIn (IN_BSTR, metricNames),
156 ComSafeArrayIn (IUnknown *, objects),
157 ULONG aPeriod, ULONG aCount,
158 ComSafeArrayOut (IPerformanceMetric *,
159 outMetrics));
160 STDMETHOD(EnableMetrics) (ComSafeArrayIn (IN_BSTR, metricNames),
161 ComSafeArrayIn (IUnknown *, objects),
162 ComSafeArrayOut (IPerformanceMetric *,
163 outMetrics));
164 STDMETHOD(DisableMetrics) (ComSafeArrayIn (IN_BSTR, metricNames),
165 ComSafeArrayIn (IUnknown *, objects),
166 ComSafeArrayOut (IPerformanceMetric *,
167 outMetrics));
168 STDMETHOD(QueryMetricsData) (ComSafeArrayIn (IN_BSTR, metricNames),
169 ComSafeArrayIn (IUnknown *, objects),
170 ComSafeArrayOut (BSTR, outMetricNames),
171 ComSafeArrayOut (IUnknown *, outObjects),
172 ComSafeArrayOut (BSTR, outUnits),
173 ComSafeArrayOut (ULONG, outScales),
174 ComSafeArrayOut (ULONG, outSequenceNumbers),
175 ComSafeArrayOut (ULONG, outDataIndices),
176 ComSafeArrayOut (ULONG, outDataLengths),
177 ComSafeArrayOut (LONG, outData));
178
179 // public methods only for internal purposes
180
181 void registerBaseMetric (pm::BaseMetric *baseMetric);
182 void registerMetric (pm::Metric *metric);
183 void unregisterBaseMetricsFor (const ComPtr<IUnknown> &object);
184 void unregisterMetricsFor (const ComPtr<IUnknown> &object);
185
186 void suspendSampling();
187 void resumeSampling();
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
197private:
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: */
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