From 976cced633c8e03409b2bb423c61fbc8a4f3a374 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Thu, 9 Mar 2023 12:40:12 +0100 Subject: [PATCH 01/10] caPutLog: Add total count for logged puts --- caPutLogApp/caPutLogTask.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/caPutLogApp/caPutLogTask.c b/caPutLogApp/caPutLogTask.c index 51a81d9..81a5561 100644 --- a/caPutLogApp/caPutLogTask.c +++ b/caPutLogApp/caPutLogTask.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include "caPutLog.h" @@ -112,6 +113,8 @@ static volatile int caPutLogConfig; int caPutLogDebug = 0; epicsExportAddress(int, caPutLogDebug); +int caPutLogTotalCount = 0; + #define MAX_MSGS 1000 /* The length of queue (in messages) */ #define MSG_SIZE sizeof(LOGDATA*) /* We store only pointers */ @@ -184,6 +187,7 @@ void caPutLogTaskShow(void) default: state = "invalid"; } printf("caPutLog mode: %d = %s\n", caPutLogConfig, state); + printf("caPutLog Total Count: %d\n", epicsAtomicGetIntT(&caPutLogTotalCount)); } void caPutLogTaskStop(void) @@ -285,6 +289,7 @@ static void caPutLogTask(void *arg) else { /* Next put of multiple puts */ if (isDbrNumeric(pcurrent->type)) { burst = TRUE; + epicsAtomicIncrIntT(&caPutLogTotalCount); val_max(pmax, &pcurrent->new_value.value, pmax, pcurrent->type); val_min(pmin, &pcurrent->new_value.value, pmin, pcurrent->type); } From 0e08853d8adac8a8360de8c35addab5b7c75f158 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Thu, 9 Mar 2023 12:41:25 +0100 Subject: [PATCH 02/10] caPutLog: Add counter for burst puts in the log message --- caPutLogApp/caPutLogTask.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/caPutLogApp/caPutLogTask.c b/caPutLogApp/caPutLogTask.c index 81a5561..fc1f477 100644 --- a/caPutLogApp/caPutLogTask.c +++ b/caPutLogApp/caPutLogTask.c @@ -224,9 +224,11 @@ void caPutLogSetTimeFmt (const char *format) static void caPutLogTask(void *arg) { - int sent = FALSE, burst = FALSE; + int sent = FALSE; + int burst = 0; int config; int msg_size; + LOGDATA *pcurrent, *pnext; VALUE old_value, max_value, min_value; VALUE *pold=&old_value, *pmax=&max_value, *pmin=&min_value; @@ -261,7 +263,7 @@ static void caPutLogTask(void *arg) log_msg(pold, pcurrent, burst, pmin, pmax, config); val_assign(pold, &pcurrent->new_value.value, pcurrent->type); sent = TRUE; - burst = FALSE; + burst = 0; } } else if (msg_size != MSG_SIZE) { @@ -284,11 +286,11 @@ static void caPutLogTask(void *arg) val_assign(pmin, &pcurrent->new_value.value, pcurrent->type); sent = FALSE; - burst = FALSE; /* First message after logging */ + burst = 0; /* First message after logging */ } else { /* Next put of multiple puts */ if (isDbrNumeric(pcurrent->type)) { - burst = TRUE; + burst++; epicsAtomicIncrIntT(&caPutLogTotalCount); val_max(pmax, &pcurrent->new_value.value, pmax, pcurrent->type); val_min(pmin, &pcurrent->new_value.value, pmin, pcurrent->type); @@ -318,7 +320,7 @@ static void caPutLogTask(void *arg) val_assign(pmin, &pcurrent->new_value.value, pcurrent->type); sent = FALSE; - burst = FALSE; + burst = 0; } } errlogSevPrintf(errlogInfo, "caPutLog: log task exiting\n"); @@ -402,6 +404,10 @@ static void log_msg(const VALUE *pold_value, const LOGDATA *pLogData, if (len >= space) { do_log(msg, space-1, YES); return; } len += val_to_string(msg+len, space-len, pmax, pLogData->type); if (len >= space) { do_log(msg, space-1, YES); return; } + + /* burst count */ + len += epicsSnprintf(msg+len, space-len, " burst_count=%d", burst); + if (len >= space) { do_log(msg, space-1, YES); return; } } do_log(msg, len, NO); } From a59ac95d20726a7f4c6d922420cde329ff6e68f1 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Thu, 9 Mar 2023 13:13:31 +0100 Subject: [PATCH 03/10] caPutJsonLog: Add burst count to log message --- caPutLogApp/caPutJsonLogTask.cpp | 19 +++++++++++++------ caPutLogApp/caPutJsonLogTask.h | 6 +++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/caPutLogApp/caPutJsonLogTask.cpp b/caPutLogApp/caPutJsonLogTask.cpp index a9c20c8..15d9894 100644 --- a/caPutLogApp/caPutJsonLogTask.cpp +++ b/caPutLogApp/caPutJsonLogTask.cpp @@ -272,7 +272,8 @@ caPutJsonLogStatus CaPutJsonLogTask::configurePvLogging() void CaPutJsonLogTask::caPutJsonLogTask(void *arg) { - bool sent = false, burst = false; + bool sent = false; + int burst = 0; LOGDATA *pcurrent, *pnext; VALUE old_value, max_value, min_value; VALUE *pold=&old_value, *pmax=&max_value, *pmin=&min_value; @@ -301,7 +302,7 @@ void CaPutJsonLogTask::caPutJsonLogTask(void *arg) buildJsonMsg(pold, pcurrent, burst, pmin, pmax); std::memcpy(pold, &pcurrent->new_value.value, sizeof(VALUE)); sent = true; - burst = false; + burst = 0; } } @@ -326,12 +327,12 @@ void CaPutJsonLogTask::caPutJsonLogTask(void *arg) std::memcpy(pmin, &pcurrent->new_value.value, sizeof(VALUE)); sent = false; - burst = false; + burst = 0; } // Multiple puts within timeout else { if (isDbrNumeric(pcurrent->type) && pcurrent->new_size == 1) { - burst = true; + burst++; calculateMax(pmax, &pcurrent->new_value.value, pmax, pcurrent->type); calculateMin(pmin, &pcurrent->new_value.value, pmin, pcurrent->type); } @@ -356,7 +357,7 @@ void CaPutJsonLogTask::caPutJsonLogTask(void *arg) std::memcpy(pmin, &pcurrent->new_value.value, sizeof(VALUE)); sent = false; - burst = false; + burst = 0; } } epics::atomic::set(this->taskStopper, false); @@ -383,7 +384,7 @@ void CaPutJsonLogTask::addPutToQueue(LOGDATA * plogData) } caPutJsonLogStatus CaPutJsonLogTask::buildJsonMsg(const VALUE *pold_value, const LOGDATA *pLogData, - bool burst, const VALUE *pmin, const VALUE *pmax) + int burst, const VALUE *pmin, const VALUE *pmax) { // Intermediate message build buffer // The longest message for the buffer can occur in the lso/lsi records which @@ -583,6 +584,12 @@ caPutJsonLogStatus CaPutJsonLogTask::buildJsonMsg(const VALUE *pold_value, const CALL_YAJL_FUNCTION_AND_CHECK_STATUS(status, yajl_gen_number(handle, reinterpret_cast(interBuffer), strlen(reinterpret_cast(interBuffer)))); + + // Add burst count + const unsigned char str_burst[] = "burst_count"; + CALL_YAJL_FUNCTION_AND_CHECK_STATUS(status, yajl_gen_string(handle, str_burst, + strlen(reinterpret_cast(str_burst)))); + CALL_YAJL_FUNCTION_AND_CHECK_STATUS(status, yajl_gen_integer(handle, burst)); } /* Close root map */ diff --git a/caPutLogApp/caPutJsonLogTask.h b/caPutLogApp/caPutJsonLogTask.h index 3df4889..8f655b2 100644 --- a/caPutLogApp/caPutJsonLogTask.h +++ b/caPutLogApp/caPutJsonLogTask.h @@ -55,7 +55,7 @@ enum specialValues { * \code{.txt} * {"date": "
--"","time":"::","host":"","user":"","pv":"","new":,"old":""}\n * \endcode - * Burst puts add extra JSON properties (supported only for numberic scalar puts): + * Burst puts add extra JSON properties (supported only for numeric scalar puts): * - "min": Which is a minimum value inside the burst period * - "max": Represents maximum value inside the burst of puts * Array puts add following JSON properties: @@ -183,13 +183,13 @@ class epicsShareClass CaPutJsonLogTask { * * @param pold_value Pointer to a ::VALUE structure holding an old PV value. * @param pLogData Pointer to a ::LOGDATA structure holding new value and other meta databa about the put. - * @param burst Boolean value. It determinate if put was a burst of values. + * @param burst Integer value. Indicates the number of burst of values, if any. * @param pmin Pointer to a ::VALUE structure holding an min value if burst is true. * @param pmax Pointer to a ::VALUE structure holding an max value if burst is true. * @return int Status code. */ caPutJsonLogStatus buildJsonMsg(const VALUE *pold_value, const LOGDATA *pLogData, - bool burst, const VALUE *pmin, const VALUE *pmax); + int burst, const VALUE *pmin, const VALUE *pmax); /** * @brief Configure logging to a server. From 19790815e16c0fcfc91dffa34db90e95fb67514d Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Thu, 9 Mar 2023 13:31:16 +0100 Subject: [PATCH 04/10] caPutLog: Fix counting of non-burst puts --- caPutLogApp/caPutLogTask.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/caPutLogApp/caPutLogTask.c b/caPutLogApp/caPutLogTask.c index fc1f477..7dece77 100644 --- a/caPutLogApp/caPutLogTask.c +++ b/caPutLogApp/caPutLogTask.c @@ -276,10 +276,11 @@ static void caPutLogTask(void *arg) } /* current and next are same pv */ - caPutLogDataFree(pcurrent); pcurrent = pnext; + epicsAtomicIncrIntT(&caPutLogTotalCount); + if (sent) { /* Set new initial max & min values */ val_assign(pmax, &pcurrent->new_value.value, pcurrent->type); @@ -291,7 +292,6 @@ static void caPutLogTask(void *arg) else { /* Next put of multiple puts */ if (isDbrNumeric(pcurrent->type)) { burst++; - epicsAtomicIncrIntT(&caPutLogTotalCount); val_max(pmax, &pcurrent->new_value.value, pmax, pcurrent->type); val_min(pmin, &pcurrent->new_value.value, pmin, pcurrent->type); } @@ -312,6 +312,8 @@ static void caPutLogTask(void *arg) caPutLogDataFree(pcurrent); pcurrent = pnext; + epicsAtomicIncrIntT(&caPutLogTotalCount); + /* Set new old_value */ val_assign(pold, &pcurrent->old_value, pcurrent->type); From 2a8a3934cc0cc24084d32331f13c7956f103b178 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Thu, 9 Mar 2023 14:27:00 +0100 Subject: [PATCH 05/10] Small typo fix in caPutJsonLogTask header --- caPutLogApp/caPutJsonLogTask.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caPutLogApp/caPutJsonLogTask.h b/caPutLogApp/caPutJsonLogTask.h index 8f655b2..272d5b3 100644 --- a/caPutLogApp/caPutJsonLogTask.h +++ b/caPutLogApp/caPutJsonLogTask.h @@ -144,7 +144,7 @@ class epicsShareClass CaPutJsonLogTask { private: - // Singelton instance of this class. + // Singleton instance of this class. static CaPutJsonLogTask *instance; // Logger configuration From da784a811c83ef2d5d0a112b4e8f6e44dcb973d8 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Thu, 9 Mar 2023 14:28:14 +0100 Subject: [PATCH 06/10] caPutJsonLog: Add total put count to caPutJsonLogShow --- caPutLogApp/caPutJsonLogTask.cpp | 7 +++++++ caPutLogApp/caPutJsonLogTask.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/caPutLogApp/caPutJsonLogTask.cpp b/caPutLogApp/caPutJsonLogTask.cpp index 15d9894..4313661 100644 --- a/caPutLogApp/caPutJsonLogTask.cpp +++ b/caPutLogApp/caPutJsonLogTask.cpp @@ -107,6 +107,7 @@ caPutJsonLogStatus CaPutJsonLogTask::report(int level) for (client = clients; client; client = client->next) { logClientShow(client->caPutJsonLogClient, level); } + printf("caPutJsonLog: Total count = %d\n", epics::atomic::get(this->caPutTotalCount)); return caPutJsonLogSuccess; } else { @@ -278,6 +279,8 @@ void CaPutJsonLogTask::caPutJsonLogTask(void *arg) VALUE old_value, max_value, min_value; VALUE *pold=&old_value, *pmax=&max_value, *pmin=&min_value; + epics::atomic::set(this->caPutTotalCount, 0); + // Receive 1st message this->caPutJsonLogQ.receive(&pcurrent, sizeof(LOGDATA *)); std::memcpy(pold, &pcurrent->old_value, sizeof(VALUE)); @@ -320,6 +323,8 @@ void CaPutJsonLogTask::caPutJsonLogTask(void *arg) caPutLogDataFree(pcurrent); pcurrent = pnext; + epics::atomic::increment(this->caPutTotalCount); + // First message after logging if (sent) { // Set new initial max & min values @@ -349,6 +354,8 @@ void CaPutJsonLogTask::caPutJsonLogTask(void *arg) caPutLogDataFree(pcurrent); pcurrent = pnext; + epics::atomic::increment(this->caPutTotalCount); + /* Set new old_value */ std::memcpy(pold, &pcurrent->old_value, sizeof(VALUE)); diff --git a/caPutLogApp/caPutJsonLogTask.h b/caPutLogApp/caPutJsonLogTask.h index 272d5b3..67a7832 100644 --- a/caPutLogApp/caPutJsonLogTask.h +++ b/caPutLogApp/caPutJsonLogTask.h @@ -169,6 +169,8 @@ class epicsShareClass CaPutJsonLogTask { DBADDR caPutJsonLogPV; DBADDR *pCaPutJsonLogPV; + // Total count of logged puts + int caPutTotalCount; // To modify or read this value only epicsAtomic methods should be used // Class methods (Do not allow public constructors - class is designed as singleton) CaPutJsonLogTask(); From f1fb08ac7555a17fbd0cd0c77d6556f02821a4b1 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Thu, 9 Mar 2023 14:36:36 +0100 Subject: [PATCH 07/10] Add documentation for burst counter --- docs/index.rst | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 268640b..41e0766 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -201,12 +201,13 @@ record.field name, and is either:: or:: - new= old= min= max= + new= old= min= max= burst_count= The latter format means that several puts for the same PV were received in quick succession; in this case only the original and final values of the burst as well -as the minimum and maximum values seen are logged. This burst filtering can be -disabled by selecting the ``caPutLogAllNoFilter`` (``2``) configuration value. +as the minimum and maximum values seen are logged. The number of successive puts +filtered is also logged. This burst filtering can be disabled by selecting the +``caPutLogAllNoFilter`` (``2``) configuration value. From release 4.0 on, string values are placed inside quotes, and special characters within the string are escaped. The default date/time format @@ -227,7 +228,8 @@ It looks like this:: "pv":"", "new":,["new-size":,] "old":[,"old-size":] - [,"min":][,"max":]} + [,"min":][,"max":] + [,"burst_count":]} The JSON properties are: @@ -266,6 +268,8 @@ The JSON properties are: * **max** value is included only if the burst filtering was applied and gives the maximum value of the puts received within the burst period. + * **burst_count** number of filtered puts in the burst period. + The JSON implementation of the logger added support for arrays and long string fields. As these values can get very large, there is a limit to how long the **new value** and **old value** properties can be. Each value can use up to 400 @@ -297,7 +301,8 @@ Burst of scalar values:: "host":"devWs","user":"devman", "pv":"ao", "new":8,"old":77.5, - "min":7.5,"max":870.5} + "min":7.5,"max":870.5, + "burst_count"=10} String value:: @@ -400,4 +405,3 @@ If you have any problems with this module, send me (`Ben Franksen`_) a mail. .. _R3-3: releasenotes.rst#r3-3-changes-since-r3-2 .. _R3-2: releasenotes.rst#r3-2-changes-since-r3-1 .. _R3-1: releasenotes.rst#r3-1-changes-since-r3-0 - From 74c123db9694cb210a88b811d13f7277ec5e8aa0 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Thu, 9 Mar 2023 14:37:33 +0100 Subject: [PATCH 08/10] Add documentation regarding total put counter --- docs/index.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index 41e0766..00a12c2 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -161,7 +161,8 @@ Other shell commands for controlling the logger are: ``caPutLogShow level`` / ``caPutJsonLogShow level`` Show information about an active logger, including its current ``config`` - setting. ``level`` is the usual interest level (0, 1, or 2). + setting and total number of logged puts. ``level`` is the usual interest + level (0, 1, or 2). Set up a Log Server From 604d4ec7c6d55f1f99f368b650b441ed7d83d6ee Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Fri, 10 Mar 2023 10:19:29 +0100 Subject: [PATCH 09/10] Shorten burst counter identifier in log message --- caPutLogApp/caPutJsonLogTask.cpp | 2 +- caPutLogApp/caPutLogTask.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/caPutLogApp/caPutJsonLogTask.cpp b/caPutLogApp/caPutJsonLogTask.cpp index 4313661..da15ac2 100644 --- a/caPutLogApp/caPutJsonLogTask.cpp +++ b/caPutLogApp/caPutJsonLogTask.cpp @@ -593,7 +593,7 @@ caPutJsonLogStatus CaPutJsonLogTask::buildJsonMsg(const VALUE *pold_value, const strlen(reinterpret_cast(interBuffer)))); // Add burst count - const unsigned char str_burst[] = "burst_count"; + const unsigned char str_burst[] = "burst"; CALL_YAJL_FUNCTION_AND_CHECK_STATUS(status, yajl_gen_string(handle, str_burst, strlen(reinterpret_cast(str_burst)))); CALL_YAJL_FUNCTION_AND_CHECK_STATUS(status, yajl_gen_integer(handle, burst)); diff --git a/caPutLogApp/caPutLogTask.c b/caPutLogApp/caPutLogTask.c index 7dece77..e57c9f2 100644 --- a/caPutLogApp/caPutLogTask.c +++ b/caPutLogApp/caPutLogTask.c @@ -408,7 +408,7 @@ static void log_msg(const VALUE *pold_value, const LOGDATA *pLogData, if (len >= space) { do_log(msg, space-1, YES); return; } /* burst count */ - len += epicsSnprintf(msg+len, space-len, " burst_count=%d", burst); + len += epicsSnprintf(msg+len, space-len, " burst=%d", burst); if (len >= space) { do_log(msg, space-1, YES); return; } } do_log(msg, len, NO); From 18ba33905ecee6049af11d39a3223a179ca3ad3e Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Fri, 10 Mar 2023 13:14:25 +0100 Subject: [PATCH 10/10] Fix burst count key in documentation Changed from burst_count to burst --- docs/index.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 00a12c2..4b60923 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -202,7 +202,7 @@ record.field name, and is either:: or:: - new= old= min= max= burst_count= + new= old= min= max= burst= The latter format means that several puts for the same PV were received in quick succession; in this case only the original and final values of the burst as well @@ -230,7 +230,7 @@ It looks like this:: "new":,["new-size":,] "old":[,"old-size":] [,"min":][,"max":] - [,"burst_count":]} + [,"burst":]} The JSON properties are: @@ -269,7 +269,7 @@ The JSON properties are: * **max** value is included only if the burst filtering was applied and gives the maximum value of the puts received within the burst period. - * **burst_count** number of filtered puts in the burst period. + * **burst** number of filtered puts in the burst period. The JSON implementation of the logger added support for arrays and long string fields. As these values can get very large, there is a limit to how long the @@ -303,7 +303,7 @@ Burst of scalar values:: "pv":"ao", "new":8,"old":77.5, "min":7.5,"max":870.5, - "burst_count"=10} + "burst"=10} String value::