VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

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