This is Unofficial EPICS BASE Doxygen Site
catime.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include "epicsAssert.h"
#include "epicsTime.h"
#include "cadef.h"
#include "caProto.h"
#include "caDiagnostics.h"
+ Include dependency graph for catime.c:

Go to the source code of this file.

Classes

struct  testItem
 

Macros

#define epicsAssertAuthor   "Jeff Hill johill@lanl.gov"
 
#define NULL   0
 
#define WAIT_FOR_ACK
 

Typedefs

typedef struct testItem ti
 
typedef void tf(ti *pItems, unsigned iterations, unsigned *pInlineIter)
 

Functions

void timeIt (tf *pfunc, ti *pItems, unsigned iterations, unsigned nBytesSent, unsigned nBytesRecv)
 
int catime (const char *channelName, unsigned channelCount, enum appendNumberFlag appNF)
 

Macro Definition Documentation

#define epicsAssertAuthor   "Jeff Hill johill@lanl.gov"

Definition at line 28 of file catime.c.

#define NULL   0

Definition at line 38 of file catime.c.

#define WAIT_FOR_ACK

Definition at line 41 of file catime.c.

Typedef Documentation

typedef void tf(ti *pItems, unsigned iterations, unsigned *pInlineIter)

Definition at line 51 of file catime.c.

typedef struct testItem ti

Function Documentation

int catime ( const char *  channelName,
unsigned  channelCount,
enum appendNumberFlag  appNF 
)

Definition at line 531 of file catime.c.

533 {
534  unsigned i;
535  int j;
536  unsigned strsize;
537  unsigned nBytesSent, nBytesRecv;
538  ti *pItemList;
539 
540  if ( channelCount == 0 ) {
541  printf ( "channel count was zero\n" );
542  return 0;
543  }
544 
545  pItemList = calloc ( channelCount, sizeof (ti) );
546  if ( ! pItemList ) {
547  return -1;
548  }
549 
551  "Unable to initialize" );
552 
553  if ( appNF == appendNumber ) {
554  printf ( "Testing with %u channels named %snnn\n",
555  channelCount, channelName );
556  }
557  else {
558  printf ( "Testing with %u channels named %s\n",
559  channelCount, channelName );
560  }
561 
562  strsize = sizeof ( pItemList[0].name ) - 1;
563  nBytesSent = 0;
564  nBytesRecv = 0;
565  for ( i=0; i < channelCount; i++ ) {
566  if ( appNF == appendNumber ) {
567  sprintf ( pItemList[i].name,"%.*s%.6u",
568  (int) (strsize - 15u), channelName, i );
569  }
570  else {
571  strncpy ( pItemList[i].name, channelName, strsize);
572  }
573  pItemList[i].name[strsize]= '\0';
574  pItemList[i].count = 0;
575  pItemList[i].pValue = 0;
576  nBytesSent += 2 * ( CA_MESSAGE_ALIGN ( strlen ( pItemList[i].name ) )
577  + sizeof (caHdr) );
578  nBytesRecv += 2 * sizeof (caHdr);
579  }
580 
581  printf ( "Channel Connect Test\n" );
582  printf ( "--------------------\n" );
583  timeIt ( test_search, pItemList, channelCount, nBytesSent, nBytesRecv );
584  printSearchStat ( pItemList, channelCount );
585 
586  for ( i = 0; i < channelCount; i++ ) {
587  size_t count = ca_element_count ( pItemList[i].chix );
588  size_t size = sizeof ( dbr_string_t ) * count;
589  pItemList[i].count = count;
590  pItemList[i].pValue = malloc ( size );
591  assert ( pItemList[i].pValue );
592  }
593 
594  printf (
595  "channel name=%s, native type=%d, native count=%u\n",
596  ca_name (pItemList[0].chix),
597  ca_field_type (pItemList[0].chix),
598  pItemList[0].count );
599 
600  printf ("Pend Event Test\n");
601  printf ( "----------------\n" );
602  timeIt ( test_pend, NULL, 100, 0, 0 );
603 
604  for ( i = 0; i < channelCount; i++ ) {
605  dbr_float_t * pFltVal = ( dbr_float_t * ) pItemList[i].pValue;
606  double val = i;
607  val /= channelCount;
608  for ( j = 0; j < pItemList[i].count; j++ ) {
609  pFltVal[j] = (dbr_float_t) val;
610  }
611  pItemList[i].type = DBR_FLOAT;
612  }
613  printf ( "DBR_FLOAT Test\n" );
614  printf ( "--------------\n" );
615  test ( pItemList, channelCount );
616 
617  for ( i = 0; i < channelCount; i++ ) {
618  dbr_double_t * pDblVal = ( dbr_double_t * ) pItemList[i].pValue;
619  double val = i;
620  val /= channelCount;
621  for ( j = 0; j < pItemList[i].count; j++ ) {
622  pDblVal[j] = (dbr_double_t) val;
623  }
624  pItemList[i].type = DBR_DOUBLE;
625  }
626  printf ( "DBR_DOUBLE Test\n" );
627  printf ( "---------------\n" );
628  test ( pItemList, channelCount );
629 
630 
631  for ( i = 0; i < channelCount; i++ ) {
632  dbr_string_t * pStrVal = ( dbr_string_t * ) pItemList[i].pValue;
633  double val = i;
634  val /= channelCount;
635  for ( j = 0; j < pItemList[i].count; j++ ) {
636  sprintf ( pStrVal[j], "%f", val );
637  }
638  pItemList[i].type = DBR_STRING;
639  }
640  printf ( "DBR_STRING Test\n" );
641  printf ( "---------------\n" );
642  test ( pItemList, channelCount );
643 
644  for ( i = 0; i < channelCount; i++ ) {
645  dbr_int_t * pIntVal = ( dbr_int_t * ) pItemList[i].pValue;
646  double val = i;
647  val /= channelCount;
648  for ( j = 0; j < pItemList[i].count; j++ ) {
649  pIntVal[j] = (dbr_int_t) val;
650  }
651  pItemList[i].type = DBR_INT;
652  }
653  printf ( "DBR_INT Test\n" );
654  printf ( "------------\n" );
655  test ( pItemList, channelCount );
656 
657  printf ( "Get Latency Test\n" );
658  printf ( "----------------\n" );
659  for ( i = 0; i < channelCount; i++ ) {
660  dbr_double_t * pDblVal = ( dbr_double_t * ) pItemList[i].pValue;
661  for ( j = 0; j < pItemList[i].count; j++ ) {
662  pDblVal[j] = 0;
663  }
664  pItemList[i].type = DBR_DOUBLE;
665  }
666  measure_get_latency ( pItemList, channelCount );
667 
668  printf ( "Free Channel Test\n" );
669  printf ( "-----------------\n" );
670  timeIt ( test_free, pItemList, channelCount, 0, 0 );
671 
672  SEVCHK ( ca_task_exit (), "Unable to free resources at exit" );
673 
674  for ( i = 0; i < channelCount; i++ ) {
675  free ( pItemList[i].pValue );
676  }
677 
678  free ( pItemList );
679 
680  return CATIME_OK;
681 }
#define CATIME_OK
Definition: caDiagnostics.h:26
int epicsStdCall ca_task_exit()
Definition: access.cpp:251
#define DBR_STRING
Definition: db_access.h:69
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
int i
Definition: scan.c:967
int count
Definition: catime.c:47
LIBCA_API unsigned long epicsStdCall ca_element_count(chid chan)
epicsFloat32 dbr_float_t
Definition: db_access.h:46
#define DBR_FLOAT
Definition: db_access.h:72
#define printf
Definition: epicsStdio.h:41
#define DBR_INT
Definition: db_access.h:70
#define NULL
Definition: catime.c:38
LIBCA_API short epicsStdCall ca_field_type(chid chan)
void * pValue
Definition: catime.c:48
void timeIt(tf *pfunc, ti *pItems, unsigned iterations, unsigned nBytesSent, unsigned nBytesRecv)
Definition: catime.c:447
int epicsStdCall ca_context_create(ca_preemptive_callback_select premptiveCallbackSelect)
Definition: access.cpp:172
char name[128]
Definition: catime.c:45
#define CA_MESSAGE_ALIGN(A)
Definition: caProto.h:154
#define SEVCHK(CA_ERROR_CODE, MESSAGE_STRING)
Definition: cadef.h:137
#define DBR_DOUBLE
Definition: db_access.h:76
epicsFloat64 dbr_double_t
Definition: db_access.h:47
LIBCA_API const char *epicsStdCall ca_name(chid chan)
epicsOldString dbr_string_t
Definition: db_access.h:38
epicsInt16 dbr_int_t
Definition: db_access.h:42
struct ca_hdr caHdr
int type
Definition: catime.c:46
void timeIt ( tf pfunc,
ti pItems,
unsigned  iterations,
unsigned  nBytesSent,
unsigned  nBytesRecv 
)

Definition at line 447 of file catime.c.

449 {
450  epicsTimeStamp end_time;
451  epicsTimeStamp start_time;
452  double delay;
453  unsigned inlineIter;
454 
455  epicsTimeGetCurrent ( &start_time );
456  (*pfunc) ( pItems, iterations, &inlineIter );
457  epicsTimeGetCurrent ( &end_time );
458  delay = epicsTimeDiffInSeconds ( &end_time, &start_time );
459  if ( delay > 0.0 ) {
460  double freq = ( iterations * inlineIter ) / delay;
461  printf ( "Per Op, %8.4f uS ( %8.4f MHz )",
462  1e6 / freq, freq / 1e6 );
463  if ( pItems != NULL ) {
464  printf(", %8.4f snd Mbps, %8.4f rcv Mbps\n",
465  (inlineIter*nBytesSent*CHAR_BIT)/(delay*1e6),
466  (inlineIter*nBytesRecv*CHAR_BIT)/(delay*1e6) );
467  }
468  else {
469  printf ("\n");
470  }
471  }
472 }
#define printf
Definition: epicsStdio.h:41
#define NULL
Definition: catime.c:38
int epicsStdCall epicsTimeGetCurrent(epicsTimeStamp *pDest)
Get current time into *pDest.
EPICS time stamp, for use from C code.
Definition: epicsTime.h:33
LIBCOM_API double epicsStdCall epicsTimeDiffInSeconds(const epicsTimeStamp *pLeft, const epicsTimeStamp *pRight)
Time difference between left and right in seconds.
Definition: epicsTime.cpp:1048