From 79f66abba343cb3e37870be994ed8c2f57cd6525 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Sat, 27 Jan 2001 00:07:52 +0000 Subject: [PATCH] installed event rate test --- src/ca/Makefile | 5 ++- src/ca/caEventRate.cpp | 78 ++++++++++++++++++++++++++++++++++++++ src/ca/caEventRateMain.cpp | 16 ++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 src/ca/caEventRate.cpp create mode 100644 src/ca/caEventRateMain.cpp diff --git a/src/ca/Makefile b/src/ca/Makefile index 20941b2fc..fd85e1107 100644 --- a/src/ca/Makefile +++ b/src/ca/Makefile @@ -78,13 +78,14 @@ Com_DIR = $(INSTALL_LIB) caRepeater_SRCS = caRepeater.cpp PROD += caRepeater -PROD_DEFAULT += catime acctst caConnTest casw +PROD_DEFAULT += catime acctst caConnTest casw caEventRate catime_SRCS = catimeMain.c catime.c acctst_SRCS = acctstMain.c acctst.c +caEventRate_SRCS = caEventRateMain.cpp caEventRate.cpp casw_SRCS = casw.cpp caConnTest_SRCS = caConnTestMain.cpp caConnTest.cpp -PROD_vxWorks = catime acctst caConnTest +PROD_vxWorks = catime acctst caConnTest caEventRate include $(TOP)/configure/RULES diff --git a/src/ca/caEventRate.cpp b/src/ca/caEventRate.cpp new file mode 100644 index 000000000..57c1bd015 --- /dev/null +++ b/src/ca/caEventRate.cpp @@ -0,0 +1,78 @@ + + +#include "cadef.h" + +#include +#include + +#include "cadef.h" +#include "dbDefs.h" +#include "tsStamp.h" + +/* + * event_handler() + */ +void eventCallBack ( struct event_handler_args args ) +{ + unsigned *pCount = static_cast < unsigned * > ( args.usr ); + (*pCount)++; +} + + +/* + * cam () + */ +void caEventRate ( const char *pName ) +{ + static const double initialSamplePeriod = 1.0; + static const double maxSamplePeriod = 60.0; + + chid chan; + int status = ca_search ( pName, &chan ); + SEVCHK(status, NULL); + + unsigned eventCount = 0u; + status = ca_add_event ( DBR_FLOAT, chan, eventCallBack, &eventCount, NULL); + SEVCHK ( status, __FILE__ ); + + status = ca_pend_io ( 10.0 ); + if ( status != ECA_NORMAL ) { + printf ( "%s not found\n", pName ); + return; + } + + // let the first one go by + while ( eventCount < 1u ) { + status = ca_pend_event ( 0.01 ); + if ( status != ECA_TIMEOUT ) { + SEVCHK ( status, NULL ); + } + } + + double samplePeriod = initialSamplePeriod; + while ( true ) { + unsigned nEvents, lastEventCount, curEventCount; + + lastEventCount = eventCount; + status = ca_pend_event ( samplePeriod ); + curEventCount = eventCount; + if ( status != ECA_TIMEOUT ) { + SEVCHK ( status, NULL ); + } + + if ( curEventCount >= lastEventCount ) { + nEvents = curEventCount - lastEventCount; + } + else { + nEvents = ( UINT_MAX - lastEventCount ) + curEventCount +1u; + } + + printf ( "CA Channel \"%s\" is producing %g subscription update events per second.\n", + pName, nEvents / samplePeriod ); + + if ( samplePeriod < maxSamplePeriod ) { + samplePeriod += samplePeriod; + } + } +} + diff --git a/src/ca/caEventRateMain.cpp b/src/ca/caEventRateMain.cpp new file mode 100644 index 000000000..69a6a09dd --- /dev/null +++ b/src/ca/caEventRateMain.cpp @@ -0,0 +1,16 @@ + +#include +#include + +void caEventRate ( const char *pName ); + +int main ( int argc, char **argv ) +{ + if ( argc < 2 || argc > 2 ) { + printf ( "usage: %s < chan name >\n", argv[0] ); + } + + caEventRate ( argv[1] ); + + return 0; +}