VirtualBox

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

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

Main. QT/FE: fix long standing COM issue

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