VirtualBox

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

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

Main: remove SupportErrorInfo template magic

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/* $Id: PerformanceImpl.h 30714 2010-07-07 16:20:03Z 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.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
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 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(PerformanceMetric, IPerformanceMetric)
55
56 DECLARE_NOT_AGGREGATABLE (PerformanceMetric)
57
58 DECLARE_PROTECT_FINAL_CONSTRUCT()
59
60 BEGIN_COM_MAP (PerformanceMetric)
61 COM_INTERFACE_ENTRY (IPerformanceMetric)
62 COM_INTERFACE_ENTRY (IDispatch)
63 END_COM_MAP()
64
65 DECLARE_EMPTY_CTOR_DTOR (PerformanceMetric)
66
67 HRESULT FinalConstruct();
68 void FinalRelease();
69
70 // public initializer/uninitializer for internal purposes only
71 HRESULT init (pm::Metric *aMetric);
72 HRESULT init (pm::BaseMetric *aMetric);
73 void uninit();
74
75 // IPerformanceMetric properties
76 STDMETHOD(COMGETTER(MetricName)) (BSTR *aMetricName);
77 STDMETHOD(COMGETTER(Object)) (IUnknown **anObject);
78 STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
79 STDMETHOD(COMGETTER(Period)) (ULONG *aPeriod);
80 STDMETHOD(COMGETTER(Count)) (ULONG *aCount);
81 STDMETHOD(COMGETTER(Unit)) (BSTR *aUnit);
82 STDMETHOD(COMGETTER(MinimumValue)) (LONG *aMinValue);
83 STDMETHOD(COMGETTER(MaximumValue)) (LONG *aMaxValue);
84
85 // IPerformanceMetric methods
86
87 // public methods only for internal purposes
88
89 // public methods for internal purposes only
90 // (ensure there is a caller and a read lock before calling them!)
91
92private:
93
94 struct Data
95 {
96 /* Constructor. */
97 Data()
98 : period(0), count(0), min(0), max(0)
99 {
100 }
101
102 Bstr name;
103 ComPtr<IUnknown> object;
104 Bstr description;
105 ULONG period;
106 ULONG count;
107 Bstr unit;
108 LONG min;
109 LONG max;
110 };
111
112 Data m;
113};
114
115
116class ATL_NO_VTABLE PerformanceCollector :
117 public VirtualBoxBase,
118 public VirtualBoxSupportTranslation<PerformanceCollector>,
119 VBOX_SCRIPTABLE_IMPL(IPerformanceCollector)
120{
121public:
122
123 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(PerformanceCollector, IPerformanceCollector)
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
190private:
191 HRESULT toIPerformanceMetric(pm::Metric *src, IPerformanceMetric **dst);
192 HRESULT toIPerformanceMetric(pm::BaseMetric *src, IPerformanceMetric **dst);
193
194 static void staticSamplerCallback (RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick);
195 void samplerCallback(uint64_t iTick);
196
197 typedef std::list<pm::Metric*> MetricList;
198 typedef std::list<pm::BaseMetric*> BaseMetricList;
199
200 enum
201 {
202 MAGIC = 0xABBA1972u
203 };
204
205 unsigned int mMagic;
206
207 struct Data
208 {
209 Data() : hal(0) {};
210
211 BaseMetricList baseMetrics;
212 MetricList metrics;
213 RTTIMERLR sampler;
214 pm::CollectorHAL *hal;
215 };
216
217 Data m;
218};
219
220#endif //!____H_PERFORMANCEIMPL
221/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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