VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

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