VirtualBox

source: vbox/trunk/src/VBox/Main/PerformanceImpl.cpp@ 16560

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

Main: do not include include/VBox/settings.h from other header files but only from implementations that need it (save compile time)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 21.2 KB
RevLine 
[10641]1/* $Id: PerformanceImpl.cpp 16560 2009-02-06 18:06:04Z vboxsync $ */
2
3/** @file
4 *
5 * VBox Performance API COM Classes implementation
6 */
7
8/*
9 * Copyright (C) 2008 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#include "PerformanceImpl.h"
25
26#include "Logging.h"
27
28#include <iprt/process.h>
29
[16560]30#include <VBox/err.h>
31#include <VBox/settings.h>
32
[10641]33#include <vector>
34#include <algorithm>
35#include <functional>
36
37static Bstr gMetricNames[] =
38{
[11377]39 "CPU/Load/User",
[10679]40 "CPU/Load/User:avg",
41 "CPU/Load/User:min",
42 "CPU/Load/User:max",
[11377]43 "CPU/Load/Kernel",
[10679]44 "CPU/Load/Kernel:avg",
45 "CPU/Load/Kernel:min",
46 "CPU/Load/Kernel:max",
[11377]47 "CPU/Load/Idle",
[10679]48 "CPU/Load/Idle:avg",
49 "CPU/Load/Idle:min",
50 "CPU/Load/Idle:max",
[11377]51 "CPU/MHz",
[10641]52 "CPU/MHz:avg",
53 "CPU/MHz:min",
54 "CPU/MHz:max",
[11377]55 "RAM/Usage/Total",
[10679]56 "RAM/Usage/Total:avg",
57 "RAM/Usage/Total:min",
58 "RAM/Usage/Total:max",
[11377]59 "RAM/Usage/Used",
[10679]60 "RAM/Usage/Used:avg",
61 "RAM/Usage/Used:min",
62 "RAM/Usage/Used:max",
[11377]63 "RAM/Usage/Free",
[10679]64 "RAM/Usage/Free:avg",
65 "RAM/Usage/Free:min",
66 "RAM/Usage/Free:max",
[10641]67};
68
69////////////////////////////////////////////////////////////////////////////////
70// PerformanceCollector class
71////////////////////////////////////////////////////////////////////////////////
72
73// constructor / destructor
74////////////////////////////////////////////////////////////////////////////////
75
[10713]76PerformanceCollector::PerformanceCollector() : mMagic(0) {}
[10641]77
78PerformanceCollector::~PerformanceCollector() {}
79
80HRESULT PerformanceCollector::FinalConstruct()
81{
82 LogFlowThisFunc (("\n"));
83
84 return S_OK;
85}
86
87void PerformanceCollector::FinalRelease()
88{
89 LogFlowThisFunc (("\n"));
90}
91
92// public initializer/uninitializer for internal purposes only
93////////////////////////////////////////////////////////////////////////////////
94
95/**
96 * Initializes the PerformanceCollector object.
97 */
98HRESULT PerformanceCollector::init()
99{
100 /* Enclose the state transition NotReady->InInit->Ready */
101 AutoInitSpan autoInitSpan (this);
[14579]102 AssertReturn (autoInitSpan.isOk(), E_FAIL);
[10641]103
104 LogFlowThisFuncEnter();
105
106 HRESULT rc = S_OK;
107
[12400]108 m.hal = pm::createHAL();
[10713]109
110 /* Let the sampler know it gets a valid collector. */
111 mMagic = MAGIC;
112
[10641]113 /* Start resource usage sampler */
[10959]114 int vrc = RTTimerLRCreate (&m.sampler, VBOX_USAGE_SAMPLER_MIN_INTERVAL,
115 &PerformanceCollector::staticSamplerCallback, this);
[10641]116 AssertMsgRC (vrc, ("Failed to create resource usage "
117 "sampling timer(%Rra)\n", vrc));
118 if (RT_FAILURE (vrc))
119 rc = E_FAIL;
120
121 if (SUCCEEDED (rc))
122 autoInitSpan.setSucceeded();
123
124 LogFlowThisFuncLeave();
125
126 return rc;
127}
128
129/**
130 * Uninitializes the PerformanceCollector object.
131 *
132 * Called either from FinalRelease() or by the parent when it gets destroyed.
133 */
134void PerformanceCollector::uninit()
135{
136 LogFlowThisFuncEnter();
137
138 /* Enclose the state transition Ready->InUninit->NotReady */
139 AutoUninitSpan autoUninitSpan (this);
140 if (autoUninitSpan.uninitDone())
141 {
142 LogFlowThisFunc (("Already uninitialized.\n"));
143 LogFlowThisFuncLeave();
144 return;
145 }
146
[10713]147 mMagic = 0;
148
[10641]149 /* Destroy resource usage sampler */
[10959]150 int vrc = RTTimerLRDestroy (m.sampler);
[10641]151 AssertMsgRC (vrc, ("Failed to destroy resource usage "
152 "sampling timer (%Rra)\n", vrc));
[10770]153 m.sampler = NULL;
[10641]154
[12400]155 //delete m.factory;
156 //m.factory = NULL;
[10641]157
[12400]158 delete m.hal;
159 m.hal = NULL;
160
[10641]161 LogFlowThisFuncLeave();
162}
163
164// IPerformanceCollector properties
165////////////////////////////////////////////////////////////////////////////////
166
167STDMETHODIMP
168PerformanceCollector::COMGETTER(MetricNames) (ComSafeArrayOut (BSTR, theMetricNames))
169{
170 if (ComSafeArrayOutIsNull (theMetricNames))
171 return E_POINTER;
172
173 AutoCaller autoCaller (this);
174 CheckComRCReturnRC (autoCaller.rc());
175
176 AutoReadLock alock (this);
177
178 com::SafeArray <BSTR> metricNames(RT_ELEMENTS(gMetricNames));
179 for (size_t i = 0; i < RT_ELEMENTS(gMetricNames); i++)
180 {
181 gMetricNames[i].detachTo(&metricNames[i]);
182 }
183 //gMetricNames.detachTo(ComSafeArrayOutArg (theMetricNames));
184 metricNames.detachTo (ComSafeArrayOutArg (theMetricNames));
185
186 return S_OK;
187}
188
189// IPerformanceCollector methods
190////////////////////////////////////////////////////////////////////////////////
191
[12668]192HRESULT PerformanceCollector::toIPerformanceMetric(pm::Metric *src, IPerformanceMetric **dst)
193{
194 ComObjPtr <PerformanceMetric> metric;
195 HRESULT rc = metric.createObject();
196 if (SUCCEEDED (rc))
197 rc = metric->init (src);
198 AssertComRCReturnRC (rc);
199 metric.queryInterfaceTo (dst);
200 return rc;
201}
202
203HRESULT PerformanceCollector::toIPerformanceMetric(pm::BaseMetric *src, IPerformanceMetric **dst)
204{
205 ComObjPtr <PerformanceMetric> metric;
206 HRESULT rc = metric.createObject();
207 if (SUCCEEDED (rc))
208 rc = metric->init (src);
209 AssertComRCReturnRC (rc);
210 metric.queryInterfaceTo (dst);
211 return rc;
212}
213
[10770]214STDMETHODIMP
[15051]215PerformanceCollector::GetMetrics (ComSafeArrayIn (IN_BSTR, metricNames),
[10770]216 ComSafeArrayIn (IUnknown *, objects),
217 ComSafeArrayOut (IPerformanceMetric *, outMetrics))
[10641]218{
[10868]219 LogFlowThisFuncEnter();
[10641]220 //LogFlowThisFunc (("mState=%d, mType=%d\n", mState, mType));
221
[10725]222 HRESULT rc = S_OK;
223
[10641]224 AutoCaller autoCaller (this);
225 CheckComRCReturnRC (autoCaller.rc());
226
[10770]227 pm::Filter filter (ComSafeArrayInArg (metricNames),
228 ComSafeArrayInArg (objects));
[10725]229
[10753]230 AutoReadLock alock (this);
231
[10725]232 MetricList filteredMetrics;
233 MetricList::iterator it;
[10770]234 for (it = m.metrics.begin(); it != m.metrics.end(); ++it)
235 if (filter.match ((*it)->getObject(), (*it)->getName()))
236 filteredMetrics.push_back (*it);
[10725]237
[10770]238 com::SafeIfaceArray<IPerformanceMetric> retMetrics (filteredMetrics.size());
[10725]239 int i = 0;
[10753]240 for (it = filteredMetrics.begin(); it != filteredMetrics.end(); ++it)
[10725]241 {
[10770]242 ComObjPtr <PerformanceMetric> metric;
[10725]243 rc = metric.createObject();
244 if (SUCCEEDED (rc))
245 rc = metric->init (*it);
[10770]246 AssertComRCReturnRC (rc);
247 LogFlow (("PerformanceCollector::GetMetrics() store a metric at "
248 "retMetrics[%d]...\n", i));
[10779]249 metric.queryInterfaceTo (&retMetrics [i++]);
[10725]250 }
[10770]251 retMetrics.detachTo (ComSafeArrayOutArg(outMetrics));
[10868]252 LogFlowThisFuncLeave();
[10725]253 return rc;
[10641]254}
255
[10770]256STDMETHODIMP
[15051]257PerformanceCollector::SetupMetrics (ComSafeArrayIn (IN_BSTR, metricNames),
[10770]258 ComSafeArrayIn (IUnknown *, objects),
[13082]259 ULONG aPeriod, ULONG aCount,
260 ComSafeArrayOut (IPerformanceMetric *,
261 outMetrics))
[10641]262{
[10725]263 AutoCaller autoCaller (this);
264 CheckComRCReturnRC (autoCaller.rc());
265
[10770]266 pm::Filter filter (ComSafeArrayInArg (metricNames),
267 ComSafeArrayInArg (objects));
[10641]268
[10753]269 AutoWriteLock alock (this);
270
[12668]271 HRESULT rc = S_OK;
272 BaseMetricList filteredMetrics;
[10679]273 BaseMetricList::iterator it;
[10770]274 for (it = m.baseMetrics.begin(); it != m.baseMetrics.end(); ++it)
[10679]275 if (filter.match((*it)->getObject(), (*it)->getName()))
[10713]276 {
[11336]277 LogFlow (("PerformanceCollector::SetupMetrics() setting period to %u,"
278 " count to %u for %s\n", aPeriod, aCount, (*it)->getName()));
[10641]279 (*it)->init(aPeriod, aCount);
[11481]280 if (aPeriod == 0 || aCount == 0)
281 {
282 LogFlow (("PerformanceCollector::SetupMetrics() disabling %s\n",
283 (*it)->getName()));
284 (*it)->disable();
285 }
286 else
287 {
288 LogFlow (("PerformanceCollector::SetupMetrics() enabling %s\n",
289 (*it)->getName()));
290 (*it)->enable();
291 }
[13082]292 filteredMetrics.push_back(*it);
[10713]293 }
[14579]294
[13082]295 com::SafeIfaceArray<IPerformanceMetric> retMetrics (filteredMetrics.size());
296 int i = 0;
297 for (it = filteredMetrics.begin();
298 it != filteredMetrics.end() && SUCCEEDED (rc); ++it)
299 rc = toIPerformanceMetric(*it, &retMetrics [i++]);
300 retMetrics.detachTo (ComSafeArrayOutArg(outMetrics));
301
[12668]302 LogFlowThisFuncLeave();
303 return rc;
[10641]304}
305
[10770]306STDMETHODIMP
[15051]307PerformanceCollector::EnableMetrics (ComSafeArrayIn (IN_BSTR, metricNames),
[13082]308 ComSafeArrayIn (IUnknown *, objects),
309 ComSafeArrayOut (IPerformanceMetric *,
310 outMetrics))
[10641]311{
[10725]312 AutoCaller autoCaller (this);
313 CheckComRCReturnRC (autoCaller.rc());
314
[10770]315 pm::Filter filter (ComSafeArrayInArg (metricNames),
316 ComSafeArrayInArg (objects));
[10713]317
[10868]318 AutoWriteLock alock (this); /* Write lock is not needed atm since we are */
319 /* fiddling with enable bit only, but we */
320 /* care for those who come next :-). */
[10770]321
[12668]322 HRESULT rc = S_OK;
323 BaseMetricList filteredMetrics;
[10713]324 BaseMetricList::iterator it;
[10770]325 for (it = m.baseMetrics.begin(); it != m.baseMetrics.end(); ++it)
[10713]326 if (filter.match((*it)->getObject(), (*it)->getName()))
[12668]327 {
[10713]328 (*it)->enable();
[13082]329 filteredMetrics.push_back(*it);
[12668]330 }
[10713]331
[13082]332 com::SafeIfaceArray<IPerformanceMetric> retMetrics (filteredMetrics.size());
333 int i = 0;
334 for (it = filteredMetrics.begin();
335 it != filteredMetrics.end() && SUCCEEDED (rc); ++it)
336 rc = toIPerformanceMetric(*it, &retMetrics [i++]);
337 retMetrics.detachTo (ComSafeArrayOutArg(outMetrics));
338
[12668]339 LogFlowThisFuncLeave();
340 return rc;
[10641]341}
342
[10770]343STDMETHODIMP
[15051]344PerformanceCollector::DisableMetrics (ComSafeArrayIn (IN_BSTR, metricNames),
[12668]345 ComSafeArrayIn (IUnknown *, objects),
346 ComSafeArrayOut (IPerformanceMetric *,
347 outMetrics))
348{
[10725]349 AutoCaller autoCaller (this);
350 CheckComRCReturnRC (autoCaller.rc());
351
[10770]352 pm::Filter filter (ComSafeArrayInArg (metricNames),
353 ComSafeArrayInArg (objects));
[10713]354
[10868]355 AutoWriteLock alock (this); /* Write lock is not needed atm since we are */
356 /* fiddling with enable bit only, but we */
357 /* care for those who come next :-). */
[10770]358
[12668]359 HRESULT rc = S_OK;
360 BaseMetricList filteredMetrics;
[10713]361 BaseMetricList::iterator it;
[10770]362 for (it = m.baseMetrics.begin(); it != m.baseMetrics.end(); ++it)
[10713]363 if (filter.match((*it)->getObject(), (*it)->getName()))
[12668]364 {
[10713]365 (*it)->disable();
[13082]366 filteredMetrics.push_back(*it);
[12668]367 }
[10713]368
[13082]369 com::SafeIfaceArray<IPerformanceMetric> retMetrics (filteredMetrics.size());
370 int i = 0;
371 for (it = filteredMetrics.begin();
372 it != filteredMetrics.end() && SUCCEEDED (rc); ++it)
373 rc = toIPerformanceMetric(*it, &retMetrics [i++]);
374 retMetrics.detachTo (ComSafeArrayOutArg(outMetrics));
375
[12668]376 LogFlowThisFuncLeave();
377 return rc;
[10641]378}
379
[10770]380STDMETHODIMP
[15051]381PerformanceCollector::QueryMetricsData (ComSafeArrayIn (IN_BSTR, metricNames),
[10770]382 ComSafeArrayIn (IUnknown *, objects),
383 ComSafeArrayOut (BSTR, outMetricNames),
384 ComSafeArrayOut (IUnknown *, outObjects),
[13082]385 ComSafeArrayOut (BSTR, outUnits),
386 ComSafeArrayOut (ULONG, outScales),
387 ComSafeArrayOut (ULONG, outSequenceNumbers),
[10770]388 ComSafeArrayOut (ULONG, outDataIndices),
389 ComSafeArrayOut (ULONG, outDataLengths),
390 ComSafeArrayOut (LONG, outData))
[10641]391{
392 AutoCaller autoCaller (this);
393 CheckComRCReturnRC (autoCaller.rc());
394
[10868]395 pm::Filter filter (ComSafeArrayInArg (metricNames),
396 ComSafeArrayInArg (objects));
397
[10753]398 AutoReadLock alock (this);
[10641]399
400 /* Let's compute the size of the resulting flat array */
[10868]401 size_t flatSize = 0;
402 MetricList filteredMetrics;
403 MetricList::iterator it;
[10770]404 for (it = m.metrics.begin(); it != m.metrics.end(); ++it)
[10868]405 if (filter.match ((*it)->getObject(), (*it)->getName()))
406 {
407 filteredMetrics.push_back (*it);
408 flatSize += (*it)->getLength();
409 }
410
411 int i = 0;
[10641]412 size_t flatIndex = 0;
[10868]413 size_t numberOfMetrics = filteredMetrics.size();
[10770]414 com::SafeArray <BSTR> retNames (numberOfMetrics);
415 com::SafeIfaceArray <IUnknown> retObjects (numberOfMetrics);
[12973]416 com::SafeArray <BSTR> retUnits (numberOfMetrics);
417 com::SafeArray <ULONG> retScales (numberOfMetrics);
418 com::SafeArray <ULONG> retSequenceNumbers (numberOfMetrics);
[10770]419 com::SafeArray <ULONG> retIndices (numberOfMetrics);
420 com::SafeArray <ULONG> retLengths (numberOfMetrics);
421 com::SafeArray <LONG> retData (flatSize);
[10713]422
[10868]423 for (it = filteredMetrics.begin(); it != filteredMetrics.end(); ++it, ++i)
[10641]424 {
[12973]425 ULONG *values, length, sequenceNumber;
[10641]426 /* @todo We may want to revise the query method to get rid of excessive alloc/memcpy calls. */
[12973]427 (*it)->query(&values, &length, &sequenceNumber);
[11336]428 LogFlow (("PerformanceCollector::QueryMetricsData() querying metric %s "
429 "returned %d values.\n", (*it)->getName(), length));
[10641]430 memcpy(retData.raw() + flatIndex, values, length * sizeof(*values));
431 Bstr tmp((*it)->getName());
432 tmp.detachTo(&retNames[i]);
[10770]433 (*it)->getObject().queryInterfaceTo (&retObjects[i]);
[12973]434 tmp = (*it)->getUnit();
435 tmp.detachTo(&retUnits[i]);
436 retScales[i] = (*it)->getScale();
437 retSequenceNumbers[i] = sequenceNumber;
[10641]438 retLengths[i] = length;
439 retIndices[i] = flatIndex;
440 flatIndex += length;
441 }
[10713]442
[10770]443 retNames.detachTo (ComSafeArrayOutArg (outMetricNames));
444 retObjects.detachTo (ComSafeArrayOutArg (outObjects));
[12973]445 retUnits.detachTo (ComSafeArrayOutArg (outUnits));
446 retScales.detachTo (ComSafeArrayOutArg (outScales));
447 retSequenceNumbers.detachTo (ComSafeArrayOutArg (outSequenceNumbers));
[10770]448 retIndices.detachTo (ComSafeArrayOutArg (outDataIndices));
449 retLengths.detachTo (ComSafeArrayOutArg (outDataLengths));
450 retData.detachTo (ComSafeArrayOutArg (outData));
[10641]451 return S_OK;
452}
453
454// public methods for internal purposes
455///////////////////////////////////////////////////////////////////////////////
456
457void PerformanceCollector::registerBaseMetric (pm::BaseMetric *baseMetric)
458{
[11391]459 //LogFlowThisFuncEnter();
[10779]460 AutoCaller autoCaller (this);
461 if (!SUCCEEDED (autoCaller.rc())) return;
[10770]462
[10753]463 AutoWriteLock alock (this);
[11391]464 LogAleksey(("{%p} " LOG_FN_FMT ": obj=%p name=%s\n", this, __PRETTY_FUNCTION__, (void *)baseMetric->getObject(), baseMetric->getName()));
[10770]465 m.baseMetrics.push_back (baseMetric);
[11391]466 //LogFlowThisFuncLeave();
[10641]467}
468
469void PerformanceCollector::registerMetric (pm::Metric *metric)
470{
[11391]471 //LogFlowThisFuncEnter();
[10779]472 AutoCaller autoCaller (this);
473 if (!SUCCEEDED (autoCaller.rc())) return;
[10770]474
[10753]475 AutoWriteLock alock (this);
[11391]476 LogAleksey(("{%p} " LOG_FN_FMT ": obj=%p name=%s\n", this, __PRETTY_FUNCTION__, (void *)metric->getObject(), metric->getName()));
[10770]477 m.metrics.push_back (metric);
[11391]478 //LogFlowThisFuncLeave();
[10641]479}
480
481void PerformanceCollector::unregisterBaseMetricsFor (const ComPtr <IUnknown> &aObject)
482{
[11391]483 //LogFlowThisFuncEnter();
[10779]484 AutoCaller autoCaller (this);
485 if (!SUCCEEDED (autoCaller.rc())) return;
[10770]486
[10753]487 AutoWriteLock alock (this);
[11391]488 LogAleksey(("{%p} " LOG_FN_FMT ": before remove_if: m.baseMetrics.size()=%d\n", this, __PRETTY_FUNCTION__, m.baseMetrics.size()));
[10868]489 BaseMetricList::iterator it = std::remove_if (
490 m.baseMetrics.begin(), m.baseMetrics.end(), std::bind2nd (
491 std::mem_fun (&pm::BaseMetric::associatedWith), aObject));
492 m.baseMetrics.erase(it, m.baseMetrics.end());
[11391]493 LogAleksey(("{%p} " LOG_FN_FMT ": after remove_if: m.baseMetrics.size()=%d\n", this, __PRETTY_FUNCTION__, m.baseMetrics.size()));
494 //LogFlowThisFuncLeave();
[10641]495}
496
497void PerformanceCollector::unregisterMetricsFor (const ComPtr <IUnknown> &aObject)
498{
[11391]499 //LogFlowThisFuncEnter();
[10779]500 AutoCaller autoCaller (this);
501 if (!SUCCEEDED (autoCaller.rc())) return;
[10770]502
[10753]503 AutoWriteLock alock (this);
[11391]504 LogAleksey(("{%p} " LOG_FN_FMT ": obj=%p\n", this, __PRETTY_FUNCTION__, (void *)aObject));
[10868]505 MetricList::iterator it = std::remove_if (
506 m.metrics.begin(), m.metrics.end(), std::bind2nd (
507 std::mem_fun (&pm::Metric::associatedWith), aObject));
508 m.metrics.erase(it, m.metrics.end());
[11391]509 //LogFlowThisFuncLeave();
[10641]510}
511
512// private methods
513///////////////////////////////////////////////////////////////////////////////
514
515/* static */
[10959]516void PerformanceCollector::staticSamplerCallback (RTTIMERLR hTimerLR, void *pvUser,
[10641]517 uint64_t iTick)
518{
519 AssertReturnVoid (pvUser != NULL);
[10713]520 PerformanceCollector *collector = static_cast <PerformanceCollector *> (pvUser);
[10770]521 Assert (collector->mMagic == MAGIC);
[10713]522 if (collector->mMagic == MAGIC)
523 {
524 collector->samplerCallback();
525 }
[10959]526 NOREF (hTimerLR);
[10641]527}
528
529void PerformanceCollector::samplerCallback()
530{
[11391]531 Log4(("{%p} " LOG_FN_FMT ": ENTER\n", this, __PRETTY_FUNCTION__));
[10753]532 AutoWriteLock alock (this);
533
[12400]534 pm::CollectorHints hints;
[10713]535 uint64_t timestamp = RTTimeMilliTS();
[12400]536 BaseMetricList toBeCollected;
537 BaseMetricList::iterator it;
538 /* Compose the list of metrics being collected at this moment */
539 for (it = m.baseMetrics.begin(); it != m.baseMetrics.end(); it++)
540 if ((*it)->collectorBeat(timestamp))
541 {
542 (*it)->preCollect(hints);
543 toBeCollected.push_back(*it);
544 }
545
[12461]546 if (toBeCollected.size() == 0)
547 return;
548
[12400]549 /* Let know the platform specific code what is being collected */
550 m.hal->preCollect(hints);
551
552 /* Finally, collect the data */
[12456]553 std::for_each (toBeCollected.begin(), toBeCollected.end(),
[12400]554 std::mem_fun (&pm::BaseMetric::collect));
[11391]555 Log4(("{%p} " LOG_FN_FMT ": LEAVE\n", this, __PRETTY_FUNCTION__));
[10641]556}
557
558////////////////////////////////////////////////////////////////////////////////
559// PerformanceMetric class
560////////////////////////////////////////////////////////////////////////////////
561
562// constructor / destructor
563////////////////////////////////////////////////////////////////////////////////
564
[10779]565PerformanceMetric::PerformanceMetric()
[10641]566{
567}
568
569PerformanceMetric::~PerformanceMetric()
570{
571}
572
573HRESULT PerformanceMetric::FinalConstruct()
574{
575 LogFlowThisFunc (("\n"));
576
577 return S_OK;
578}
579
580void PerformanceMetric::FinalRelease()
581{
582 LogFlowThisFunc (("\n"));
583
584 uninit ();
585}
586
587// public initializer/uninitializer for internal purposes only
588////////////////////////////////////////////////////////////////////////////////
589
590HRESULT PerformanceMetric::init (pm::Metric *aMetric)
591{
[11583]592 m.name = aMetric->getName();
593 m.object = aMetric->getObject();
594 m.description = aMetric->getDescription();
595 m.period = aMetric->getPeriod();
596 m.count = aMetric->getLength();
597 m.unit = aMetric->getUnit();
598 m.min = aMetric->getMinValue();
599 m.max = aMetric->getMaxValue();
[10641]600 return S_OK;
601}
602
[12668]603HRESULT PerformanceMetric::init (pm::BaseMetric *aMetric)
604{
605 m.name = aMetric->getName();
606 m.object = aMetric->getObject();
607 m.description = "";
608 m.period = aMetric->getPeriod();
609 m.count = aMetric->getLength();
610 m.unit = aMetric->getUnit();
611 m.min = aMetric->getMinValue();
612 m.max = aMetric->getMaxValue();
613 return S_OK;
614}
615
[10641]616void PerformanceMetric::uninit()
617{
618}
619
620STDMETHODIMP PerformanceMetric::COMGETTER(MetricName) (BSTR *aMetricName)
621{
[10770]622 /// @todo (r=dmik) why do all these getters not do AutoCaller and
623 /// AutoReadLock? Is the underlying metric a constant object?
624
[10779]625 m.name.cloneTo (aMetricName);
[10641]626 return S_OK;
627}
628
629STDMETHODIMP PerformanceMetric::COMGETTER(Object) (IUnknown **anObject)
630{
[10779]631 m.object.queryInterfaceTo(anObject);
[10641]632 return S_OK;
633}
634
[11583]635STDMETHODIMP PerformanceMetric::COMGETTER(Description) (BSTR *aDescription)
636{
637 m.description.cloneTo (aDescription);
638 return S_OK;
639}
640
[10725]641STDMETHODIMP PerformanceMetric::COMGETTER(Period) (ULONG *aPeriod)
[10641]642{
[10779]643 *aPeriod = m.period;
[10641]644 return S_OK;
645}
646
[10725]647STDMETHODIMP PerformanceMetric::COMGETTER(Count) (ULONG *aCount)
[10641]648{
[10779]649 *aCount = m.count;
[10641]650 return S_OK;
651}
652
653STDMETHODIMP PerformanceMetric::COMGETTER(Unit) (BSTR *aUnit)
654{
[10779]655 m.unit.cloneTo(aUnit);
[10641]656 return S_OK;
657}
658
[10725]659STDMETHODIMP PerformanceMetric::COMGETTER(MinimumValue) (LONG *aMinValue)
[10641]660{
[10779]661 *aMinValue = m.min;
[10641]662 return S_OK;
663}
664
[10725]665STDMETHODIMP PerformanceMetric::COMGETTER(MaximumValue) (LONG *aMaxValue)
[10641]666{
[10779]667 *aMaxValue = m.max;
[10641]668 return S_OK;
669}
[14772]670/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use