VirtualBox

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

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

Main: cleanup: get rid of VirtualBoxBaseProto, move AutoCaller*/*Span* classes out of VirtualBoxBaseProto class scope and into separate header; move CombinedProgress into separate header (it's only used by Console any more)

  • 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 25860 2010-01-15 13:27:26Z 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
171PerformanceCollector::COMGETTER(MetricNames) (ComSafeArrayOut(BSTR, theMetricNames))
172{
173 if (ComSafeArrayOutIsNull(theMetricNames))
174 return E_POINTER;
175
176 AutoCaller autoCaller(this);
177 if (FAILED(autoCaller.rc())) return autoCaller.rc();
178
179 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
180
181 com::SafeArray<BSTR> metricNames(RT_ELEMENTS(gMetricNames));
182 for (size_t i = 0; i < RT_ELEMENTS(gMetricNames); i++)
183 {
184 Bstr tmp(gMetricNames[i]); /* gcc-3.3 cruft */
185 tmp.cloneTo(&metricNames[i]);
186 }
187 //gMetricNames.detachTo(ComSafeArrayOutArg(theMetricNames));
188 metricNames.detachTo(ComSafeArrayOutArg(theMetricNames));
189
190 return S_OK;
191}
192
193// IPerformanceCollector methods
194////////////////////////////////////////////////////////////////////////////////
195
196HRESULT PerformanceCollector::toIPerformanceMetric(pm::Metric *src, IPerformanceMetric **dst)
197{
198 ComObjPtr<PerformanceMetric> metric;
199 HRESULT rc = metric.createObject();
200 if (SUCCEEDED(rc))
201 rc = metric->init (src);
202 AssertComRCReturnRC(rc);
203 metric.queryInterfaceTo(dst);
204 return rc;
205}
206
207HRESULT PerformanceCollector::toIPerformanceMetric(pm::BaseMetric *src, IPerformanceMetric **dst)
208{
209 ComObjPtr<PerformanceMetric> metric;
210 HRESULT rc = metric.createObject();
211 if (SUCCEEDED(rc))
212 rc = metric->init (src);
213 AssertComRCReturnRC(rc);
214 metric.queryInterfaceTo(dst);
215 return rc;
216}
217
218STDMETHODIMP
219PerformanceCollector::GetMetrics (ComSafeArrayIn (IN_BSTR, metricNames),
220 ComSafeArrayIn (IUnknown *, objects),
221 ComSafeArrayOut(IPerformanceMetric *, outMetrics))
222{
223 LogFlowThisFuncEnter();
224 //LogFlowThisFunc(("mState=%d, mType=%d\n", mState, mType));
225
226 HRESULT rc = S_OK;
227
228 AutoCaller autoCaller(this);
229 if (FAILED(autoCaller.rc())) return autoCaller.rc();
230
231 pm::Filter filter (ComSafeArrayInArg (metricNames),
232 ComSafeArrayInArg (objects));
233
234 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
235
236 MetricList filteredMetrics;
237 MetricList::iterator it;
238 for (it = m.metrics.begin(); it != m.metrics.end(); ++it)
239 if (filter.match ((*it)->getObject(), (*it)->getName()))
240 filteredMetrics.push_back (*it);
241
242 com::SafeIfaceArray<IPerformanceMetric> retMetrics (filteredMetrics.size());
243 int i = 0;
244 for (it = filteredMetrics.begin(); it != filteredMetrics.end(); ++it)
245 {
246 ComObjPtr<PerformanceMetric> metric;
247 rc = metric.createObject();
248 if (SUCCEEDED(rc))
249 rc = metric->init (*it);
250 AssertComRCReturnRC(rc);
251 LogFlow (("PerformanceCollector::GetMetrics() store a metric at "
252 "retMetrics[%d]...\n", i));
253 metric.queryInterfaceTo(&retMetrics [i++]);
254 }
255 retMetrics.detachTo(ComSafeArrayOutArg(outMetrics));
256 LogFlowThisFuncLeave();
257 return rc;
258}
259
260STDMETHODIMP
261PerformanceCollector::SetupMetrics (ComSafeArrayIn (IN_BSTR, metricNames),
262 ComSafeArrayIn (IUnknown *, objects),
263 ULONG aPeriod, ULONG aCount,
264 ComSafeArrayOut(IPerformanceMetric *,
265 outMetrics))
266{
267 AutoCaller autoCaller(this);
268 if (FAILED(autoCaller.rc())) return autoCaller.rc();
269
270 pm::Filter filter (ComSafeArrayInArg (metricNames),
271 ComSafeArrayInArg (objects));
272
273 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
274
275 HRESULT rc = S_OK;
276 BaseMetricList filteredMetrics;
277 BaseMetricList::iterator it;
278 for (it = m.baseMetrics.begin(); it != m.baseMetrics.end(); ++it)
279 if (filter.match((*it)->getObject(), (*it)->getName()))
280 {
281 LogFlow (("PerformanceCollector::SetupMetrics() setting period to %u,"
282 " count to %u for %s\n", aPeriod, aCount, (*it)->getName()));
283 (*it)->init(aPeriod, aCount);
284 if (aPeriod == 0 || aCount == 0)
285 {
286 LogFlow (("PerformanceCollector::SetupMetrics() disabling %s\n",
287 (*it)->getName()));
288 (*it)->disable();
289 }
290 else
291 {
292 LogFlow (("PerformanceCollector::SetupMetrics() enabling %s\n",
293 (*it)->getName()));
294 (*it)->enable();
295 }
296 filteredMetrics.push_back(*it);
297 }
298
299 com::SafeIfaceArray<IPerformanceMetric> retMetrics (filteredMetrics.size());
300 int i = 0;
301 for (it = filteredMetrics.begin();
302 it != filteredMetrics.end() && SUCCEEDED(rc); ++it)
303 rc = toIPerformanceMetric(*it, &retMetrics [i++]);
304 retMetrics.detachTo(ComSafeArrayOutArg(outMetrics));
305
306 LogFlowThisFuncLeave();
307 return rc;
308}
309
310STDMETHODIMP
311PerformanceCollector::EnableMetrics (ComSafeArrayIn (IN_BSTR, metricNames),
312 ComSafeArrayIn (IUnknown *, objects),
313 ComSafeArrayOut(IPerformanceMetric *,
314 outMetrics))
315{
316 AutoCaller autoCaller(this);
317 if (FAILED(autoCaller.rc())) return autoCaller.rc();
318
319 pm::Filter filter (ComSafeArrayInArg (metricNames),
320 ComSafeArrayInArg (objects));
321
322 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); /* Write lock is not needed atm since we are */
323 /* fiddling with enable bit only, but we */
324 /* care for those who come next :-). */
325
326 HRESULT rc = S_OK;
327 BaseMetricList filteredMetrics;
328 BaseMetricList::iterator it;
329 for (it = m.baseMetrics.begin(); it != m.baseMetrics.end(); ++it)
330 if (filter.match((*it)->getObject(), (*it)->getName()))
331 {
332 (*it)->enable();
333 filteredMetrics.push_back(*it);
334 }
335
336 com::SafeIfaceArray<IPerformanceMetric> retMetrics (filteredMetrics.size());
337 int i = 0;
338 for (it = filteredMetrics.begin();
339 it != filteredMetrics.end() && SUCCEEDED(rc); ++it)
340 rc = toIPerformanceMetric(*it, &retMetrics [i++]);
341 retMetrics.detachTo(ComSafeArrayOutArg(outMetrics));
342
343 LogFlowThisFuncLeave();
344 return rc;
345}
346
347STDMETHODIMP
348PerformanceCollector::DisableMetrics (ComSafeArrayIn (IN_BSTR, metricNames),
349 ComSafeArrayIn (IUnknown *, objects),
350 ComSafeArrayOut(IPerformanceMetric *,
351 outMetrics))
352{
353 AutoCaller autoCaller(this);
354 if (FAILED(autoCaller.rc())) return autoCaller.rc();
355
356 pm::Filter filter (ComSafeArrayInArg (metricNames),
357 ComSafeArrayInArg (objects));
358
359 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); /* Write lock is not needed atm since we are */
360 /* fiddling with enable bit only, but we */
361 /* care for those who come next :-). */
362
363 HRESULT rc = S_OK;
364 BaseMetricList filteredMetrics;
365 BaseMetricList::iterator it;
366 for (it = m.baseMetrics.begin(); it != m.baseMetrics.end(); ++it)
367 if (filter.match((*it)->getObject(), (*it)->getName()))
368 {
369 (*it)->disable();
370 filteredMetrics.push_back(*it);
371 }
372
373 com::SafeIfaceArray<IPerformanceMetric> retMetrics (filteredMetrics.size());
374 int i = 0;
375 for (it = filteredMetrics.begin();
376 it != filteredMetrics.end() && SUCCEEDED(rc); ++it)
377 rc = toIPerformanceMetric(*it, &retMetrics [i++]);
378 retMetrics.detachTo(ComSafeArrayOutArg(outMetrics));
379
380 LogFlowThisFuncLeave();
381 return rc;
382}
383
384STDMETHODIMP
385PerformanceCollector::QueryMetricsData (ComSafeArrayIn (IN_BSTR, metricNames),
386 ComSafeArrayIn (IUnknown *, objects),
387 ComSafeArrayOut(BSTR, outMetricNames),
388 ComSafeArrayOut(IUnknown *, outObjects),
389 ComSafeArrayOut(BSTR, outUnits),
390 ComSafeArrayOut(ULONG, outScales),
391 ComSafeArrayOut(ULONG, outSequenceNumbers),
392 ComSafeArrayOut(ULONG, outDataIndices),
393 ComSafeArrayOut(ULONG, outDataLengths),
394 ComSafeArrayOut(LONG, outData))
395{
396 AutoCaller autoCaller(this);
397 if (FAILED(autoCaller.rc())) return autoCaller.rc();
398
399 pm::Filter filter (ComSafeArrayInArg (metricNames),
400 ComSafeArrayInArg (objects));
401
402 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
403
404 /* Let's compute the size of the resulting flat array */
405 size_t flatSize = 0;
406 MetricList filteredMetrics;
407 MetricList::iterator it;
408 for (it = m.metrics.begin(); it != m.metrics.end(); ++it)
409 if (filter.match ((*it)->getObject(), (*it)->getName()))
410 {
411 filteredMetrics.push_back (*it);
412 flatSize += (*it)->getLength();
413 }
414
415 int i = 0;
416 size_t flatIndex = 0;
417 size_t numberOfMetrics = filteredMetrics.size();
418 com::SafeArray<BSTR> retNames (numberOfMetrics);
419 com::SafeIfaceArray<IUnknown> retObjects (numberOfMetrics);
420 com::SafeArray<BSTR> retUnits (numberOfMetrics);
421 com::SafeArray<ULONG> retScales (numberOfMetrics);
422 com::SafeArray<ULONG> retSequenceNumbers (numberOfMetrics);
423 com::SafeArray<ULONG> retIndices (numberOfMetrics);
424 com::SafeArray<ULONG> retLengths (numberOfMetrics);
425 com::SafeArray<LONG> retData (flatSize);
426
427 for (it = filteredMetrics.begin(); it != filteredMetrics.end(); ++it, ++i)
428 {
429 ULONG *values, length, sequenceNumber;
430 /* @todo We may want to revise the query method to get rid of excessive alloc/memcpy calls. */
431 (*it)->query(&values, &length, &sequenceNumber);
432 LogFlow (("PerformanceCollector::QueryMetricsData() querying metric %s "
433 "returned %d values.\n", (*it)->getName(), length));
434 memcpy(retData.raw() + flatIndex, values, length * sizeof(*values));
435 Bstr tmp((*it)->getName());
436 tmp.detachTo(&retNames[i]);
437 (*it)->getObject().queryInterfaceTo(&retObjects[i]);
438 tmp = (*it)->getUnit();
439 tmp.detachTo(&retUnits[i]);
440 retScales[i] = (*it)->getScale();
441 retSequenceNumbers[i] = sequenceNumber;
442 retLengths[i] = length;
443 retIndices[i] = (ULONG)flatIndex;
444 flatIndex += length;
445 }
446
447 retNames.detachTo(ComSafeArrayOutArg(outMetricNames));
448 retObjects.detachTo(ComSafeArrayOutArg(outObjects));
449 retUnits.detachTo(ComSafeArrayOutArg(outUnits));
450 retScales.detachTo(ComSafeArrayOutArg(outScales));
451 retSequenceNumbers.detachTo(ComSafeArrayOutArg(outSequenceNumbers));
452 retIndices.detachTo(ComSafeArrayOutArg(outDataIndices));
453 retLengths.detachTo(ComSafeArrayOutArg(outDataLengths));
454 retData.detachTo(ComSafeArrayOutArg(outData));
455 return S_OK;
456}
457
458// public methods for internal purposes
459///////////////////////////////////////////////////////////////////////////////
460
461void PerformanceCollector::registerBaseMetric (pm::BaseMetric *baseMetric)
462{
463 //LogFlowThisFuncEnter();
464 AutoCaller autoCaller(this);
465 if (!SUCCEEDED(autoCaller.rc())) return;
466
467 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
468 LogAleksey(("{%p} " LOG_FN_FMT ": obj=%p name=%s\n", this, __PRETTY_FUNCTION__, (void *)baseMetric->getObject(), baseMetric->getName()));
469 m.baseMetrics.push_back (baseMetric);
470 //LogFlowThisFuncLeave();
471}
472
473void PerformanceCollector::registerMetric (pm::Metric *metric)
474{
475 //LogFlowThisFuncEnter();
476 AutoCaller autoCaller(this);
477 if (!SUCCEEDED(autoCaller.rc())) return;
478
479 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
480 LogAleksey(("{%p} " LOG_FN_FMT ": obj=%p name=%s\n", this, __PRETTY_FUNCTION__, (void *)metric->getObject(), metric->getName()));
481 m.metrics.push_back (metric);
482 //LogFlowThisFuncLeave();
483}
484
485void PerformanceCollector::unregisterBaseMetricsFor (const ComPtr<IUnknown> &aObject)
486{
487 //LogFlowThisFuncEnter();
488 AutoCaller autoCaller(this);
489 if (!SUCCEEDED(autoCaller.rc())) return;
490
491 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
492 LogAleksey(("{%p} " LOG_FN_FMT ": before remove_if: m.baseMetrics.size()=%d\n", this, __PRETTY_FUNCTION__, m.baseMetrics.size()));
493 BaseMetricList::iterator it;
494 for (it = m.baseMetrics.begin(); it != m.baseMetrics.end();)
495 if ((*it)->associatedWith(aObject))
496 {
497 delete *it;
498 it = m.baseMetrics.erase(it);
499 }
500 else
501 ++it;
502 LogAleksey(("{%p} " LOG_FN_FMT ": after remove_if: m.baseMetrics.size()=%d\n", this, __PRETTY_FUNCTION__, m.baseMetrics.size()));
503 //LogFlowThisFuncLeave();
504}
505
506void PerformanceCollector::unregisterMetricsFor (const ComPtr<IUnknown> &aObject)
507{
508 //LogFlowThisFuncEnter();
509 AutoCaller autoCaller(this);
510 if (!SUCCEEDED(autoCaller.rc())) return;
511
512 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
513 LogAleksey(("{%p} " LOG_FN_FMT ": obj=%p\n", this, __PRETTY_FUNCTION__, (void *)aObject));
514 MetricList::iterator it;
515 for (it = m.metrics.begin(); it != m.metrics.end();)
516 if ((*it)->associatedWith(aObject))
517 {
518 delete *it;
519 it = m.metrics.erase(it);
520 }
521 else
522 ++it;
523 //LogFlowThisFuncLeave();
524}
525
526void PerformanceCollector::suspendSampling()
527{
528 AutoCaller autoCaller(this);
529 if (!SUCCEEDED(autoCaller.rc())) return;
530
531 int rc = RTTimerLRStop(m.sampler);
532 AssertRC(rc);
533}
534
535void PerformanceCollector::resumeSampling()
536{
537 AutoCaller autoCaller(this);
538 if (!SUCCEEDED(autoCaller.rc())) return;
539
540 int rc = RTTimerLRStart(m.sampler, 0);
541 AssertRC(rc);
542}
543
544
545// private methods
546///////////////////////////////////////////////////////////////////////////////
547
548/* static */
549void PerformanceCollector::staticSamplerCallback (RTTIMERLR hTimerLR, void *pvUser,
550 uint64_t /* iTick */)
551{
552 AssertReturnVoid (pvUser != NULL);
553 PerformanceCollector *collector = static_cast <PerformanceCollector *> (pvUser);
554 Assert (collector->mMagic == MAGIC);
555 if (collector->mMagic == MAGIC)
556 {
557 collector->samplerCallback();
558 }
559 NOREF (hTimerLR);
560}
561
562void PerformanceCollector::samplerCallback()
563{
564 Log4(("{%p} " LOG_FN_FMT ": ENTER\n", this, __PRETTY_FUNCTION__));
565 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
566
567 pm::CollectorHints hints;
568 uint64_t timestamp = RTTimeMilliTS();
569 BaseMetricList toBeCollected;
570 BaseMetricList::iterator it;
571 /* Compose the list of metrics being collected at this moment */
572 for (it = m.baseMetrics.begin(); it != m.baseMetrics.end(); it++)
573 if ((*it)->collectorBeat(timestamp))
574 {
575 (*it)->preCollect(hints);
576 toBeCollected.push_back(*it);
577 }
578
579 if (toBeCollected.size() == 0)
580 return;
581
582 /* Let know the platform specific code what is being collected */
583 m.hal->preCollect(hints);
584
585 /* Finally, collect the data */
586 std::for_each (toBeCollected.begin(), toBeCollected.end(),
587 std::mem_fun (&pm::BaseMetric::collect));
588 Log4(("{%p} " LOG_FN_FMT ": LEAVE\n", this, __PRETTY_FUNCTION__));
589}
590
591////////////////////////////////////////////////////////////////////////////////
592// PerformanceMetric class
593////////////////////////////////////////////////////////////////////////////////
594
595// constructor / destructor
596////////////////////////////////////////////////////////////////////////////////
597
598PerformanceMetric::PerformanceMetric()
599{
600}
601
602PerformanceMetric::~PerformanceMetric()
603{
604}
605
606HRESULT PerformanceMetric::FinalConstruct()
607{
608 LogFlowThisFunc(("\n"));
609
610 return S_OK;
611}
612
613void PerformanceMetric::FinalRelease()
614{
615 LogFlowThisFunc(("\n"));
616
617 uninit ();
618}
619
620// public initializer/uninitializer for internal purposes only
621////////////////////////////////////////////////////////////////////////////////
622
623HRESULT PerformanceMetric::init (pm::Metric *aMetric)
624{
625 m.name = aMetric->getName();
626 m.object = aMetric->getObject();
627 m.description = aMetric->getDescription();
628 m.period = aMetric->getPeriod();
629 m.count = aMetric->getLength();
630 m.unit = aMetric->getUnit();
631 m.min = aMetric->getMinValue();
632 m.max = aMetric->getMaxValue();
633 return S_OK;
634}
635
636HRESULT PerformanceMetric::init (pm::BaseMetric *aMetric)
637{
638 m.name = aMetric->getName();
639 m.object = aMetric->getObject();
640 m.description = "";
641 m.period = aMetric->getPeriod();
642 m.count = aMetric->getLength();
643 m.unit = aMetric->getUnit();
644 m.min = aMetric->getMinValue();
645 m.max = aMetric->getMaxValue();
646 return S_OK;
647}
648
649void PerformanceMetric::uninit()
650{
651}
652
653STDMETHODIMP PerformanceMetric::COMGETTER(MetricName) (BSTR *aMetricName)
654{
655 /// @todo (r=dmik) why do all these getters not do AutoCaller and
656 /// AutoReadLock? Is the underlying metric a constant object?
657
658 m.name.cloneTo(aMetricName);
659 return S_OK;
660}
661
662STDMETHODIMP PerformanceMetric::COMGETTER(Object) (IUnknown **anObject)
663{
664 m.object.queryInterfaceTo(anObject);
665 return S_OK;
666}
667
668STDMETHODIMP PerformanceMetric::COMGETTER(Description) (BSTR *aDescription)
669{
670 m.description.cloneTo(aDescription);
671 return S_OK;
672}
673
674STDMETHODIMP PerformanceMetric::COMGETTER(Period) (ULONG *aPeriod)
675{
676 *aPeriod = m.period;
677 return S_OK;
678}
679
680STDMETHODIMP PerformanceMetric::COMGETTER(Count) (ULONG *aCount)
681{
682 *aCount = m.count;
683 return S_OK;
684}
685
686STDMETHODIMP PerformanceMetric::COMGETTER(Unit) (BSTR *aUnit)
687{
688 m.unit.cloneTo(aUnit);
689 return S_OK;
690}
691
692STDMETHODIMP PerformanceMetric::COMGETTER(MinimumValue) (LONG *aMinValue)
693{
694 *aMinValue = m.min;
695 return S_OK;
696}
697
698STDMETHODIMP PerformanceMetric::COMGETTER(MaximumValue) (LONG *aMaxValue)
699{
700 *aMaxValue = m.max;
701 return S_OK;
702}
703/* 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