Factor out UptimeTimer from LoadManager

This commit is contained in:
Vinnie Falco
2013-05-25 10:51:04 -07:00
parent d0f75ccda1
commit 4cb44a8915
5 changed files with 79 additions and 34 deletions

View File

@@ -8,6 +8,7 @@
#include "Config.h"
#include "Application.h"
/*
static volatile int* uptimePtr = NULL;
int upTime()
@@ -17,10 +18,11 @@ int upTime()
return *uptimePtr;
return static_cast<int>(time(NULL) - firstCall);
}
*/
LoadManager::LoadManager(int creditRate, int creditLimit, int debitWarn, int debitLimit) :
mCreditRate(creditRate), mCreditLimit(creditLimit), mDebitWarn(debitWarn), mDebitLimit(debitLimit),
mShutdown(false), mArmed(false), mUptime(0), mDeadLock(0), mCosts(LT_MAX)
mShutdown(false), mArmed(false), /*mUptime(0),*/ mDeadLock(0), mCosts(LT_MAX)
{
addLoadCost(LoadCost(LT_InvalidRequest, -10, LC_CPU | LC_Network));
addLoadCost(LoadCost(LT_RequestNoReply, -1, LC_CPU | LC_Disk));
@@ -39,19 +41,22 @@ LoadManager::LoadManager(int creditRate, int creditLimit, int debitWarn, int deb
void LoadManager::init()
{
/*
if (uptimePtr == NULL)
uptimePtr = static_cast<volatile int *>(&mUptime);
*/
UptimeTimer::getInstance().beginManualUpdates ();
boost::thread(boost::bind(&LoadManager::threadEntry, this)).detach();
}
LoadManager::~LoadManager()
{
/*
if (uptimePtr == &mUptime)
uptimePtr = NULL;
{
boost::mutex::scoped_lock sl(mLock);
mShutdown = true;
}
*/
UptimeTimer::getInstance().endManualUpdates ();
do
{
@@ -68,7 +73,8 @@ LoadManager::~LoadManager()
void LoadManager::noDeadLock()
{
boost::mutex::scoped_lock sl(mLock);
mDeadLock = mUptime;
//mDeadLock = mUptime;
mDeadLock = UptimeTimer::getInstance ().getElapsedSeconds ();
}
int LoadManager::getCreditRate() const
@@ -342,9 +348,11 @@ void LoadManager::threadEntry()
mShutdown = false;
return;
}
++mUptime;
//++mUptime;
UptimeTimer::getInstance ().incrementElapsedTime ();
int dlTime = mUptime - mDeadLock;
int dlTime = UptimeTimer::getInstance ().getElapsedSeconds () - mDeadLock;
if (mArmed && (dlTime >= 10))
{
if ((dlTime % 10) == 0)

View File

@@ -102,9 +102,11 @@ protected:
bool mShutdown;
bool mArmed;
/*
int mSpace1[4]; // We want mUptime to have its own cache line
int mUptime;
int mSpace2[4];
*/
int mDeadLock; // Detect server deadlocks

View File

@@ -55,6 +55,15 @@ public:
static std::vector< std::pair<std::string, std::string> > getSeverities();
private:
/** Retrieve file name from a log partition.
Key must have this shape:
struct Key
{
static char const* getFileName ();
};
*/
template <class Key>
inline static LogPartition getFileName ()
{