PerformanceImpl.cpp revision 52b9ffdb596974faf66a826097386ba74a9c7cd0
/* $Id$ */
/** @file
*
* VBox Performance API COM Classes implementation
*/
/*
* Copyright (C) 2008-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*
* Rules of engagement:
* 1) All performance objects must be destroyed by PerformanceCollector only!
* 2) All public methods of PerformanceCollector must be protected with
* read or write lock.
* 3) samplerCallback only uses the write lock during the third phase
* which pulls data into SubMetric objects. This is where object destruction
* and all list modifications are done. The pre-collection phases are
* run without any locks which is only possible because:
* 4) Public methods of PerformanceCollector as well as pre-collection methods
cannot modify lists or destroy objects, and:
* 5) Pre-collection methods cannot modify metric data.
*/
#include "PerformanceImpl.h"
#include "AutoCaller.h"
#include "Logging.h"
#include <VBox/settings.h>
#include <vector>
#include <algorithm>
#include <functional>
#include "Performance.h"
static const char *g_papcszMetricNames[] =
{
};
////////////////////////////////////////////////////////////////////////////////
// PerformanceCollector class
////////////////////////////////////////////////////////////////////////////////
// constructor / destructor
////////////////////////////////////////////////////////////////////////////////
{
}
{
LogFlowThisFunc(("\n"));
return BaseFinalConstruct();
}
void PerformanceCollector::FinalRelease()
{
LogFlowThisFunc(("\n"));
}
// public initializer/uninitializer for internal purposes only
////////////////////////////////////////////////////////////////////////////////
/**
* Initializes the PerformanceCollector object.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* Let the sampler know it gets a valid collector. */
/* Start resource usage sampler */
&PerformanceCollector::staticSamplerCallback, this);
"sampling timer(%Rra)\n", vrc));
if (RT_FAILURE(vrc))
return rc;
}
/**
* Uninitializes the PerformanceCollector object.
*
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
void PerformanceCollector::uninit()
{
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
{
LogFlowThisFunc(("Already uninitialized.\n"));
return;
}
mMagic = 0;
/* Destroy unregistered metrics */
if ((*it)->isUnregistered())
{
delete *it;
}
else
++it;
/*
* Now when we have destroyed all base metrics that could
* try to pull data from unregistered CollectorGuest objects
* it is safe to destroy them as well.
*/
m.gm->destroyUnregistered();
/* Destroy resource usage sampler */
"sampling timer (%Rra)\n", vrc));
//delete m.factory;
//m.factory = NULL;
delete m.gm;
delete m.hal;
}
// IPerformanceCollector properties
////////////////////////////////////////////////////////////////////////////////
{
return E_POINTER;
AutoCaller autoCaller(this);
{
}
//gMetricNames.detachTo(ComSafeArrayOutArg(theMetricNames));
return S_OK;
}
// IPerformanceCollector methods
////////////////////////////////////////////////////////////////////////////////
{
return rc;
}
{
return rc;
}
{
if (pGuest)
return mUnknownGuest;
}
{
//LogFlowThisFunc(("mState=%d, mType=%d\n", mState, mType));
AutoCaller autoCaller(this);
int i = 0;
{
LogFlow (("PerformanceCollector::GetMetrics() store a metric at "
"retMetrics[%d]...\n", i));
}
return rc;
}
{
AutoCaller autoCaller(this);
{
LogFlow (("PerformanceCollector::SetupMetrics() setting period to %u,"
{
LogFlow (("PerformanceCollector::SetupMetrics() disabling %s\n",
break;
}
else
{
LogFlow (("PerformanceCollector::SetupMetrics() enabling %s\n",
break;
}
}
int i = 0;
getFailedGuestName().c_str());
return rc;
}
{
AutoCaller autoCaller(this);
/* fiddling with enable bit only, but we */
/* care for those who come next :-). */
{
break;
}
int i = 0;
getFailedGuestName().c_str());
return rc;
}
{
AutoCaller autoCaller(this);
/* fiddling with enable bit only, but we */
/* care for those who come next :-). */
{
break;
}
int i = 0;
getFailedGuestName().c_str());
return rc;
}
{
AutoCaller autoCaller(this);
/* Let's compute the size of the resulting flat array */
{
}
int i = 0;
{
LogFlow (("PerformanceCollector::QueryMetricsData() querying metric %s "
retLengths[i] = length;
}
return S_OK;
}
// public methods for internal purposes
///////////////////////////////////////////////////////////////////////////////
{
//LogFlowThisFuncEnter();
AutoCaller autoCaller(this);
LogAleksey(("{%p} " LOG_FN_FMT ": obj=%p name=%s\n", this, __PRETTY_FUNCTION__, (void *)baseMetric->getObject(), baseMetric->getName()));
//LogFlowThisFuncLeave();
}
{
//LogFlowThisFuncEnter();
AutoCaller autoCaller(this);
LogAleksey(("{%p} " LOG_FN_FMT ": obj=%p name=%s\n", this, __PRETTY_FUNCTION__, (void *)metric->getObject(), metric->getName()));
//LogFlowThisFuncLeave();
}
{
//LogFlowThisFuncEnter();
AutoCaller autoCaller(this);
int n = 0;
{
(*it)->unregister();
++n;
}
this, __PRETTY_FUNCTION__, (void *)aObject, n));
//LogFlowThisFuncLeave();
}
{
//LogFlowThisFuncEnter();
AutoCaller autoCaller(this);
{
delete *it;
}
else
++it;
//LogFlowThisFuncLeave();
}
{
AutoCaller autoCaller(this);
}
{
AutoCaller autoCaller(this);
}
void PerformanceCollector::suspendSampling()
{
AutoCaller autoCaller(this);
}
void PerformanceCollector::resumeSampling()
{
AutoCaller autoCaller(this);
}
// private methods
///////////////////////////////////////////////////////////////////////////////
/* static */
{
}
/*
* Metrics collection is a three stage process:
* 1) Pre-collection (hinting)
* At this stage we compose the list of all metrics to be collected
* If any metrics cannot be collected separately or if it is more
* efficient to collect several metric at once, these metrics should
* use hints to mark that they will need to be collected.
* 2) Pre-collection (bulk)
* Using hints set at stage 1 platform-specific HAL
* instance collects all marked host-related metrics.
* Hinted guest-related metrics then get collected by CollectorGuestManager.
* 3) Collection
* Metrics that are collected individually get collected and stored. Values
* saved in HAL and CollectorGuestManager are extracted and stored to
* individual metrics.
*/
{
/* No locking until stage 3!*/
/* Compose the list of metrics being collected at this moment */
{
}
if (toBeCollected.size() == 0)
{
return;
}
/* Let know the platform specific code what is being collected */
#if 0
/* Guest stats are now pushed by guests themselves */
/* Collect the data in bulk from all hinted guests */
#endif
/*
* Before we can collect data we need to go through both lists
* again to see if any base metrics are marked as unregistered.
* Those should be destroyed now.
*/
LogAleksey(("{%p} " LOG_FN_FMT ": before remove_if: toBeCollected.size()=%d\n", this, __PRETTY_FUNCTION__, toBeCollected.size()));
LogAleksey(("{%p} " LOG_FN_FMT ": after remove_if: toBeCollected.size()=%d\n", this, __PRETTY_FUNCTION__, toBeCollected.size()));
LogAleksey(("{%p} " LOG_FN_FMT ": before remove_if: m.baseMetrics.size()=%d\n", this, __PRETTY_FUNCTION__, m.baseMetrics.size()));
if ((*it)->isUnregistered())
{
delete *it;
}
else
++it;
LogAleksey(("{%p} " LOG_FN_FMT ": after remove_if: m.baseMetrics.size()=%d\n", this, __PRETTY_FUNCTION__, m.baseMetrics.size()));
/*
* Now when we have destroyed all base metrics that could
* try to pull data from unregistered CollectorGuest objects
* it is safe to destroy them as well.
*/
m.gm->destroyUnregistered();
/* Finally, collect the data */
}
////////////////////////////////////////////////////////////////////////////////
// PerformanceMetric class
////////////////////////////////////////////////////////////////////////////////
// constructor / destructor
////////////////////////////////////////////////////////////////////////////////
{
}
{
}
{
LogFlowThisFunc(("\n"));
return BaseFinalConstruct();
}
void PerformanceMetric::FinalRelease()
{
LogFlowThisFunc(("\n"));
uninit ();
}
// public initializer/uninitializer for internal purposes only
////////////////////////////////////////////////////////////////////////////////
{
return S_OK;
}
{
m.description = "";
return S_OK;
}
void PerformanceMetric::uninit()
{
}
{
/// @todo (r=dmik) why do all these getters not do AutoCaller and
/// AutoReadLock? Is the underlying metric a constant object?
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
{
return S_OK;
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */