VirtualBox

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

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

Metrics: work in progress

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