VirtualBox

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

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

Main: coding style fixes

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