From f169cd57f9c5bc3570e203d3a6e55bb624e54462 Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Wed, 21 Apr 2004 13:46:28 +0000 Subject: [PATCH] camonitor += relative and incremental timestamps --- src/catools/camonitor.c | 21 ++++++++--- src/catools/tool_lib.c | 79 +++++++++++++++++++++++++---------------- src/catools/tool_lib.h | 16 +++++---- 3 files changed, 75 insertions(+), 41 deletions(-) diff --git a/src/catools/camonitor.c b/src/catools/camonitor.c index b6390a476..11f326171 100644 --- a/src/catools/camonitor.c +++ b/src/catools/camonitor.c @@ -29,9 +29,8 @@ #define VALID_DOUBLE_DIGITS 18 /* Max usable precision for a double */ -static int nConn = 0; /* Number of connected PVs */ - /* Event mask used */ -static unsigned long eventMask = DBE_VALUE | DBE_ALARM; +static int nConn = 0; /* Number of connected PVs */ +static unsigned long eventMask = DBE_VALUE | DBE_ALARM; /* Event mask used */ void usage (void) @@ -42,6 +41,11 @@ void usage (void) " -w : Wait time, specifies longer CA timeout, default is %f second\n" " -m : Specify CA event mask to use, with being any combination of\n" " 'v' (value), 'a' (alarm), 'l' (log). Default: va\n" + "Timestamps:\n" + " Default: Print absolute timestamps (as reported by CA)\n" + " -r: Relative timestamps (time elapsed since start of program)\n" + " -i: Incremental timestamps (time elapsed since last update)\n" + " -I: Incremental timestamps (time elapsed since last update for this channel)\n" "Enum format:\n" " -n: Print DBF_ENUM values as number (default are enum string values)\n" "Arrays: Value format: print number of requested values, then list of values\n" @@ -196,7 +200,7 @@ int main (int argc, char *argv[]) setvbuf(stdout,NULL,_IOLBF,0); /* Set stdout to line buffering */ - while ((opt = getopt(argc, argv, ":nhm:e:f:#:d:0:w:")) != -1) { + while ((opt = getopt(argc, argv, ":nhriIm:e:f:#:d:0:w:")) != -1) { switch (opt) { case 'h': /* Print usage */ usage(); @@ -204,6 +208,15 @@ int main (int argc, char *argv[]) case 'n': /* Print ENUM as index numbers */ charAsNr=1; break; + case 'r': /* Select relative timestamps */ + tsType = relative; + break; + case 'i': /* Select incremental timestamps */ + tsType = incremental; + break; + case 'I': /* Select incremental timestamps (by channel) */ + tsType = incrementalByChan; + break; case 'w': /* Set CA timeout value */ if(sscanf(optarg,"%lf", &timeout) != 1) { diff --git a/src/catools/tool_lib.c b/src/catools/tool_lib.c index cdc07447a..bf7259c13 100644 --- a/src/catools/tool_lib.c +++ b/src/catools/tool_lib.c @@ -28,14 +28,14 @@ #include "tool_lib.h" -/* Time stamps for program start, previous value (used for differential - * times with monitors) */ -static TS_STAMP tsStart, tsPrev; +/* Time stamps for program start, previous value (used for relative resp. + * incremental times with monitors) */ +static TS_STAMP tsStart, tsPrevious; static int tsInit = 0; /* Flag: Timestamps init'd */ static int firstStampPrinted = 0; /* Flag: First timestamp already printed */ -TimeT tsType = absTime; /* Timestamp type flag (-q or -Q option) */ +TimeT tsType = absolute; /* Timestamp type flag (-q or -Q option) */ IntFormatT outType = dec; /* For -0.. output format option */ char dblFormatStr[30] = "%g"; /* Format string to print doubles (see -e -f option) */ @@ -370,36 +370,53 @@ double tsDiffDbl(TS_STAMP *ts1, TS_STAMP * ts2) #define PRN_TIME_VAL_STS(TYPE,TYPE_ENUM) \ if (!tsInit) \ - { /* Initialise reference timestamp */ \ - tsStart = tsPrev = ((struct TYPE *)value)->stamp; \ + { /* Initialize start timestamp */ \ + tsStart = tsPrevious = ((struct TYPE *)value)->stamp; \ tsInit = 1; \ } \ - /* Print Timestamp */ \ - if (!firstStampPrinted) \ - { /* First stamp is always absolute */ \ - printf("%s ", tsStampToText(&(((struct TYPE *)value)->stamp), \ - TS_TEXT_MMDDYY, timeText)); \ - firstStampPrinted = 1; \ - } else { \ - switch (tsType) { \ - case incTime: /* The following can be incremental, */ \ - printf("%10.4fs ", \ - tsDiffDbl( &(((struct TYPE *)value)->stamp), \ - &tsPrev) ); \ - break; \ - case relTime: /* relative, */ \ - printf("%10.4fs ", \ - tsDiffDbl( &(((struct TYPE *)value)->stamp), \ - &tsStart)); \ - break; \ - default : /* or also absolute */ \ - printf("%s ", \ - tsStampToText( &(((struct TYPE *)value)->stamp), \ - TS_TEXT_MMDDYY, timeText)); \ - break; \ + \ + switch (tsType) { \ + case relative: \ + if (pv->firstStampPrinted) \ + { \ + printf("%10.4fs ", tsDiffDbl( &(((struct TYPE *)value)->stamp), \ + &tsStart) ); \ + } else { /* First stamp is always absolute */ \ + printf("%s ", tsStampToText(&(((struct TYPE *)value)->stamp), \ + TS_TEXT_MMDDYY, timeText)); \ + pv->firstStampPrinted = 1; \ } \ + break; \ + case incremental: \ + if (firstStampPrinted) \ + { \ + printf("%10.4fs ", tsDiffDbl( &(((struct TYPE *)value)->stamp), \ + &tsPrevious) ); \ + } else { /* First stamp is always absolute */ \ + printf("%s ", tsStampToText(&(((struct TYPE *)value)->stamp), \ + TS_TEXT_MMDDYY, timeText)); \ + firstStampPrinted = 1; \ + } \ + break; \ + case incrementalByChan: \ + if (pv->firstStampPrinted) \ + { \ + printf("%10.4fs ", tsDiffDbl( &(((struct TYPE *)value)->stamp), \ + &pv->tsPrevious) ); \ + } else { /* First stamp is always absolute */ \ + printf("%s ", tsStampToText(&(((struct TYPE *)value)->stamp), \ + TS_TEXT_MMDDYY, timeText)); \ + pv->firstStampPrinted = 1; \ + } \ + pv->tsPrevious = ((struct TYPE *)value)->stamp; \ + break; \ + default : /* Absolute */ \ + printf("%s ", tsStampToText( &(((struct TYPE *)value)->stamp), \ + TS_TEXT_MMDDYY, timeText)); \ + break; \ } \ - tsPrev = ((struct TYPE *)value)->stamp; \ + \ + tsPrevious = ((struct TYPE *)value)->stamp; \ /* Print Values */ \ for (i=0; i + /* Convert status and severity to strings */ -#define stat_to_str(stat) \ +#define stat_to_str(stat) \ ((stat) >= 0 && (stat) <= (signed)lastEpicsAlarmCond) ? \ epicsAlarmConditionStrings[stat] : "??" -#define sevr_to_str(stat) \ +#define sevr_to_str(stat) \ ((stat) >= 0 && (stat) <= (signed)lastEpicsAlarmSev) ? \ epicsAlarmSeverityStrings[stat] : "??" @@ -33,8 +35,8 @@ #define DEFAULT_TIMEOUT 1.0 /* Default CA timeout */ -/* Type of timestamp (absolute, relative, incremental) */ -typedef enum { absTime, relTime, incTime } TimeT; +/* Type of timestamp */ +typedef enum { absolute, relative, incremental, incrementalByChan } TimeT; /* Output formats for integer data types */ typedef enum { dec, bin, oct, hex } IntFormatT; @@ -50,10 +52,12 @@ typedef struct unsigned long reqElems; int status; void* value; + TS_STAMP tsPrevious; + int firstStampPrinted; } pv; -extern TimeT tsType; /* Timestamp type flag (-q or -Q option) */ +extern TimeT tsType; /* Timestamp type flag (-r -i -I options) */ extern IntFormatT outType; /* Flag used for -0.. output format option */ extern int charAsNr; /* Used for -n option (get DBF_CHAR as number) */ extern double timeout; /* Wait time default (see -w option) */ @@ -62,7 +66,7 @@ extern char dblFormatStr[]; /* Format string to print doubles (see -e -f option) extern char *val2str (const void *v, unsigned type, int index); extern char *dbr2str (const void *value, unsigned type); -extern void print_time_val_sts (const pv *pv, int nElems); +extern void print_time_val_sts (pv *pv, int nElems); extern int connect_pvs (pv *pvs, int nPvs); /*