VirtualBox

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

Last change on this file since 34575 was 30764, checked in by vboxsync, 14 years ago

back out r63543, r63544 until windows build problems can be solved properly

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/* $Id: PerformanceImpl.h 30764 2010-07-09 14:12:12Z 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 VBOX_SCRIPTABLE_IMPL(IPerformanceMetric)
51{
52public:
53 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(PerformanceMetric, IPerformanceMetric)
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 VBOX_SCRIPTABLE_IMPL(IPerformanceCollector)
118{
119public:
120
121 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(PerformanceCollector, IPerformanceCollector)
122
123 DECLARE_NOT_AGGREGATABLE (PerformanceCollector)
124
125 DECLARE_PROTECT_FINAL_CONSTRUCT()
126
127 BEGIN_COM_MAP(PerformanceCollector)
128 COM_INTERFACE_ENTRY(ISupportErrorInfo)
129 COM_INTERFACE_ENTRY(IPerformanceCollector)
130 COM_INTERFACE_ENTRY(IDispatch)
131 END_COM_MAP()
132
133 DECLARE_EMPTY_CTOR_DTOR (PerformanceCollector)
134
135 HRESULT FinalConstruct();
136 void FinalRelease();
137
138 // public initializers/uninitializers only for internal purposes
139 HRESULT init();
140 void uninit();
141
142 // IPerformanceCollector properties
143 STDMETHOD(COMGETTER(MetricNames)) (ComSafeArrayOut (BSTR, metricNames));
144
145 // IPerformanceCollector methods
146 STDMETHOD(GetMetrics) (ComSafeArrayIn (IN_BSTR, metricNames),
147 ComSafeArrayIn (IUnknown *, objects),
148 ComSafeArrayOut (IPerformanceMetric *, outMetrics));
149 STDMETHOD(SetupMetrics) (ComSafeArrayIn (IN_BSTR, metricNames),
150 ComSafeArrayIn (IUnknown *, objects),
151 ULONG aPeriod, ULONG aCount,
152 ComSafeArrayOut (IPerformanceMetric *,
153 outMetrics));
154 STDMETHOD(EnableMetrics) (ComSafeArrayIn (IN_BSTR, metricNames),
155 ComSafeArrayIn (IUnknown *, objects),
156 ComSafeArrayOut (IPerformanceMetric *,
157 outMetrics));
158 STDMETHOD(DisableMetrics) (ComSafeArrayIn (IN_BSTR, metricNames),
159 ComSafeArrayIn (IUnknown *, objects),
160 ComSafeArrayOut (IPerformanceMetric *,
161 outMetrics));
162 STDMETHOD(QueryMetricsData) (ComSafeArrayIn (IN_BSTR, metricNames),
163 ComSafeArrayIn (IUnknown *, objects),
164 ComSafeArrayOut (BSTR, outMetricNames),
165 ComSafeArrayOut (IUnknown *, outObjects),
166 ComSafeArrayOut (BSTR, outUnits),
167 ComSafeArrayOut (ULONG, outScales),
168 ComSafeArrayOut (ULONG, outSequenceNumbers),
169 ComSafeArrayOut (ULONG, outDataIndices),
170 ComSafeArrayOut (ULONG, outDataLengths),
171 ComSafeArrayOut (LONG, outData));
172
173 // public methods only for internal purposes
174
175 void registerBaseMetric (pm::BaseMetric *baseMetric);
176 void registerMetric (pm::Metric *metric);
177 void unregisterBaseMetricsFor (const ComPtr<IUnknown> &object);
178 void unregisterMetricsFor (const ComPtr<IUnknown> &object);
179
180 void suspendSampling();
181 void resumeSampling();
182
183 // public methods for internal purposes only
184 // (ensure there is a caller and a read lock before calling them!)
185
186 pm::CollectorHAL *getHAL() { return m.hal; };
187
188private:
189 HRESULT toIPerformanceMetric(pm::Metric *src, IPerformanceMetric **dst);
190 HRESULT toIPerformanceMetric(pm::BaseMetric *src, IPerformanceMetric **dst);
191
192 static void staticSamplerCallback (RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick);
193 void samplerCallback(uint64_t iTick);
194
195 typedef std::list<pm::Metric*> MetricList;
196 typedef std::list<pm::BaseMetric*> BaseMetricList;
197
198 enum
199 {
200 MAGIC = 0xABBA1972u
201 };
202
203 unsigned int mMagic;
204
205 struct Data
206 {
207 Data() : hal(0) {};
208
209 BaseMetricList baseMetrics;
210 MetricList metrics;
211 RTTIMERLR sampler;
212 pm::CollectorHAL *hal;
213 };
214
215 Data m;
216};
217
218#endif //!____H_PERFORMANCEIMPL
219/* 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