From 2b15ae7ac06ff7c55d743890174eb44560afa700 Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Fri, 12 Mar 2021 14:46:31 +0000 Subject: [PATCH] Refactor to set dead time as a shell variable and add documentation --- docs/setup.html | 16 ++++++++++++++++ src/StreamCore.cc | 6 +++--- src/StreamCore.h | 2 +- src/StreamEpics.cc | 22 +--------------------- src/makedbd.pl | 1 + 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/docs/setup.html b/docs/setup.html index 98fe6ec..b6d13e6 100644 --- a/docs/setup.html +++ b/docs/setup.html @@ -399,11 +399,25 @@ Debug output can be redirected to a file with the command When called without a filename, debug output is directed back to the console.

+

+By default the debug/error output is set to be colored if the terminal allows +it but this can be set to always colored or never colored by setting +streamDebugColored to 1 or 0 respectively. +

+

+When a device is disconnected StreamDevice can produce many repeated timeout +messages. To reduce this logging you can set streamErrorDeadTime +to an integer number of seconds. When this is set repeated timeout messages +will not be printed in the specified dead time after the last message. The +default dead time is 0, resulting in every message being printed. +

Example (vxWorks):

 streamError=1
 streamDebug=1
+streamDebugColored=1
+streamErrorDeadTime=30
 streamSetLogfile("logfile.txt")
 
@@ -411,6 +425,8 @@ streamSetLogfile("logfile.txt")
 var streamError 1
 var streamDebug 1
+var streamDebugColored 1
+var streamErrorDeadTime 30
 streamSetLogfile("logfile.txt")
 
diff --git a/src/StreamCore.cc b/src/StreamCore.cc index 3edd06e..6729a06 100644 --- a/src/StreamCore.cc +++ b/src/StreamCore.cc @@ -27,7 +27,7 @@ #define Z PRINTF_SIZE_T_PREFIX -int DeadTime = 0; +int streamErrorDeadTime = 0; /// debug functions ///////////////////////////////////////////// @@ -1848,11 +1848,11 @@ bool StreamCore::checkShouldPrint(ProtocolResult newErrorType) time(&lastErrorTime); return true; } - else if (time(NULL) - lastErrorTime > DeadTime) { + else if (time(NULL) - lastErrorTime > streamErrorDeadTime) { time(&lastErrorTime); if (numberOfErrors != 0) { error("%s: %i additional errors of the following type seen in the last %i seconds\n", - name(), numberOfErrors, DeadTime); + name(), numberOfErrors, streamErrorDeadTime); } numberOfErrors = 0; return true; diff --git a/src/StreamCore.h b/src/StreamCore.h index 240545d..7ae4661 100644 --- a/src/StreamCore.h +++ b/src/StreamCore.h @@ -96,7 +96,7 @@ const unsigned long ClearOnStart = InitRun|AsyncMode|GotValue|Aborted| AcceptInput|AcceptEvent|BusPending; // The amount of time to wait before printing duplicated messages -extern int DeadTime; +extern int streamErrorDeadTime; struct StreamFormat; diff --git a/src/StreamEpics.cc b/src/StreamEpics.cc index 7e2aa25..d1e8ca8 100644 --- a/src/StreamEpics.cc +++ b/src/StreamEpics.cc @@ -199,6 +199,7 @@ extern "C" { // needed for Windows epicsExportAddress(int, streamDebug); epicsExportAddress(int, streamError); epicsExportAddress(int, streamDebugColored); +epicsExportAddress(int, streamErrorDeadTime); } // for subroutine record @@ -261,12 +262,6 @@ long streamSetLogfile(const char* filename) return OK; } -long streamMessageDeadTime(int newDeadTime) -{ - DeadTime = newDeadTime; - return OK; -} - #ifndef EPICS_3_13 static const iocshArg streamReloadArg0 = { "recordname", iocshArgString }; @@ -304,26 +299,11 @@ void streamSetLogfileFunc (const iocshArgBuf *args) streamSetLogfile(args[0].sval); } -// Setting a dead time for messages at the IOC Console will cause repeated messages to only be periodically logged. -static const iocshArg streamMessageDeadTimeArg0 = - { "dead time (s)", iocshArgInt }; -static const iocshArg * const streamMessageDeadTimeArgs[] = - { &streamMessageDeadTimeArg0 }; -static const iocshFuncDef messageDeadTimeDef = - { "streamMessageDeadTime", 1, streamMessageDeadTimeArgs }; - -extern "C" void messageDeadTimeFunc(const iocshArgBuf *args) -{ - streamMessageDeadTime(args[0].ival); -} - - static void streamRegistrar () { iocshRegister(&streamReloadDef, streamReloadFunc); iocshRegister(&streamReportRecordDef, streamReportRecordFunc); iocshRegister(&streamSetLogfileDef, streamSetLogfileFunc); - iocshRegister(&messageDeadTimeDef, messageDeadTimeFunc); // make streamReload available for subroutine records registryFunctionAdd("streamReload", (REGISTRYFUNCTION)streamReloadSub); diff --git a/src/makedbd.pl b/src/makedbd.pl index 2ec4f4c..c480525 100644 --- a/src/makedbd.pl +++ b/src/makedbd.pl @@ -33,6 +33,7 @@ if (@ARGV[0] eq "-3.13") { print "variable(streamDebug, int)\n"; print "variable(streamError, int)\n"; print "variable(streamDebugColored, int)\n"; + print "variable(streamErrorDeadTime, int)\n"; print "registrar(streamRegistrar)\n"; if ($asyn) { print "registrar(AsynDriverInterfaceRegistrar)\n"; } }