Split LoadEvent to a new file

This commit is contained in:
Vinnie Falco
2013-06-03 07:39:49 -07:00
parent 32a3024ce4
commit 3f3c76ab7e
7 changed files with 93 additions and 51 deletions

View File

@@ -1022,6 +1022,7 @@ void LedgerConsensus::playbackProposals()
}
}
// VFALCO: TODO, clean these macros up and put them somewhere. Try to eliminate them if possible.
#define LCAT_SUCCESS 0
#define LCAT_FAIL 1
#define LCAT_RETRY 2
@@ -1040,6 +1041,7 @@ int LedgerConsensus::applyTransaction(TransactionEngine& engine, SerializedTrans
<< (retryAssured ? "/retry" : "/final");
WriteLog (lsTRACE, LedgerConsensus) << txn->getJson(0);
// VFALCO: TODO, figure out what this "trust network" is all about and why it needs exceptions.
#ifndef TRUST_NETWORK
try
{

View File

@@ -55,51 +55,4 @@ private:
boost::mutex mLock;
};
class LoadEvent
{
public:
typedef boost::shared_ptr<LoadEvent> pointer;
typedef UPTR_T<LoadEvent> autoptr;
public:
LoadEvent(LoadMonitor& monitor, const std::string& name, bool shouldStart) :
mMonitor(monitor), mRunning(false), mName(name)
{
mStartTime = boost::posix_time::microsec_clock::universal_time();
if (shouldStart)
start();
}
~LoadEvent()
{
if (mRunning)
stop();
}
void reName(const std::string& name)
{
mName = name;
}
void start()
{ // okay to call if already started
mRunning = true;
mStartTime = boost::posix_time::microsec_clock::universal_time();
}
void stop()
{
assert(mRunning);
mRunning = false;
mMonitor.addCountAndLatency(mName,
static_cast<int>((boost::posix_time::microsec_clock::universal_time() - mStartTime).total_milliseconds()));
}
private:
LoadMonitor& mMonitor;
bool mRunning;
std::string mName;
boost::posix_time::ptime mStartTime;
};
#endif

View File

@@ -0,0 +1,37 @@
LoadEvent::LoadEvent (LoadMonitor& monitor, const std::string& name, bool shouldStart)
: mMonitor (monitor)
, mRunning (false)
, mName (name)
{
mStartTime = boost::posix_time::microsec_clock::universal_time();
if (shouldStart)
start();
}
LoadEvent::~LoadEvent()
{
if (mRunning)
stop();
}
void LoadEvent::reName(const std::string& name)
{
mName = name;
}
void LoadEvent::start()
{
mRunning = true;
mStartTime = boost::posix_time::microsec_clock::universal_time();
}
void LoadEvent::stop()
{
assert(mRunning);
mRunning = false;
mMonitor.addCountAndLatency (mName,
static_cast<int>((boost::posix_time::microsec_clock::universal_time() - mStartTime).total_milliseconds()));
}

View File

@@ -0,0 +1,35 @@
#ifndef RIPPLE_LOADEVENT_H
#define RIPPLE_LOADEVENT_H
class LoadMonitor;
class LoadEvent
{
public:
typedef boost::shared_ptr<LoadEvent> pointer;
typedef UPTR_T<LoadEvent> autoptr;
public:
// VFALCO: TODO, remove the dependency on LoadMonitor.
LoadEvent (LoadMonitor& monitor,
const std::string& name,
bool shouldStart);
~LoadEvent();
// VFALCO: TODO, rename this to setName () or setLabel ()
void reName (const std::string& name);
// okay to call if already started
void start();
void stop();
private:
LoadMonitor& mMonitor;
bool mRunning;
std::string mName;
boost::posix_time::ptime mStartTime;
};
#endif