Measure CPU utilization in ServiceQueue

This commit is contained in:
Vinnie Falco
2013-10-04 11:46:10 -07:00
parent ca47d72aee
commit 93e9d8622e
6 changed files with 46 additions and 36 deletions

View File

@@ -57,6 +57,8 @@ ServiceQueueBase::~ServiceQueueBase()
std::size_t ServiceQueueBase::poll ()
{
CPUMeter::ScopedActiveTime interval (m_cpuMeter);
std::size_t total (0);
ScopedServiceThread thread (this);
for (;;)
@@ -71,6 +73,8 @@ std::size_t ServiceQueueBase::poll ()
std::size_t ServiceQueueBase::poll_one ()
{
CPUMeter::ScopedActiveTime interval (m_cpuMeter);
ScopedServiceThread thread (this);
return dequeue();
}
@@ -81,8 +85,15 @@ std::size_t ServiceQueueBase::run ()
ScopedServiceThread thread (this);
while (! stopped())
{
total += poll ();
wait ();
{
CPUMeter::ScopedActiveTime interval (m_cpuMeter);
total += poll ();
}
{
CPUMeter::ScopedIdleTime interval (m_cpuMeter);
wait ();
}
}
return total;
}
@@ -93,10 +104,17 @@ std::size_t ServiceQueueBase::run_one ()
ScopedServiceThread (this);
for (;;)
{
n = poll_one();
if (n != 0)
break;
wait();
{
CPUMeter::ScopedActiveTime interval (m_cpuMeter);
n = poll_one();
if (n != 0)
break;
}
{
CPUMeter::ScopedIdleTime interval (m_cpuMeter);
wait();
}
}
return n;
}