diff --git a/src/ioc/db/test/dbStressLock.c b/src/ioc/db/test/dbStressLock.c index 376587975..aed0116e0 100644 --- a/src/ioc/db/test/dbStressLock.c +++ b/src/ioc/db/test/dbStressLock.c @@ -27,7 +27,10 @@ #include "epicsSpin.h" #include "epicsThread.h" #include "epicsMutex.h" +#include "epicsEvent.h" +#include "epicsMath.h" #include "dbCommon.h" +#include "epicsTime.h" #include "dbLockPvt.h" #include "dbStaticLib.h" @@ -40,10 +43,6 @@ #include "xRecord.h" -#if defined(CLOCK_REALTIME) && defined(CLOCK_MONOTONIC) && !defined(_WIN32) -# define TIME_STATS -#endif - #define testIntOk1(A, OP, B) testOk((A) OP (B), "%s (%d) %s %s (%d)", #A, A, #OP, #B, B); #define testPtrOk1(A, OP, B) testOk((A) OP (B), "%s (%p) %s %s (%p)", #A, A, #OP, #B, B); @@ -64,10 +63,9 @@ static dbCommon **precords; typedef struct { int id; unsigned long N[3]; -#ifdef TIME_STATS double X[3]; double X2[3]; -#endif + double min[3], max[3]; unsigned int done; epicsEventId donevent; @@ -158,25 +156,19 @@ void doreTarget(workerPriv *p) static void worker(void *raw) { -#ifdef TIME_STATS - struct timespec before; -#endif + unsigned init = 1; workerPriv *priv = raw; testDiag("worker %d is %p", priv->id, epicsThreadGetIdSelf()); -#ifdef TIME_STATS - clock_gettime(CLOCK_MONOTONIC, &before); -#endif - while(!priv->done) { + epicsUInt64 after, before; double sel = getRand(); -#ifdef TIME_STATS - struct timespec after; double duration; -#endif - int act; + + before = epicsMonotonicGet(); + if(sel<0.33) { doSingle(priv); act = 0; @@ -188,19 +180,18 @@ void worker(void *raw) act = 2; } -#ifdef TIME_STATS - clock_gettime(CLOCK_MONOTONIC, &after); - - duration = (double)((long)after.tv_nsec - (long)before.tv_nsec); - duration *= 1e-9; - duration += (double)(after.tv_sec - before.tv_sec); -#endif + after = epicsMonotonicGet(); + duration = (after-before)*1e-9; priv->N[act]++; -#ifdef TIME_STATS priv->X[act] += duration; priv->X2[act] += duration*duration; -#endif + if(durationmin[act] || init) { + priv->min[act] = duration; + init = 0; + } + if(duration>priv->max[act]) + priv->max[act] = duration; } epicsEventMustTrigger(priv->donevent); @@ -333,12 +324,18 @@ MAIN(dbStressTest) testDiag("Statistics"); for(i=0; i0); testOk1(priv[i].N[1]>0);