diff --git a/src/counters.c b/src/counters.c index a62183c091..2a8982b7c7 100644 --- a/src/counters.c +++ b/src/counters.c @@ -21,6 +21,141 @@ static SCPerfOPIfaceContext *sc_perf_op_ctx = NULL; +/** + * \brief Increments the local counter + * + * \param id Index of the counter in the counter array + * \param pca Counter array that holds the local counters for this TM + */ +void SCPerfCounterIncr(uint16_t id, SCPerfCounterArray *pca) +{ + if (pca == NULL) { + SCLogDebug("counterarray is NULL"); + return; + } + if ((id < 1) || (id > pca->size)) { + SCLogDebug("counter doesn't exist"); + return; + } + + switch (pca->head[id].pc->value->type) { + case SC_PERF_TYPE_UINT64: + pca->head[id].ui64_cnt++; + break; + case SC_PERF_TYPE_DOUBLE: + pca->head[id].d_cnt++; + break; + } + + if (pca->head[id].syncs == ULONG_MAX) { + pca->head[id].syncs = 0; + pca->head[id].wrapped_syncs++; + } + pca->head[id].syncs++; + + return; +} + +/** + * \brief Sets a value of type double to the local counter + * + * \param id Index of the local counter in the counter array + * \param pca Pointer to the SCPerfCounterArray + * \param x The value to set for the counter + */ +void SCPerfCounterSetUI64(uint16_t id, SCPerfCounterArray *pca, + uint64_t x) +{ + if (!pca) { + SCLogDebug("counterarray is NULL"); + return; + } + + if ((id < 1) || (id > pca->size)) { + SCLogDebug("counter doesn't exist"); + return; + } + + switch (pca->head[id].pc->value->type) { + case SC_PERF_TYPE_UINT64: + if ( (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_MAXIMUM) && + (x > pca->head[id].ui64_cnt)) { + pca->head[id].ui64_cnt = x; + } else if (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_NORMAL) { + pca->head[id].ui64_cnt = x; + } + + break; + case SC_PERF_TYPE_DOUBLE: + if ( (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_MAXIMUM) && + (x > pca->head[id].d_cnt)) { + pca->head[id].d_cnt = x; + } else if (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_NORMAL) { + pca->head[id].d_cnt = x; + } + + break; + } + + if (pca->head[id].syncs == ULONG_MAX) { + pca->head[id].syncs = 0; + pca->head[id].wrapped_syncs++; + } + pca->head[id].syncs++; + + return; +} + +/** + * \brief Sets a local counter to an arg of type double + * + * \param id Index of the local counter in the counter array + * \param pca Pointer to the SCPerfCounterArray + * \param x The value to set for the counter + */ +void SCPerfCounterSetDouble(uint16_t id, SCPerfCounterArray *pca, + double x) +{ + if (!pca) { + SCLogDebug("counterarray is NULL"); + return; + } + + if ((id < 1) || (id > pca->size)) { + SCLogDebug("counter doesn't exist"); + return; + } + + switch (pca->head[id].pc->value->type) { + case SC_PERF_TYPE_UINT64: + if ( (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_MAXIMUM) && + (x > pca->head[id].ui64_cnt)) { + pca->head[id].ui64_cnt = x; + } else if (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_NORMAL) { + pca->head[id].ui64_cnt = x; + } + + break; + case SC_PERF_TYPE_DOUBLE: + if ( (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_MAXIMUM) && + (x > pca->head[id].d_cnt)) { + pca->head[id].d_cnt = x; + } else if (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_NORMAL) { + pca->head[id].d_cnt = x; + } + + break; + } + + if (pca->head[id].syncs == ULONG_MAX) { + pca->head[id].syncs = 0; + pca->head[id].wrapped_syncs++; + } + pca->head[id].syncs++; + + return; +} + /** * \brief Get the filename with path to the stats log file. * @@ -1292,215 +1427,6 @@ int SCPerfCounterDisplay(uint16_t id, SCPerfContext *pctx, int disp) return 1; } -/** - * \brief Increments the local counter - * - * \param id Index of the counter in the counter array - * \param pca Counter array that holds the local counters for this TM - */ -inline void SCPerfCounterIncr(uint16_t id, SCPerfCounterArray *pca) -{ - if (pca == NULL) { - SCLogDebug("counterarray is NULL"); - return; - } - if ((id < 1) || (id > pca->size)) { - SCLogDebug("counter doesn't exist"); - return; - } - - switch (pca->head[id].pc->value->type) { - case SC_PERF_TYPE_UINT64: - pca->head[id].ui64_cnt++; - break; - case SC_PERF_TYPE_DOUBLE: - pca->head[id].d_cnt++; - break; - } - - if (pca->head[id].syncs == ULONG_MAX) { - pca->head[id].syncs = 0; - pca->head[id].wrapped_syncs++; - } - pca->head[id].syncs++; - - return; -} - -/** - * \brief Adds a value of type uint64_t to the local counter. - * - * \param id ID of the counter as set by the API - * \param pca Counter array that holds the local counter for this TM - * \param x Value to add to this local counter - */ -inline void SCPerfCounterAddUI64(uint16_t id, SCPerfCounterArray *pca, uint64_t x) -{ - if (!pca) { - SCLogDebug("counterarray is NULL"); - return; - } - if ((id < 1) || (id > pca->size)) { - SCLogDebug("counter doesn't exist"); - return; - } - - switch (pca->head[id].pc->value->type) { - case SC_PERF_TYPE_UINT64: - pca->head[id].ui64_cnt += x; - break; - case SC_PERF_TYPE_DOUBLE: - pca->head[id].d_cnt += x; - break; - } - - if (pca->head[id].syncs == ULONG_MAX) { - pca->head[id].syncs = 0; - pca->head[id].wrapped_syncs++; - } - pca->head[id].syncs++; - - return; -} - -/** - * \brief Adds a value of type double to the local counter - * - * \param id ID of the counter as set by the API - * \param pca Counter array that holds the local counter for this TM - * \param x Value to add to this local counter - */ -inline void SCPerfCounterAddDouble(uint16_t id, SCPerfCounterArray *pca, double x) -{ - if (!pca) { - SCLogDebug("counterarray is NULL"); - return; - } - if ((id < 1) || (id > pca->size)) { - SCLogDebug("counter doesn't exist"); - return; - } - - /* incase you are trying to add a double to a counter of type SC_PERF_TYPE_UINT64 - * it will be truncated */ - switch (pca->head[id].pc->value->type) { - case SC_PERF_TYPE_UINT64: - pca->head[id].ui64_cnt += x; - break; - case SC_PERF_TYPE_DOUBLE: - pca->head[id].d_cnt += x; - break; - } - - if (pca->head[id].syncs == ULONG_MAX) { - pca->head[id].syncs = 0; - pca->head[id].wrapped_syncs++; - } - pca->head[id].syncs++; - - return; -} - -/** - * \brief Sets a value of type double to the local counter - * - * \param id Index of the local counter in the counter array - * \param pca Pointer to the SCPerfCounterArray - * \param x The value to set for the counter - */ -inline void SCPerfCounterSetUI64(uint16_t id, SCPerfCounterArray *pca, - uint64_t x) -{ - if (!pca) { - SCLogDebug("counterarray is NULL"); - return; - } - - if ((id < 1) || (id > pca->size)) { - SCLogDebug("counter doesn't exist"); - return; - } - - switch (pca->head[id].pc->value->type) { - case SC_PERF_TYPE_UINT64: - if ( (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_MAXIMUM) && - (x > pca->head[id].ui64_cnt)) { - pca->head[id].ui64_cnt = x; - } else if (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_NORMAL) { - pca->head[id].ui64_cnt = x; - } - - break; - case SC_PERF_TYPE_DOUBLE: - if ( (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_MAXIMUM) && - (x > pca->head[id].d_cnt)) { - pca->head[id].d_cnt = x; - } else if (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_NORMAL) { - pca->head[id].d_cnt = x; - } - - break; - } - - if (pca->head[id].syncs == ULONG_MAX) { - pca->head[id].syncs = 0; - pca->head[id].wrapped_syncs++; - } - pca->head[id].syncs++; - - return; -} - -/** - * \brief Sets a local counter to an arg of type double - * - * \param id Index of the local counter in the counter array - * \param pca Pointer to the SCPerfCounterArray - * \param x The value to set for the counter - */ -inline void SCPerfCounterSetDouble(uint16_t id, SCPerfCounterArray *pca, - double x) -{ - if (!pca) { - SCLogDebug("counterarray is NULL"); - return; - } - - if ((id < 1) || (id > pca->size)) { - SCLogDebug("counter doesn't exist"); - return; - } - - switch (pca->head[id].pc->value->type) { - case SC_PERF_TYPE_UINT64: - if ( (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_MAXIMUM) && - (x > pca->head[id].ui64_cnt)) { - pca->head[id].ui64_cnt = x; - } else if (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_NORMAL) { - pca->head[id].ui64_cnt = x; - } - - break; - case SC_PERF_TYPE_DOUBLE: - if ( (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_MAXIMUM) && - (x > pca->head[id].d_cnt)) { - pca->head[id].d_cnt = x; - } else if (pca->head[id].pc->type_q->type & SC_PERF_TYPE_Q_NORMAL) { - pca->head[id].d_cnt = x; - } - - break; - } - - if (pca->head[id].syncs == ULONG_MAX) { - pca->head[id].syncs = 0; - pca->head[id].wrapped_syncs++; - } - pca->head[id].syncs++; - - return; -} - /** * \brief Syncs the counter array with the global counter variables * diff --git a/src/counters.h b/src/counters.h index ff44a96ee8..c42cefed3a 100644 --- a/src/counters.h +++ b/src/counters.h @@ -221,13 +221,6 @@ SCPerfCounterArray *SCPerfGetCounterArrayRange(uint16_t, uint16_t, SCPerfContext SCPerfCounterArray * SCPerfGetAllCountersArray(SCPerfContext *); int SCPerfCounterDisplay(uint16_t, SCPerfContext *, int); -/* functions used to update local counter values */ -inline void SCPerfCounterIncr(uint16_t, SCPerfCounterArray *); -inline void SCPerfCounterAddUI64(uint16_t, SCPerfCounterArray *, uint64_t); -inline void SCPerfCounterAddDouble(uint16_t, SCPerfCounterArray *, double); -inline void SCPerfCounterSetUI64(uint16_t, SCPerfCounterArray *, uint64_t); -inline void SCPerfCounterSetDouble(uint16_t, SCPerfCounterArray *, double); - int SCPerfUpdateCounterArray(SCPerfCounterArray *, SCPerfContext *, int); double SCPerfGetLocalCounterValue(uint16_t, SCPerfCounterArray *); @@ -238,6 +231,89 @@ void SCPerfReleaseResources(void); void SCPerfReleasePerfCounterS(SCPerfCounter *); void SCPerfReleasePCA(SCPerfCounterArray *); +void SCPerfCounterSetUI64(uint16_t, SCPerfCounterArray *, uint64_t); +void SCPerfCounterSetDouble(uint16_t, SCPerfCounterArray *, double); +void SCPerfCounterIncr(uint16_t, SCPerfCounterArray *); + void SCPerfRegisterTests(void); +/** ------------ Inlined functions ----------- */ +/* functions used to update local counter values */ +static inline void SCPerfCounterAddUI64(uint16_t, SCPerfCounterArray *, uint64_t); +static inline void SCPerfCounterAddDouble(uint16_t, SCPerfCounterArray *, double); + +/** + * \brief Adds a value of type uint64_t to the local counter. + * + * \param id ID of the counter as set by the API + * \param pca Counter array that holds the local counter for this TM + * \param x Value to add to this local counter + */ +static inline void SCPerfCounterAddUI64(uint16_t id, SCPerfCounterArray *pca, uint64_t x) +{ + if (!pca) { + SCLogDebug("counterarray is NULL"); + return; + } + if ((id < 1) || (id > pca->size)) { + SCLogDebug("counter doesn't exist"); + return; + } + + switch (pca->head[id].pc->value->type) { + case SC_PERF_TYPE_UINT64: + pca->head[id].ui64_cnt += x; + break; + case SC_PERF_TYPE_DOUBLE: + pca->head[id].d_cnt += x; + break; + } + + if (pca->head[id].syncs == ULONG_MAX) { + pca->head[id].syncs = 0; + pca->head[id].wrapped_syncs++; + } + pca->head[id].syncs++; + + return; +} + +/** + * \brief Adds a value of type double to the local counter + * + * \param id ID of the counter as set by the API + * \param pca Counter array that holds the local counter for this TM + * \param x Value to add to this local counter + */ +static inline void SCPerfCounterAddDouble(uint16_t id, SCPerfCounterArray *pca, double x) +{ + if (!pca) { + SCLogDebug("counterarray is NULL"); + return; + } + if ((id < 1) || (id > pca->size)) { + SCLogDebug("counter doesn't exist"); + return; + } + + /* incase you are trying to add a double to a counter of type SC_PERF_TYPE_UINT64 + * it will be truncated */ + switch (pca->head[id].pc->value->type) { + case SC_PERF_TYPE_UINT64: + pca->head[id].ui64_cnt += x; + break; + case SC_PERF_TYPE_DOUBLE: + pca->head[id].d_cnt += x; + break; + } + + if (pca->head[id].syncs == ULONG_MAX) { + pca->head[id].syncs = 0; + pca->head[id].wrapped_syncs++; + } + pca->head[id].syncs++; + + return; +} + #endif /* __COUNTERS_H__ */