diff --git a/Builds/VisualStudio2012/beast.vcxproj b/Builds/VisualStudio2012/beast.vcxproj index 29b8ea374..e89b435e5 100644 --- a/Builds/VisualStudio2012/beast.vcxproj +++ b/Builds/VisualStudio2012/beast.vcxproj @@ -337,7 +337,6 @@ - @@ -1190,12 +1189,6 @@ true true - - true - true - true - true - true true diff --git a/Builds/VisualStudio2012/beast.vcxproj.filters b/Builds/VisualStudio2012/beast.vcxproj.filters index 2d991fef4..ac32658af 100644 --- a/Builds/VisualStudio2012/beast.vcxproj.filters +++ b/Builds/VisualStudio2012/beast.vcxproj.filters @@ -1139,9 +1139,6 @@ beast_asio\async - - beast_core\thread - beast @@ -1757,9 +1754,6 @@ beast\crypto\impl - - beast_core\thread - beast\chrono\impl diff --git a/beast/chrono/CPUMeter.h b/beast/chrono/CPUMeter.h index 4040e1382..fd728a54e 100644 --- a/beast/chrono/CPUMeter.h +++ b/beast/chrono/CPUMeter.h @@ -51,22 +51,6 @@ private: CPUMeter* m_meter; }; -public: - /** The type of container that measures idle time. */ - typedef ScopedTimeInterval ScopedIdleTime; - typedef ScopedTimeInterval 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 { // The amount of time an aggregate must accrue before a swap @@ -152,6 +136,21 @@ private: state->front().active += interval; state->update(); } + +public: + /** The type of container that measures idle time. */ + typedef ScopedTimeInterval ScopedIdleTime; + typedef ScopedTimeInterval 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; + } }; } diff --git a/beast/chrono/ScopedTimeInterval.h b/beast/chrono/ScopedTimeInterval.h index af3672870..53b85b742 100644 --- a/beast/chrono/ScopedTimeInterval.h +++ b/beast/chrono/ScopedTimeInterval.h @@ -41,7 +41,7 @@ public: /** Create the measurement with UnaryFunction constructed from one argument. */ template - explicit ScopedTimeInterval (Arg arg) + explicit ScopedTimeInterval (Arg& arg) : m_func (arg) , m_start (RelativeTime::fromStartup ()) { diff --git a/beast/thread/ServiceQueue.h b/beast/thread/ServiceQueue.h index 1f5454051..a9f337ec1 100644 --- a/beast/thread/ServiceQueue.h +++ b/beast/thread/ServiceQueue.h @@ -20,6 +20,7 @@ #ifndef BEAST_THREAD_SERVICEQUEUE_H_INCLUDED #define BEAST_THREAD_SERVICEQUEUE_H_INCLUDED +#include "../chrono/CPUMeter.h" #include "../intrusive/List.h" #include "../intrusive/LockFreeStack.h" #include "SharedData.h" @@ -390,6 +391,7 @@ protected: typedef SharedData SharedState; SharedState m_state; + CPUMeter m_cpuMeter; Atomic m_stopped; static ThreadLocalValue 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. */ allocator_type get_allocator() const { diff --git a/beast/thread/impl/ServiceQueue.cpp b/beast/thread/impl/ServiceQueue.cpp index ddf9bd4f0..f82368c49 100644 --- a/beast/thread/impl/ServiceQueue.cpp +++ b/beast/thread/impl/ServiceQueue.cpp @@ -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; }