VirtualBox

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

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

More metrics changes

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