#include <StatsTimer.h>
Inheritance diagram for StatsTimer:
Public Member Functions | |
StatsTimer (uint intervalInMillis) | |
Creates a new StatsTimer without any initial target. | |
StatsTimer (StatsTarget &target, uint intervalInMillis) | |
Creates a new StatsTimer with an initial target. | |
virtual | ~StatsTimer () |
void | setTarget (StatsTarget &target) |
Sets the target for events. | |
void | addSource (SharedStatsSource pSource) |
Adds a source to be published. | |
void | start () |
Starts publication. | |
void | stop () |
Stops publication and forgets all sources. | |
Private Member Functions | |
virtual uint | getTimerIntervalMillis () |
Calculates the interval which should elapse before the next call to onTimerInterval. | |
virtual void | onThreadStart () |
Called in new thread context before thread's body runs. | |
virtual void | onTimerInterval () |
Receives notification from TimerThread that interval has elapsed. | |
virtual void | onThreadEnd () |
Called in thread context after thread's body runs. | |
virtual FennelExcn * | cloneExcn (std::exception &ex) |
Clones an exception so that it can be rethrown in a different thread context. | |
Private Attributes | |
StatsTarget * | pTarget |
std::vector< SharedStatsSource > | sources |
TimerThread | timerThread |
uint | intervalInMillis |
Definition at line 38 of file StatsTimer.h.
StatsTimer::StatsTimer | ( | uint | intervalInMillis | ) | [explicit] |
Creates a new StatsTimer without any initial target.
intervalInMillis | interval between publications |
Definition at line 40 of file StatsTimer.cpp.
References intervalInMillis, and pTarget.
00042 : timerThread(*this) 00043 { 00044 pTarget = NULL; 00045 intervalInMillis = intervalInMillisInit; 00046 }
StatsTimer::StatsTimer | ( | StatsTarget & | target, | |
uint | intervalInMillis | |||
) | [explicit] |
Creates a new StatsTimer with an initial target.
target | target to receive events | |
intervalInMillis | interval between publications |
Definition at line 31 of file StatsTimer.cpp.
References intervalInMillis, and pTarget.
00034 : timerThread(*this) 00035 { 00036 pTarget = ⌖ 00037 intervalInMillis = intervalInMillisInit; 00038 }
StatsTimer::~StatsTimer | ( | ) | [virtual] |
uint StatsTimer::getTimerIntervalMillis | ( | ) | [private, virtual] |
Calculates the interval which should elapse before the next call to onTimerInterval.
This can be different each time. A return value of 0 will cause the TimerThread to cease calling back.
Implements TimerThreadClient.
Definition at line 80 of file StatsTimer.cpp.
References intervalInMillis.
00081 { 00082 return intervalInMillis; 00083 }
void StatsTimer::onThreadStart | ( | ) | [private, virtual] |
Called in new thread context before thread's body runs.
Reimplemented from ThreadTracker.
Definition at line 85 of file StatsTimer.cpp.
References StatsTarget::onThreadStart(), and pTarget.
00086 { 00087 if (pTarget) { 00088 pTarget->onThreadStart(); 00089 } 00090 }
void StatsTimer::onTimerInterval | ( | ) | [private, virtual] |
Receives notification from TimerThread that interval has elapsed.
Implements TimerThreadClient.
Definition at line 99 of file StatsTimer.cpp.
References StatsTarget::beginSnapshot(), StatsTarget::endSnapshot(), pTarget, and sources.
00100 { 00101 if (!pTarget) { 00102 return; 00103 } 00104 pTarget->beginSnapshot(); 00105 for (uint i = 0; i < sources.size(); ++i) { 00106 sources[i]->writeStats(*pTarget); 00107 } 00108 pTarget->endSnapshot(); 00109 }
void StatsTimer::onThreadEnd | ( | ) | [private, virtual] |
Called in thread context after thread's body runs.
Reimplemented from ThreadTracker.
Definition at line 92 of file StatsTimer.cpp.
References StatsTarget::onThreadEnd(), and pTarget.
00093 { 00094 if (pTarget) { 00095 pTarget->onThreadEnd(); 00096 } 00097 }
void StatsTimer::setTarget | ( | StatsTarget & | target | ) |
Sets the target for events.
target | target to receive events |
Definition at line 52 of file StatsTimer.cpp.
References pTarget.
00053 { 00054 pTarget = ⌖ 00055 }
void StatsTimer::addSource | ( | SharedStatsSource | pSource | ) |
Adds a source to be published.
Should not be used after start().
pSource | source from which stats will be collected |
Definition at line 57 of file StatsTimer.cpp.
References sources.
Referenced by CacheTestBase::openStorage(), BTreeTxnTest::testCaseSetUp(), and BTreeTxnTest::testTxns().
00058 { 00059 sources.push_back(pSource); 00060 }
void StatsTimer::start | ( | ) |
Starts publication.
Target and sources must all remain valid until stop().
Definition at line 62 of file StatsTimer.cpp.
References Thread::start(), and timerThread.
Referenced by CacheTestBase::openStorage(), BTreeTxnTest::testCaseSetUp(), and BTreeTxnTest::testTxns().
00063 { 00064 timerThread.start(); 00065 }
void StatsTimer::stop | ( | ) |
Stops publication and forgets all sources.
Definition at line 67 of file StatsTimer.cpp.
References StatsTarget::beginSnapshot(), StatsTarget::endSnapshot(), pTarget, sources, TimerThread::stop(), and timerThread.
Referenced by CacheTestBase::closeStorage(), BTreeTxnTest::testCaseTearDown(), BTreeTxnTest::testTxns(), and CmdInterpreter::DbHandle::~DbHandle().
00068 { 00069 timerThread.stop(); 00070 00071 // clear target counters 00072 if (pTarget) { 00073 pTarget->beginSnapshot(); 00074 pTarget->endSnapshot(); 00075 } 00076 00077 sources.clear(); 00078 }
FennelExcn * ThreadTracker::cloneExcn | ( | std::exception & | ex | ) | [virtual, inherited] |
Clones an exception so that it can be rethrown in a different thread context.
ex | the excn to be cloned |
Reimplemented in JavaThreadTracker.
Definition at line 43 of file ThreadTracker.cpp.
Referenced by JavaThreadTracker::cloneExcn(), and ParallelExecStreamScheduler::executeTask().
00044 { 00045 return new FennelExcn(ex.what()); 00046 }
StatsTarget* StatsTimer::pTarget [private] |
Definition at line 40 of file StatsTimer.h.
Referenced by onThreadEnd(), onThreadStart(), onTimerInterval(), setTarget(), StatsTimer(), and stop().
std::vector<SharedStatsSource> StatsTimer::sources [private] |
Definition at line 41 of file StatsTimer.h.
Referenced by addSource(), onTimerInterval(), and stop().
TimerThread StatsTimer::timerThread [private] |
uint StatsTimer::intervalInMillis [private] |
Definition at line 43 of file StatsTimer.h.
Referenced by getTimerIntervalMillis(), and StatsTimer().