VirtualBox

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

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

Removed guest statistics interface; to be merged with metrics.

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