VirtualBox

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

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

Metrics updates

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