VirtualBox

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

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

Main: separate internal machine data structs into MachineImplPrivate.h to significantly speed up compilation and for better interface separation; remove obsolete ConsoleEvents.h file

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