diff options
| author | Alan Conway <aconway@apache.org> | 2008-12-10 00:17:34 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2008-12-10 00:17:34 +0000 |
| commit | 43c361159593004822d684a14ec13835a91c6050 (patch) | |
| tree | 74ed35095c8641d770e1c3307e9441b6a4206763 /cpp/src/qpid/sys/ActivityTimer.h | |
| parent | ea592c9579d879a971d01bbc0cd2437182bdb325 (diff) | |
| download | qpid-python-43c361159593004822d684a14ec13835a91c6050.tar.gz | |
Better output.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@724937 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys/ActivityTimer.h')
| -rw-r--r-- | cpp/src/qpid/sys/ActivityTimer.h | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/cpp/src/qpid/sys/ActivityTimer.h b/cpp/src/qpid/sys/ActivityTimer.h index 749750e821..d49e16bc4f 100644 --- a/cpp/src/qpid/sys/ActivityTimer.h +++ b/cpp/src/qpid/sys/ActivityTimer.h @@ -49,39 +49,31 @@ class ActivityTimer }; struct Data { // Must be a POD - uint64_t start, entered, exited; - Stat active, inactive; + uint64_t start, entered; + Stat active; void reset() { - start = entered = exited = 0; + start = entered = 0; active.reset(); - inactive.reset(); } void enter(uint64_t now) { entered=now; - if (start) { - assert(exited); - assert(entered > exited); - inactive.sample(entered - exited); - } - else - start = Duration(now); + if (!start) start = Duration(now); } void exit(uint64_t now) { - assert(start); - assert(entered); - exited=now; - assert(exited > entered); - active.sample(exited - entered); + active.sample(now - entered); } }; ActivityTimer(Data& d, const char* fn, const char* file, int line, uint64_t reportInterval) : data(d) { uint64_t now = Duration(qpid::sys::now()); - if (data.start && now - data.start > reportInterval) - report(fn, file, line); + if (data.start) { + interval = now-data.start; + if (interval > reportInterval) + report(fn, file, line); + } data.enter(now); } @@ -91,14 +83,13 @@ class ActivityTimer private: Data& data; + uint64_t interval; void report(const char* fn, const char* file, int line) { - uint64_t secs = (Duration(now())-data.start)/TIME_SEC; - printf("[%lu]%s:%d: %s: rate=%ld/sec active=%ld inactive=%ld\n", - Thread::current().id(), file, line, fn, - long(data.active.count/secs), - long(data.active.mean()/TIME_USEC), - long(data.inactive.mean()/TIME_USEC)); + long rate = (data.active.count*TIME_SEC)/interval; + double percent = (data.active.total*100.0)/interval; + printf("%s:%d: TIMER %ld/sec %f%% [%lu] %s\n", + file, line, rate, percent, Thread::current().id(), fn); data.reset(); } }; @@ -109,7 +100,7 @@ class ActivityTimer * Can only have one in a given scope. */ #define ACTIVITY_TIMER(REPORT_INTERVAL_SECS) \ - static __thread ::qpid::sys::ActivityTimer::Data qpid__ActivityTimerData__ = { 0, 0, 0, { 0, 0 }, { 0, 0 } }; \ + static __thread ::qpid::sys::ActivityTimer::Data qpid__ActivityTimerData__ = { 0, 0, { 0,0 }}; \ ::qpid::sys::ActivityTimer qpid__ActivityTimerInstance__(qpid__ActivityTimerData__, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, 2*::qpid::sys::TIME_SEC) #endif /*!QPID_SYS_ACTIVITYTIMER_H*/ |
