mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Measure CPU utilization in ServiceQueue
This commit is contained in:
@@ -337,7 +337,6 @@
|
|||||||
<ClInclude Include="..\..\modules\beast_core\threads\TimeSliceThread.h" />
|
<ClInclude Include="..\..\modules\beast_core\threads\TimeSliceThread.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\DeadlineTimer.h" />
|
<ClInclude Include="..\..\modules\beast_core\thread\DeadlineTimer.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\Semaphore.h" />
|
<ClInclude Include="..\..\modules\beast_core\thread\Semaphore.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\ServiceQueue.h" />
|
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\Stoppable.h" />
|
<ClInclude Include="..\..\modules\beast_core\thread\Stoppable.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\Workers.h" />
|
<ClInclude Include="..\..\modules\beast_core\thread\Workers.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\detail\ScopedLock.h" />
|
<ClInclude Include="..\..\modules\beast_core\thread\detail\ScopedLock.h" />
|
||||||
@@ -1190,12 +1189,6 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\modules\beast_core\thread\ServiceQueue.cpp">
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\modules\beast_core\thread\Stoppable.cpp">
|
<ClCompile Include="..\..\modules\beast_core\thread\Stoppable.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
|
|||||||
@@ -1139,9 +1139,6 @@
|
|||||||
<ClInclude Include="..\..\modules\beast_asio\async\AbstractHandler.h">
|
<ClInclude Include="..\..\modules\beast_asio\async\AbstractHandler.h">
|
||||||
<Filter>beast_asio\async</Filter>
|
<Filter>beast_asio\async</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\ServiceQueue.h">
|
|
||||||
<Filter>beast_core\thread</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\beast\Chrono.h">
|
<ClInclude Include="..\..\beast\Chrono.h">
|
||||||
<Filter>beast</Filter>
|
<Filter>beast</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -1757,9 +1754,6 @@
|
|||||||
<ClCompile Include="..\..\beast\crypto\impl\Sha256.cpp">
|
<ClCompile Include="..\..\beast\crypto\impl\Sha256.cpp">
|
||||||
<Filter>beast\crypto\impl</Filter>
|
<Filter>beast\crypto\impl</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\modules\beast_core\thread\ServiceQueue.cpp">
|
|
||||||
<Filter>beast_core\thread</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\beast\chrono\impl\RelativeTime.cpp">
|
<ClCompile Include="..\..\beast\chrono\impl\RelativeTime.cpp">
|
||||||
<Filter>beast\chrono\impl</Filter>
|
<Filter>beast\chrono\impl</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|||||||
@@ -51,22 +51,6 @@ private:
|
|||||||
CPUMeter* m_meter;
|
CPUMeter* m_meter;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
|
||||||
/** The type of container that measures idle time. */
|
|
||||||
typedef ScopedTimeInterval <MeasureIdle> ScopedIdleTime;
|
|
||||||
typedef ScopedTimeInterval <MeasureActive> ScopedActiveTime;
|
|
||||||
|
|
||||||
/** Returns the fraction of time that the CPU is being used. */
|
|
||||||
double getCpuUsage () const
|
|
||||||
{
|
|
||||||
SharedState::ConstAccess state (m_state);
|
|
||||||
double const seconds (state->usage.seconds());
|
|
||||||
if (seconds > 0)
|
|
||||||
return (state->usage.active.inSeconds() / seconds);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
// The amount of time an aggregate must accrue before a swap
|
// The amount of time an aggregate must accrue before a swap
|
||||||
@@ -152,6 +136,21 @@ private:
|
|||||||
state->front().active += interval;
|
state->front().active += interval;
|
||||||
state->update();
|
state->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
/** The type of container that measures idle time. */
|
||||||
|
typedef ScopedTimeInterval <MeasureIdle> ScopedIdleTime;
|
||||||
|
typedef ScopedTimeInterval <MeasureActive> ScopedActiveTime;
|
||||||
|
|
||||||
|
/** Returns the fraction of time that the CPU is being used. */
|
||||||
|
double getUtilizaton () const
|
||||||
|
{
|
||||||
|
SharedState::ConstAccess state (m_state);
|
||||||
|
double const seconds (state->usage.seconds());
|
||||||
|
if (seconds > 0)
|
||||||
|
return (state->usage.active.inSeconds() / seconds);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public:
|
|||||||
|
|
||||||
/** Create the measurement with UnaryFunction constructed from one argument. */
|
/** Create the measurement with UnaryFunction constructed from one argument. */
|
||||||
template <typename Arg>
|
template <typename Arg>
|
||||||
explicit ScopedTimeInterval (Arg arg)
|
explicit ScopedTimeInterval (Arg& arg)
|
||||||
: m_func (arg)
|
: m_func (arg)
|
||||||
, m_start (RelativeTime::fromStartup ())
|
, m_start (RelativeTime::fromStartup ())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#ifndef BEAST_THREAD_SERVICEQUEUE_H_INCLUDED
|
#ifndef BEAST_THREAD_SERVICEQUEUE_H_INCLUDED
|
||||||
#define BEAST_THREAD_SERVICEQUEUE_H_INCLUDED
|
#define BEAST_THREAD_SERVICEQUEUE_H_INCLUDED
|
||||||
|
|
||||||
|
#include "../chrono/CPUMeter.h"
|
||||||
#include "../intrusive/List.h"
|
#include "../intrusive/List.h"
|
||||||
#include "../intrusive/LockFreeStack.h"
|
#include "../intrusive/LockFreeStack.h"
|
||||||
#include "SharedData.h"
|
#include "SharedData.h"
|
||||||
@@ -390,6 +391,7 @@ protected:
|
|||||||
|
|
||||||
typedef SharedData <State> SharedState;
|
typedef SharedData <State> SharedState;
|
||||||
SharedState m_state;
|
SharedState m_state;
|
||||||
|
CPUMeter m_cpuMeter;
|
||||||
Atomic <int> m_stopped;
|
Atomic <int> m_stopped;
|
||||||
|
|
||||||
static ThreadLocalValue <ServiceQueueBase*> s_service;
|
static ThreadLocalValue <ServiceQueueBase*> s_service;
|
||||||
@@ -459,6 +461,10 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns the percentage of time the queue is using the CPU. */
|
||||||
|
double getUtilizaton () const
|
||||||
|
{ return m_cpuMeter.getUtilizaton(); }
|
||||||
|
|
||||||
/** Returns the allocator associated with the container. */
|
/** Returns the allocator associated with the container. */
|
||||||
allocator_type get_allocator() const
|
allocator_type get_allocator() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ ServiceQueueBase::~ServiceQueueBase()
|
|||||||
|
|
||||||
std::size_t ServiceQueueBase::poll ()
|
std::size_t ServiceQueueBase::poll ()
|
||||||
{
|
{
|
||||||
|
CPUMeter::ScopedActiveTime interval (m_cpuMeter);
|
||||||
|
|
||||||
std::size_t total (0);
|
std::size_t total (0);
|
||||||
ScopedServiceThread thread (this);
|
ScopedServiceThread thread (this);
|
||||||
for (;;)
|
for (;;)
|
||||||
@@ -71,6 +73,8 @@ std::size_t ServiceQueueBase::poll ()
|
|||||||
|
|
||||||
std::size_t ServiceQueueBase::poll_one ()
|
std::size_t ServiceQueueBase::poll_one ()
|
||||||
{
|
{
|
||||||
|
CPUMeter::ScopedActiveTime interval (m_cpuMeter);
|
||||||
|
|
||||||
ScopedServiceThread thread (this);
|
ScopedServiceThread thread (this);
|
||||||
return dequeue();
|
return dequeue();
|
||||||
}
|
}
|
||||||
@@ -81,9 +85,16 @@ std::size_t ServiceQueueBase::run ()
|
|||||||
ScopedServiceThread thread (this);
|
ScopedServiceThread thread (this);
|
||||||
while (! stopped())
|
while (! stopped())
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
CPUMeter::ScopedActiveTime interval (m_cpuMeter);
|
||||||
total += poll ();
|
total += poll ();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
CPUMeter::ScopedIdleTime interval (m_cpuMeter);
|
||||||
wait ();
|
wait ();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,11 +104,18 @@ std::size_t ServiceQueueBase::run_one ()
|
|||||||
ScopedServiceThread (this);
|
ScopedServiceThread (this);
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
CPUMeter::ScopedActiveTime interval (m_cpuMeter);
|
||||||
n = poll_one();
|
n = poll_one();
|
||||||
if (n != 0)
|
if (n != 0)
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
CPUMeter::ScopedIdleTime interval (m_cpuMeter);
|
||||||
wait();
|
wait();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user