This is Unofficial EPICS BASE Doxygen Site
caEventRate.cpp File Reference
#include <stdio.h>
#include <limits.h>
#include <math.h>
#include "cadef.h"
#include "dbDefs.h"
#include "epicsTime.h"
#include "errlog.h"
+ Include dependency graph for caEventRate.cpp:

Go to the source code of this file.

Functions

void eventCallBack (struct event_handler_args args)
 
void caEventRate (const char *pName, unsigned count)
 

Function Documentation

void caEventRate ( const char *  pName,
unsigned  count 
)

Definition at line 31 of file caEventRate.cpp.

32 {
33  static const double initialSamplePeriod = 1.0;
34  static const double maxSamplePeriod = 60.0 * 5.0;
35  unsigned eventCount = 0u;
36 
37  chid * pChidTable = new chid [ count ];
38 
39  {
40  printf ( "Connecting to CA Channel \"%s\" %u times.",
41  pName, count );
42  fflush ( stdout );
43 
44  epicsTime begin = epicsTime::getCurrent ();
45  for ( unsigned i = 0u; i < count; i++ ) {
46  int status = ca_search ( pName, & pChidTable[i] );
47  SEVCHK ( status, NULL );
48  }
49 
50  int status = ca_pend_io ( 10000.0 );
51  if ( status != ECA_NORMAL ) {
52  fprintf ( stderr, " not found.\n" );
53  return;
54  }
55  epicsTime end = epicsTime::getCurrent ();
56 
57  printf ( " done(%f sec).\n", end - begin );
58  }
59 
60  {
61  printf ( "Subscribing %u times.", count );
62  fflush ( stdout );
63 
64  epicsTime begin = epicsTime::getCurrent ();
65  for ( unsigned i = 0u; i < count; i++ ) {
66  int addEventStatus = ca_add_event ( DBR_FLOAT,
67  pChidTable[i], eventCallBack, &eventCount, NULL);
68  SEVCHK ( addEventStatus, __FILE__ );
69  }
70 
71  int status = ca_flush_io ();
72  SEVCHK ( status, __FILE__ );
73 
74  epicsTime end = epicsTime::getCurrent ();
75 
76  printf ( " done(%f sec).\n", end - begin );
77  }
78 
79  {
80  printf ( "Waiting for initial value events." );
81  fflush ( stdout );
82 
83  // let the first one go by
84  epicsTime begin = epicsTime::getCurrent ();
85  while ( eventCount < count ) {
86  int status = ca_pend_event ( 0.01 );
87  if ( status != ECA_TIMEOUT ) {
88  SEVCHK ( status, NULL );
89  }
90  }
91  epicsTime end = epicsTime::getCurrent ();
92 
93  printf ( " done(%f sec).\n", end - begin );
94  }
95 
96  double samplePeriod = initialSamplePeriod;
97  double X = 0.0;
98  double XX = 0.0;
99  unsigned N = 0u;
100  while ( true ) {
101  unsigned nEvents, lastEventCount, curEventCount;
102 
103  epicsTime beginPend = epicsTime::getCurrent ();
104  lastEventCount = eventCount;
105  int status = ca_pend_event ( samplePeriod );
106  curEventCount = eventCount;
107  epicsTime endPend = epicsTime::getCurrent ();
108  if ( status != ECA_TIMEOUT ) {
109  SEVCHK ( status, NULL );
110  }
111 
112  if ( curEventCount >= lastEventCount ) {
113  nEvents = curEventCount - lastEventCount;
114  }
115  else {
116  nEvents = ( UINT_MAX - lastEventCount ) + curEventCount + 1u;
117  }
118 
119  N++;
120 
121  double period = endPend - beginPend;
122  double Hz = nEvents / period;
123 
124  X += Hz;
125  XX += Hz * Hz;
126 
127  double mean = X / N;
128  double stdDev = sqrt ( XX / N - mean * mean );
129 
130  printf ( "CA Event Rate (Hz): current %g mean %g std dev %g\n",
131  Hz, mean, stdDev );
132 
133  if ( samplePeriod < maxSamplePeriod ) {
134  samplePeriod += samplePeriod;
135  }
136  }
137 }
pvd::Status status
int i
Definition: scan.c:967
#define DBR_FLOAT
Definition: db_access.h:72
int epicsStdCall ca_pend_io(ca_real timeout)
Definition: access.cpp:484
#define printf
Definition: epicsStdio.h:41
#define NULL
Definition: catime.c:38
epicsTime begin
Definition: caConnTest.cpp:22
int epicsStdCall ca_pend_event(ca_real timeout)
Definition: access.cpp:457
#define ECA_NORMAL
Definition: caerr.h:77
int epicsStdCall ca_flush_io()
Definition: access.cpp:509
#define SEVCHK(CA_ERROR_CODE, MESSAGE_STRING)
Definition: cadef.h:137
void eventCallBack(struct event_handler_args args)
Definition: caEventRate.cpp:22
#define stdout
Definition: epicsStdio.h:30
#define ca_search(pChanName, pChanID)
Definition: cadef.h:859
#define ECA_TIMEOUT
Definition: caerr.h:87
#define stderr
Definition: epicsStdio.h:32
#define ca_add_event(type, chan, pFunc, pArg, pEventID)
Definition: cadef.h:866
void eventCallBack ( struct event_handler_args  args)

Definition at line 22 of file caEventRate.cpp.

23 {
24  unsigned *pCount = static_cast < unsigned * > ( args.usr );
25  (*pCount)++;
26 }
void * usr
Definition: cadef.h:85