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 | bfa2a0997e9820216b626f65a02fec62bd76b45d (patch) | |
tree | e9fafc77054538ac55776cbb2eb0b625f26f7bc7 | |
parent | 4d3003c3d7f3cc066c56acfa02d771d599cab194 (diff) | |
download | qpid-python-bfa2a0997e9820216b626f65a02fec62bd76b45d.tar.gz |
Better output.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@724937 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/src/qpid/sys/ActivityTimer.h | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/qpid/cpp/src/qpid/sys/ActivityTimer.h b/qpid/cpp/src/qpid/sys/ActivityTimer.h index 749750e821..d49e16bc4f 100644 --- a/qpid/cpp/src/qpid/sys/ActivityTimer.h +++ b/qpid/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*/ |