counters: remaining s/SCPerf/Stats/g

pull/1508/head
Victor Julien 10 years ago
parent 4362d0a6e9
commit 752f03e7a4

@ -199,7 +199,7 @@ static ConfNode *GetConfig(void) {
*
* \todo Support multiple interfaces
*/
static void SCPerfInitOPCtx(void)
static void StatsInitOPCtx(void)
{
SCEnter();
ConfNode *stats = GetConfig();
@ -237,7 +237,7 @@ static void SCPerfInitOPCtx(void)
* \brief Releases the resources alloted to the output context of the Perf
* Counter API
*/
static void SCPerfReleaseOPCtx()
static void StatsReleaseOPCtx()
{
if (stats_ctx == NULL) {
SCLogDebug("Counter module has been disabled");
@ -280,7 +280,7 @@ static void SCPerfReleaseOPCtx()
*
* \retval NULL This is the value that is always returned
*/
static void *SCPerfMgmtThread(void *arg)
static void *StatsMgmtThread(void *arg)
{
/* block usr2. usr2 to be handled by the main thread only */
UtilSignalBlock(SIGUSR2);
@ -304,7 +304,7 @@ static void *SCPerfMgmtThread(void *arg)
if (stats_ctx == NULL) {
SCLogError(SC_ERR_PERF_STATS_NOT_INIT, "Perf Counter API not init"
"SCPerfInitCounterApi() has to be called first");
"StatsInitCounterApi() has to be called first");
TmThreadsSetFlag(tv_local, THV_CLOSED | THV_RUNNING_DONE);
return NULL;
}
@ -365,7 +365,7 @@ static void *SCPerfMgmtThread(void *arg)
*
* \retval NULL This is the value that is always returned
*/
static void *SCPerfWakeupThread(void *arg)
static void *StatsWakeupThread(void *arg)
{
/* block usr2. usr2 to be handled by the main thread only */
UtilSignalBlock(SIGUSR2);
@ -391,7 +391,7 @@ static void *SCPerfWakeupThread(void *arg)
if (stats_ctx == NULL) {
SCLogError(SC_ERR_PERF_STATS_NOT_INIT, "Perf Counter API not init"
"SCPerfInitCounterApi() has to be called first");
"StatsInitCounterApi() has to be called first");
TmThreadsSetFlag(tv_local, THV_CLOSED | THV_RUNNING_DONE);
return NULL;
}
@ -461,11 +461,11 @@ static void *SCPerfWakeupThread(void *arg)
/**
* \brief Releases a perf counter. Used internally by
* SCPerfReleasePerfCounterS()
* StatsReleasePerfCounterS()
*
* \param pc Pointer to the SCPerfCounter to be freed
* \param pc Pointer to the StatsCounter to be freed
*/
static void SCPerfReleaseCounter(SCPerfCounter *pc)
static void StatsReleaseCounter(StatsCounter *pc)
{
if (pc != NULL) {
if (pc->cname != NULL)
@ -493,10 +493,10 @@ static uint16_t StatsRegisterQualifiedCounter(char *cname, char *tm_name,
StatsPublicThreadContext *pctx,
int type_q, uint64_t (*Func)(void))
{
SCPerfCounter **head = &pctx->head;
SCPerfCounter *temp = NULL;
SCPerfCounter *prev = NULL;
SCPerfCounter *pc = NULL;
StatsCounter **head = &pctx->head;
StatsCounter *temp = NULL;
StatsCounter *prev = NULL;
StatsCounter *pc = NULL;
if (cname == NULL || pctx == NULL) {
SCLogDebug("Counter name, StatsPublicThreadContext NULL");
@ -519,16 +519,16 @@ static uint16_t StatsRegisterQualifiedCounter(char *cname, char *tm_name,
return(temp->id);
/* if we reach this point we don't have a counter registered by this cname */
if ( (pc = SCMalloc(sizeof(SCPerfCounter))) == NULL)
if ( (pc = SCMalloc(sizeof(StatsCounter))) == NULL)
return 0;
memset(pc, 0, sizeof(SCPerfCounter));
memset(pc, 0, sizeof(StatsCounter));
if ( (pc->cname = SCStrdup(cname)) == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory");
exit(EXIT_FAILURE);
}
/* assign a unique id to this SCPerfCounter. The id is local to this
/* assign a unique id to this StatsCounter. The id is local to this
* PerfContext. Please note that the id start from 1, and not 0 */
pc->id = ++(pctx->curr_id);
@ -545,16 +545,16 @@ static uint16_t StatsRegisterQualifiedCounter(char *cname, char *tm_name,
}
/**
* \brief Copies the SCPerfCounter value from the local counter present in the
* \brief Copies the StatsCounter value from the local counter present in the
* StatsPrivateThreadContext to its corresponding global counterpart. Used
* internally by SCPerfUpdateCounterArray()
* internally by StatsUpdateCounterArray()
*
* \param pcae Pointer to the StatsPrivateThreadContext which holds the local
* versions of the counters
*/
static void SCPerfCopyCounterValue(SCPCAElem *pcae)
static void StatsCopyCounterValue(SCPCAElem *pcae)
{
SCPerfCounter *pc = pcae->pc;
StatsCounter *pc = pcae->pc;
pc->value = pcae->value;
pc->updates = pcae->updates;
@ -574,7 +574,7 @@ static void SCPerfCopyCounterValue(SCPCAElem *pcae)
* \param pc Pointer to the PerfCounter for which the timebased counter has to
* be calculated
*/
static uint64_t SCPerfOutputCalculateCounterValue(SCPerfCounter *pc)
static uint64_t StatsOutputCalculateCounterValue(StatsCounter *pc)
{
return pc->value;
}
@ -585,7 +585,7 @@ static uint64_t SCPerfOutputCalculateCounterValue(SCPerfCounter *pc)
static int StatsOutput(ThreadVars *tv)
{
const StatsThreadStore *sts = NULL;
const SCPerfCounter *pc = NULL;
const StatsCounter *pc = NULL;
void *td = stats_thread_data;
if (stats_table.nstats == 0) {
@ -756,12 +756,12 @@ static int StatsOutput(ThreadVars *tv)
/**
* \brief The file output interface for the Perf Counter api
*/
TmEcode SCPerfOutputCounterSocket(json_t *cmd,
TmEcode StatsOutputCounterSocket(json_t *cmd,
json_t *answer, void *data)
{
StatsThreadStore *sts = NULL;
SCPerfCounter *pc = NULL;
SCPerfCounter **pc_heads = NULL;
StatsCounter *pc = NULL;
StatsCounter **pc_heads = NULL;
uint64_t ui64_temp = 0;
uint64_t ui64_result = 0;
@ -795,13 +795,13 @@ TmEcode SCPerfOutputCounterSocket(json_t *cmd,
json_string("internal error at json object creation"));
return TM_ECODE_FAILED;
}
if ((pc_heads = SCMalloc(sts->size * sizeof(SCPerfCounter *))) == NULL) {
if ((pc_heads = SCMalloc(sts->size * sizeof(StatsCounter *))) == NULL) {
json_decref(tm_array);
json_object_set_new(answer, "message",
json_string("internal memory error"));
return TM_ECODE_FAILED;
}
memset(pc_heads, 0, sts->size * sizeof(SCPerfCounter *));
memset(pc_heads, 0, sts->size * sizeof(StatsCounter *));
for (u = 0; u < sts->size; u++) {
pc_heads[u] = sts->head[u]->head;
@ -817,7 +817,7 @@ TmEcode SCPerfOutputCounterSocket(json_t *cmd,
pc = pc_heads[0];
for (u = 0; u < sts->size; u++) {
ui64_temp = SCPerfOutputCalculateCounterValue(pc_heads[u]);
ui64_temp = StatsOutputCalculateCounterValue(pc_heads[u]);
ui64_result += ui64_temp;
if (pc_heads[u] != NULL)
@ -857,7 +857,7 @@ void StatsInit(void)
{
BUG_ON(stats_ctx != NULL);
if ( (stats_ctx = SCMalloc(sizeof(StatsGlobalContext))) == NULL) {
SCLogError(SC_ERR_FATAL, "Fatal error encountered in SCPerfInitOPCtx. Exiting...");
SCLogError(SC_ERR_FATAL, "Fatal error encountered in StatsInitOPCtx. Exiting...");
exit(EXIT_FAILURE);
}
memset(stats_ctx, 0, sizeof(StatsGlobalContext));
@ -865,7 +865,7 @@ void StatsInit(void)
void StatsSetupPostConfig(void)
{
SCPerfInitOPCtx();
StatsInitOPCtx();
}
/**
@ -875,7 +875,7 @@ void StatsSetupPostConfig(void)
* The threads use the condition variable in the thread vars to control
* their wait loops to make sure the main thread can quickly kill them.
*/
void SCPerfSpawnThreads(void)
void StatsSpawnThreads(void)
{
SCEnter();
@ -887,8 +887,8 @@ void SCPerfSpawnThreads(void)
ThreadVars *tv_mgmt = NULL;
/* spawn the stats wakeup thread */
tv_wakeup = TmThreadCreateMgmtThread("SCPerfWakeupThread",
SCPerfWakeupThread, 1);
tv_wakeup = TmThreadCreateMgmtThread("StatsWakeupThread",
StatsWakeupThread, 1);
if (tv_wakeup == NULL) {
SCLogError(SC_ERR_THREAD_CREATE, "TmThreadCreateMgmtThread "
"failed");
@ -897,13 +897,13 @@ void SCPerfSpawnThreads(void)
if (TmThreadSpawn(tv_wakeup) != 0) {
SCLogError(SC_ERR_THREAD_SPAWN, "TmThreadSpawn failed for "
"SCPerfWakeupThread");
"StatsWakeupThread");
exit(EXIT_FAILURE);
}
/* spawn the stats mgmt thread */
tv_mgmt = TmThreadCreateMgmtThread("SCPerfMgmtThread",
SCPerfMgmtThread, 1);
tv_mgmt = TmThreadCreateMgmtThread("StatsMgmtThread",
StatsMgmtThread, 1);
if (tv_mgmt == NULL) {
SCLogError(SC_ERR_THREAD_CREATE,
"TmThreadCreateMgmtThread failed");
@ -912,7 +912,7 @@ void SCPerfSpawnThreads(void)
if (TmThreadSpawn(tv_mgmt) != 0) {
SCLogError(SC_ERR_THREAD_SPAWN, "TmThreadSpawn failed for "
"SCPerfWakeupThread");
"StatsWakeupThread");
exit(EXIT_FAILURE);
}
@ -1086,7 +1086,7 @@ static int StatsThreadRegister(const char *thread_name, StatsPublicThreadContext
CountersIdHashFreeFunc);
BUG_ON(stats_ctx->counters_id_hash == NULL);
}
SCPerfCounter *pc = pctx->head;
StatsCounter *pc = pctx->head;
while (pc != NULL) {
CountersIdType t = { 0, pc->cname }, *id = NULL;
id = HashTableLookup(stats_ctx->counters_id_hash, &t, sizeof(t));
@ -1135,11 +1135,11 @@ static int StatsThreadRegister(const char *thread_name, StatsPublicThreadContext
*
* \retval a counter-array in this(s_id-e_id) range for this TM instance
*/
static int SCPerfGetCounterArrayRange(uint16_t s_id, uint16_t e_id,
static int StatsGetCounterArrayRange(uint16_t s_id, uint16_t e_id,
StatsPublicThreadContext *pctx,
StatsPrivateThreadContext *pca)
{
SCPerfCounter *pc = NULL;
StatsCounter *pc = NULL;
uint32_t i = 0;
if (pctx == NULL || pca == NULL) {
@ -1188,18 +1188,18 @@ static int SCPerfGetCounterArrayRange(uint16_t s_id, uint16_t e_id,
* \retval pca Pointer to a counter-array for all counter of this tm instance
* on success; NULL on failure
*/
static int SCPerfGetAllCountersArray(StatsPublicThreadContext *pctx, StatsPrivateThreadContext *private)
static int StatsGetAllCountersArray(StatsPublicThreadContext *pctx, StatsPrivateThreadContext *private)
{
if (pctx == NULL || private == NULL)
return -1;
return SCPerfGetCounterArrayRange(1, pctx->curr_id, pctx, private);
return StatsGetCounterArrayRange(1, pctx->curr_id, pctx, private);
}
int SCPerfSetupPrivate(ThreadVars *tv)
int StatsSetupPrivate(ThreadVars *tv)
{
SCPerfGetAllCountersArray(&(tv)->perf_public_ctx, &(tv)->perf_private_ctx);
StatsGetAllCountersArray(&(tv)->perf_public_ctx, &(tv)->perf_private_ctx);
StatsThreadRegister(tv->name, &(tv)->perf_public_ctx);
return 0;
@ -1214,13 +1214,13 @@ int SCPerfSetupPrivate(ThreadVars *tv)
* \retval 0 on success
* \retval -1 on error
*/
int SCPerfUpdateCounterArray(StatsPrivateThreadContext *pca, StatsPublicThreadContext *pctx)
int StatsUpdateCounterArray(StatsPrivateThreadContext *pca, StatsPublicThreadContext *pctx)
{
SCPCAElem *pcae = NULL;
uint32_t i = 0;
if (pca == NULL || pctx == NULL) {
SCLogDebug("pca or pctx is NULL inside SCPerfUpdateCounterArray");
SCLogDebug("pca or pctx is NULL inside StatsUpdateCounterArray");
return -1;
}
@ -1228,7 +1228,7 @@ int SCPerfUpdateCounterArray(StatsPrivateThreadContext *pca, StatsPublicThreadCo
SCMutexLock(&pctx->m);
for (i = 1; i <= pca->size; i++) {
SCPerfCopyCounterValue(&pcae[i]);
StatsCopyCounterValue(&pcae[i]);
}
SCMutexUnlock(&pctx->m);
@ -1246,7 +1246,7 @@ int SCPerfUpdateCounterArray(StatsPrivateThreadContext *pca, StatsPublicThreadCo
* \retval 0 on success.
* \retval -1 on error.
*/
uint64_t SCPerfGetLocalCounterValue(ThreadVars *tv, uint16_t id)
uint64_t StatsGetLocalCounterValue(ThreadVars *tv, uint16_t id)
{
StatsPrivateThreadContext *pca = &tv->perf_private_ctx;
#ifdef DEBUG
@ -1258,9 +1258,9 @@ uint64_t SCPerfGetLocalCounterValue(ThreadVars *tv, uint16_t id)
/**
* \brief Releases the resources alloted by the Perf Counter API
*/
void SCPerfReleaseResources()
void StatsReleaseResources()
{
SCPerfReleaseOPCtx();
StatsReleaseOPCtx();
return;
}
@ -1271,14 +1271,14 @@ void SCPerfReleaseResources()
* \param head Pointer to the head of the list of perf counters that have to
* be freed
*/
void SCPerfReleasePerfCounterS(SCPerfCounter *head)
void StatsReleasePerfCounterS(StatsCounter *head)
{
SCPerfCounter *pc = NULL;
StatsCounter *pc = NULL;
while (head != NULL) {
pc = head;
head = head->next;
SCPerfReleaseCounter(pc);
StatsReleaseCounter(pc);
}
return;
@ -1290,7 +1290,7 @@ void SCPerfReleasePerfCounterS(SCPerfCounter *head)
*
* \param pca Pointer to the StatsPrivateThreadContext
*/
void SCPerfReleasePCA(StatsPrivateThreadContext *pca)
void StatsReleasePCA(StatsPrivateThreadContext *pca)
{
if (pca != NULL) {
if (pca->head != NULL) {
@ -1327,7 +1327,7 @@ static uint16_t RegisterCounter(char *cname, char *tm_name,
return id;
}
static int SCPerfTestCounterReg02()
static int StatsTestCounterReg02()
{
StatsPublicThreadContext pctx;
@ -1336,7 +1336,7 @@ static int SCPerfTestCounterReg02()
return RegisterCounter(NULL, NULL, &pctx);
}
static int SCPerfTestCounterReg03()
static int StatsTestCounterReg03()
{
StatsPublicThreadContext pctx;
int result;
@ -1345,12 +1345,12 @@ static int SCPerfTestCounterReg03()
result = RegisterCounter("t1", "c1", &pctx);
SCPerfReleasePerfCounterS(pctx.head);
StatsReleasePerfCounterS(pctx.head);
return result;
}
static int SCPerfTestCounterReg04()
static int StatsTestCounterReg04()
{
StatsPublicThreadContext pctx;
int result;
@ -1363,12 +1363,12 @@ static int SCPerfTestCounterReg04()
result = RegisterCounter("t1", "c1", &pctx);
SCPerfReleasePerfCounterS(pctx.head);
StatsReleasePerfCounterS(pctx.head);
return result;
}
static int SCPerfTestGetCntArray05()
static int StatsTestGetCntArray05()
{
ThreadVars tv;
int id;
@ -1381,11 +1381,11 @@ static int SCPerfTestGetCntArray05()
return 0;
}
int r = SCPerfGetAllCountersArray(NULL, &tv.perf_private_ctx);
int r = StatsGetAllCountersArray(NULL, &tv.perf_private_ctx);
return (r == -1) ? 1 : 0;
}
static int SCPerfTestGetCntArray06()
static int StatsTestGetCntArray06()
{
ThreadVars tv;
int id;
@ -1397,17 +1397,17 @@ static int SCPerfTestGetCntArray06()
if (id != 1)
return 0;
int r = SCPerfGetAllCountersArray(&tv.perf_public_ctx, &tv.perf_private_ctx);
int r = StatsGetAllCountersArray(&tv.perf_public_ctx, &tv.perf_private_ctx);
result = (r == 0) ? 1 : 0;
SCPerfReleasePerfCounterS(tv.perf_public_ctx.head);
SCPerfReleasePCA(&tv.perf_private_ctx);
StatsReleasePerfCounterS(tv.perf_public_ctx.head);
StatsReleasePCA(&tv.perf_private_ctx);
return result;
}
static int SCPerfTestCntArraySize07()
static int StatsTestCntArraySize07()
{
ThreadVars tv;
StatsPrivateThreadContext *pca = NULL;
@ -1420,7 +1420,7 @@ static int SCPerfTestCntArraySize07()
RegisterCounter("t1", "c1", &tv.perf_public_ctx);
RegisterCounter("t2", "c2", &tv.perf_public_ctx);
SCPerfGetAllCountersArray(&tv.perf_public_ctx, &tv.perf_private_ctx);
StatsGetAllCountersArray(&tv.perf_public_ctx, &tv.perf_private_ctx);
pca = &tv.perf_private_ctx;
StatsIncr(&tv, 1);
@ -1428,13 +1428,13 @@ static int SCPerfTestCntArraySize07()
result = pca->size;
SCPerfReleasePerfCounterS(tv.perf_public_ctx.head);
SCPerfReleasePCA(pca);
StatsReleasePerfCounterS(tv.perf_public_ctx.head);
StatsReleasePCA(pca);
return result;
}
static int SCPerfTestUpdateCounter08()
static int StatsTestUpdateCounter08()
{
ThreadVars tv;
StatsPrivateThreadContext *pca = NULL;
@ -1445,7 +1445,7 @@ static int SCPerfTestUpdateCounter08()
id = RegisterCounter("t1", "c1", &tv.perf_public_ctx);
SCPerfGetAllCountersArray(&tv.perf_public_ctx, &tv.perf_private_ctx);
StatsGetAllCountersArray(&tv.perf_public_ctx, &tv.perf_private_ctx);
pca = &tv.perf_private_ctx;
StatsIncr(&tv, id);
@ -1453,13 +1453,13 @@ static int SCPerfTestUpdateCounter08()
result = pca->head[id].value;
SCPerfReleasePerfCounterS(tv.perf_public_ctx.head);
SCPerfReleasePCA(pca);
StatsReleasePerfCounterS(tv.perf_public_ctx.head);
StatsReleasePCA(pca);
return result;
}
static int SCPerfTestUpdateCounter09()
static int StatsTestUpdateCounter09()
{
ThreadVars tv;
StatsPrivateThreadContext *pca = NULL;
@ -1474,7 +1474,7 @@ static int SCPerfTestUpdateCounter09()
RegisterCounter("t4", "c4", &tv.perf_public_ctx);
id2 = RegisterCounter("t5", "c5", &tv.perf_public_ctx);
SCPerfGetAllCountersArray(&tv.perf_public_ctx, &tv.perf_private_ctx);
StatsGetAllCountersArray(&tv.perf_public_ctx, &tv.perf_private_ctx);
pca = &tv.perf_private_ctx;
StatsIncr(&tv, id2);
@ -1482,13 +1482,13 @@ static int SCPerfTestUpdateCounter09()
result = (pca->head[id1].value == 0) && (pca->head[id2].value == 101);
SCPerfReleasePerfCounterS(tv.perf_public_ctx.head);
SCPerfReleasePCA(pca);
StatsReleasePerfCounterS(tv.perf_public_ctx.head);
StatsReleasePCA(pca);
return result;
}
static int SCPerfTestUpdateGlobalCounter10()
static int StatsTestUpdateGlobalCounter10()
{
ThreadVars tv;
StatsPrivateThreadContext *pca = NULL;
@ -1502,7 +1502,7 @@ static int SCPerfTestUpdateGlobalCounter10()
id2 = RegisterCounter("t2", "c2", &tv.perf_public_ctx);
id3 = RegisterCounter("t3", "c3", &tv.perf_public_ctx);
SCPerfGetAllCountersArray(&tv.perf_public_ctx, &tv.perf_private_ctx);
StatsGetAllCountersArray(&tv.perf_public_ctx, &tv.perf_private_ctx);
pca = &tv.perf_private_ctx;
StatsIncr(&tv, id1);
@ -1510,19 +1510,19 @@ static int SCPerfTestUpdateGlobalCounter10()
StatsIncr(&tv, id3);
StatsAddUI64(&tv, id3, 100);
SCPerfUpdateCounterArray(pca, &tv.perf_public_ctx);
StatsUpdateCounterArray(pca, &tv.perf_public_ctx);
result = (1 == tv.perf_public_ctx.head->value);
result &= (100 == tv.perf_public_ctx.head->next->value);
result &= (101 == tv.perf_public_ctx.head->next->next->value);
SCPerfReleasePerfCounterS(tv.perf_public_ctx.head);
SCPerfReleasePCA(pca);
StatsReleasePerfCounterS(tv.perf_public_ctx.head);
StatsReleasePCA(pca);
return result;
}
static int SCPerfTestCounterValues11()
static int StatsTestCounterValues11()
{
ThreadVars tv;
StatsPrivateThreadContext *pca = NULL;
@ -1537,7 +1537,7 @@ static int SCPerfTestCounterValues11()
id3 = RegisterCounter("t3", "c3", &tv.perf_public_ctx);
id4 = RegisterCounter("t4", "c4", &tv.perf_public_ctx);
SCPerfGetAllCountersArray(&tv.perf_public_ctx, &tv.perf_private_ctx);
StatsGetAllCountersArray(&tv.perf_public_ctx, &tv.perf_private_ctx);
pca = &tv.perf_private_ctx;
StatsIncr(&tv, id1);
@ -1545,7 +1545,7 @@ static int SCPerfTestCounterValues11()
StatsAddUI64(&tv, id3, 257);
StatsAddUI64(&tv, id4, 16843024);
SCPerfUpdateCounterArray(pca, &tv.perf_public_ctx);
StatsUpdateCounterArray(pca, &tv.perf_public_ctx);
result &= (1 == tv.perf_public_ctx.head->value);
@ -1555,27 +1555,27 @@ static int SCPerfTestCounterValues11()
result &= (16843024 == tv.perf_public_ctx.head->next->next->next->value);
SCPerfReleasePerfCounterS(tv.perf_public_ctx.head);
SCPerfReleasePCA(pca);
StatsReleasePerfCounterS(tv.perf_public_ctx.head);
StatsReleasePCA(pca);
return result;
}
#endif
void SCPerfRegisterTests()
void StatsRegisterTests()
{
#ifdef UNITTESTS
UtRegisterTest("SCPerfTestCounterReg02", SCPerfTestCounterReg02, 0);
UtRegisterTest("SCPerfTestCounterReg03", SCPerfTestCounterReg03, 1);
UtRegisterTest("SCPerfTestCounterReg04", SCPerfTestCounterReg04, 1);
UtRegisterTest("SCPerfTestGetCntArray05", SCPerfTestGetCntArray05, 1);
UtRegisterTest("SCPerfTestGetCntArray06", SCPerfTestGetCntArray06, 1);
UtRegisterTest("SCPerfTestCntArraySize07", SCPerfTestCntArraySize07, 2);
UtRegisterTest("SCPerfTestUpdateCounter08", SCPerfTestUpdateCounter08, 101);
UtRegisterTest("SCPerfTestUpdateCounter09", SCPerfTestUpdateCounter09, 1);
UtRegisterTest("SCPerfTestUpdateGlobalCounter10",
SCPerfTestUpdateGlobalCounter10, 1);
UtRegisterTest("SCPerfTestCounterValues11", SCPerfTestCounterValues11, 1);
UtRegisterTest("StatsTestCounterReg02", StatsTestCounterReg02, 0);
UtRegisterTest("StatsTestCounterReg03", StatsTestCounterReg03, 1);
UtRegisterTest("StatsTestCounterReg04", StatsTestCounterReg04, 1);
UtRegisterTest("StatsTestGetCntArray05", StatsTestGetCntArray05, 1);
UtRegisterTest("StatsTestGetCntArray06", StatsTestGetCntArray06, 1);
UtRegisterTest("StatsTestCntArraySize07", StatsTestCntArraySize07, 2);
UtRegisterTest("StatsTestUpdateCounter08", StatsTestUpdateCounter08, 101);
UtRegisterTest("StatsTestUpdateCounter09", StatsTestUpdateCounter09, 1);
UtRegisterTest("StatsTestUpdateGlobalCounter10",
StatsTestUpdateGlobalCounter10, 1);
UtRegisterTest("StatsTestCounterValues11", StatsTestCounterValues11, 1);
#endif
}

@ -31,7 +31,7 @@ struct ThreadVars_;
/**
* \brief Container to hold the counter variable
*/
typedef struct SCPerfCounter_ {
typedef struct StatsCounter_ {
int type;
/* local id for this counter in this tm */
@ -52,8 +52,8 @@ typedef struct SCPerfCounter_ {
char *cname;
/* the next perfcounter for this tv's tm instance */
struct SCPerfCounter_ *next;
} SCPerfCounter;
struct StatsCounter_ *next;
} StatsCounter;
/**
* \brief Holds the Perf Context for a ThreadVars instance
@ -63,7 +63,7 @@ typedef struct StatsPublicThreadContext_ {
uint32_t perf_flag;
/* pointer to the head of a list of counters assigned under this context */
SCPerfCounter *head;
StatsCounter *head;
/* holds the total no of counters already assigned for this perf context */
uint16_t curr_id;
@ -77,7 +77,7 @@ typedef struct StatsPublicThreadContext_ {
*/
typedef struct SCPCAElem_ {
/* pointer to the PerfCounter that corresponds to this PCAElem */
SCPerfCounter *pc;
StatsCounter *pc;
/* counter id of the above counter(pc) */
uint16_t id;
@ -105,8 +105,8 @@ typedef struct StatsPrivateThreadContext_ {
/* the initialization functions */
void StatsInit(void);
void StatsSetupPostConfig(void);
void SCPerfSpawnThreads(void);
void SCPerfRegisterTests(void);
void StatsSpawnThreads(void);
void StatsRegisterTests(void);
/* counter registration functions */
uint16_t StatsRegisterCounter(char *, struct ThreadVars_ *);
@ -115,33 +115,33 @@ uint16_t StatsRegisterMaxCounter(char *, struct ThreadVars_ *);
uint16_t StatsRegisterGlobalCounter(char *cname, uint64_t (*Func)(void));
/* utility functions */
int SCPerfUpdateCounterArray(StatsPrivateThreadContext *, StatsPublicThreadContext *);
uint64_t SCPerfGetLocalCounterValue(struct ThreadVars_ *, uint16_t);
int SCPerfSetupPrivate(struct ThreadVars_ *);
int StatsUpdateCounterArray(StatsPrivateThreadContext *, StatsPublicThreadContext *);
uint64_t StatsGetLocalCounterValue(struct ThreadVars_ *, uint16_t);
int StatsSetupPrivate(struct ThreadVars_ *);
/* functions used to free the resources alloted by the Perf counter API */
void SCPerfReleaseResources(void);
void SCPerfReleasePCA(StatsPrivateThreadContext *);
void StatsReleaseResources(void);
void StatsReleasePCA(StatsPrivateThreadContext *);
/* functions used to update local counter values */
void StatsAddUI64(struct ThreadVars_ *, uint16_t, uint64_t);
void StatsSetUI64(struct ThreadVars_ *, uint16_t, uint64_t);
void StatsIncr(struct ThreadVars_ *, uint16_t);
#define SCPerfSyncCounters(tv) \
SCPerfUpdateCounterArray(&(tv)->perf_private_ctx, &(tv)->perf_public_ctx); \
#define StatsSyncCounters(tv) \
StatsUpdateCounterArray(&(tv)->perf_private_ctx, &(tv)->perf_public_ctx); \
#define SCPerfSyncCountersIfSignalled(tv) \
#define StatsSyncCountersIfSignalled(tv) \
do { \
if ((tv)->perf_public_ctx.perf_flag == 1) { \
SCPerfUpdateCounterArray(&(tv)->perf_private_ctx, \
StatsUpdateCounterArray(&(tv)->perf_private_ctx, \
&(tv)->perf_public_ctx); \
} \
} while (0)
#ifdef BUILD_UNIX_SOCKET
#include <jansson.h>
TmEcode SCPerfOutputCounterSocket(json_t *cmd,
TmEcode StatsOutputCounterSocket(json_t *cmd,
json_t *answer, void *data);
#endif

@ -11263,24 +11263,24 @@ static int SigTestDetectAlertCounter(void)
DetectEngineThreadCtxInit(&tv, de_ctx, (void *)&det_ctx);
/* init counters */
SCPerfSetupPrivate(&tv);
StatsSetupPrivate(&tv);
p = UTHBuildPacket((uint8_t *)"boo", strlen("boo"), IPPROTO_TCP);
Detect(&tv, p, det_ctx, NULL, NULL);
result = (SCPerfGetLocalCounterValue(&tv, det_ctx->counter_alerts) == 1);
result = (StatsGetLocalCounterValue(&tv, det_ctx->counter_alerts) == 1);
Detect(&tv, p, det_ctx, NULL, NULL);
result &= (SCPerfGetLocalCounterValue(&tv, det_ctx->counter_alerts) == 2);
result &= (StatsGetLocalCounterValue(&tv, det_ctx->counter_alerts) == 2);
UTHFreePackets(&p, 1);
p = UTHBuildPacket((uint8_t *)"roo", strlen("roo"), IPPROTO_TCP);
Detect(&tv, p, det_ctx, NULL, NULL);
result &= (SCPerfGetLocalCounterValue(&tv, det_ctx->counter_alerts) == 2);
result &= (StatsGetLocalCounterValue(&tv, det_ctx->counter_alerts) == 2);
UTHFreePackets(&p, 1);
p = UTHBuildPacket((uint8_t *)"laboosa", strlen("laboosa"), IPPROTO_TCP);
Detect(&tv, p, det_ctx, NULL, NULL);
result &= (SCPerfGetLocalCounterValue(&tv, det_ctx->counter_alerts) == 3);
result &= (StatsGetLocalCounterValue(&tv, det_ctx->counter_alerts) == 3);
UTHFreePackets(&p, 1);
end:

@ -670,7 +670,7 @@ static TmEcode FlowManager(ThreadVars *th_v, void *thread_data)
}
if (TmThreadsCheckFlag(th_v, THV_KILL)) {
SCPerfSyncCounters(th_v);
StatsSyncCounters(th_v);
break;
}
@ -683,7 +683,7 @@ static TmEcode FlowManager(ThreadVars *th_v, void *thread_data)
SCLogDebug("woke up... %s", SC_ATOMIC_GET(flow_flags) & FLOW_EMERGENCY ? "emergency":"");
SCPerfSyncCountersIfSignalled(th_v);
StatsSyncCountersIfSignalled(th_v);
}
FlowHashDebugDeinit();
@ -822,7 +822,7 @@ static TmEcode FlowRecycler(ThreadVars *th_v, void *thread_data)
SCLogDebug("%u flows to recycle", len);
if (TmThreadsCheckFlag(th_v, THV_KILL)) {
SCPerfSyncCounters(th_v);
StatsSyncCounters(th_v);
break;
}
@ -835,7 +835,7 @@ static TmEcode FlowRecycler(ThreadVars *th_v, void *thread_data)
SCLogDebug("woke up...");
SCPerfSyncCountersIfSignalled(th_v);
StatsSyncCountersIfSignalled(th_v);
}
SCLogInfo("%"PRIu64" flows processed", recycled_cnt);

@ -203,7 +203,7 @@ void RunUnittests(int list_unittests, char *regex_arg)
FlowBitRegisterTests();
HostBitRegisterTests();
IPPairBitRegisterTests();
SCPerfRegisterTests();
StatsRegisterTests();
DecodePPPRegisterTests();
DecodeVLANRegisterTests();
HTPParserRegisterTests();

@ -306,7 +306,7 @@ TmEcode UnixSocketPcapFilesCheck(void *data)
/* mgt and ppt threads killed, we can run non thread-safe
* shutdown functions */
SCPerfReleaseResources();
StatsReleaseResources();
RunModeShutDown();
FlowShutdown();
IPPairShutdown();
@ -359,7 +359,7 @@ TmEcode UnixSocketPcapFilesCheck(void *data)
RunModeDispatch(RUNMODE_PCAP_FILE, NULL);
FlowManagerThreadSpawn();
FlowRecyclerThreadSpawn();
SCPerfSpawnThreads();
StatsSpawnThreads();
/* Un-pause all the paused threads */
TmThreadContinueThreads();
}

@ -1247,11 +1247,11 @@ TmEcode ReceiveAFPLoop(ThreadVars *tv, void *data, void *slot)
AFPSwitchState(ptv, AFP_STATE_DOWN);
continue;
}
SCPerfSyncCountersIfSignalled(tv);
StatsSyncCountersIfSignalled(tv);
}
AFPDumpCounters(ptv);
SCPerfSyncCountersIfSignalled(tv);
StatsSyncCountersIfSignalled(tv);
SCReturnInt(TM_ECODE_OK);
}
@ -1801,8 +1801,8 @@ void ReceiveAFPThreadExitStats(ThreadVars *tv, void *data)
AFPDumpCounters(ptv);
SCLogInfo("(%s) Kernel: Packets %" PRIu64 ", dropped %" PRIu64 "",
tv->name,
SCPerfGetLocalCounterValue(tv, ptv->capture_kernel_packets),
SCPerfGetLocalCounterValue(tv, ptv->capture_kernel_drops));
StatsGetLocalCounterValue(tv, ptv->capture_kernel_packets),
StatsGetLocalCounterValue(tv, ptv->capture_kernel_drops));
#endif
SCLogInfo("(%s) Packets %" PRIu64 ", bytes %" PRIu64 "", tv->name, ptv->pkts, ptv->bytes);

@ -379,7 +379,7 @@ ReceiveErfDagLoop(ThreadVars *tv, void *data, void *slot)
SCReturnInt(TM_ECODE_FAILED);
}
SCPerfSyncCountersIfSignalled(tv);
StatsSyncCountersIfSignalled(tv);
SCLogDebug("Read %d records from stream: %d, DAG: %s",
pkts_read, dtv->dagstream, dtv->dagname);
@ -558,16 +558,16 @@ ReceiveErfDagThreadExitStats(ThreadVars *tv, void *data)
ErfDagThreadVars *ewtn = (ErfDagThreadVars *)data;
(void)SC_ATOMIC_SET(ewtn->livedev->pkts,
SCPerfGetLocalCounterValue(tv, ewtn->packets));
StatsGetLocalCounterValue(tv, ewtn->packets));
(void)SC_ATOMIC_SET(ewtn->livedev->drop,
SCPerfGetLocalCounterValue(tv, ewtn->drops));
StatsGetLocalCounterValue(tv, ewtn->drops));
SCLogInfo("Stream: %d; Bytes: %"PRIu64"; Packets: %"PRIu64
"; Drops: %"PRIu64,
ewtn->dagstream,
ewtn->bytes,
SCPerfGetLocalCounterValue(tv, ewtn->packets),
SCPerfGetLocalCounterValue(tv, ewtn->drops));
StatsGetLocalCounterValue(tv, ewtn->packets),
StatsGetLocalCounterValue(tv, ewtn->drops));
}
/**

@ -307,7 +307,7 @@ TmEcode ReceiveIPFWLoop(ThreadVars *tv, void *data, void *slot)
SCReturnInt(TM_ECODE_FAILED);
}
SCPerfSyncCountersIfSignalled(tv);
StatsSyncCountersIfSignalled(tv);
}
SCReturnInt(TM_ECODE_OK);

@ -414,7 +414,7 @@ TmEcode ReceiveMpipeLoop(ThreadVars *tv, void *data, void *slot)
}
if (update_counter-- <= 0) {
/* Only periodically update and check for termination. */
SCPerfSyncCountersIfSignalled(tv);
StatsSyncCountersIfSignalled(tv);
update_counter = 10000;
if (suricata_ctl_flags != 0) {

@ -294,7 +294,7 @@ TmEcode NapatechStreamLoop(ThreadVars *tv, void *data, void *slot)
}
NT_NetRxRelease(ntv->rx_stream, packet_buffer);
SCPerfSyncCountersIfSignalled(tv);
StatsSyncCountersIfSignalled(tv);
}
SCReturnInt(TM_ECODE_OK);

@ -826,11 +826,11 @@ static TmEcode ReceiveNetmapLoop(ThreadVars *tv, void *data, void *slot)
}
NetmapDumpCounters(ntv);
SCPerfSyncCountersIfSignalled(tv);
StatsSyncCountersIfSignalled(tv);
}
SCFree(fds);
SCPerfSyncCountersIfSignalled(tv);
StatsSyncCountersIfSignalled(tv);
SCReturnInt(TM_ECODE_OK);
}
@ -847,8 +847,8 @@ static void ReceiveNetmapThreadExitStats(ThreadVars *tv, void *data)
NetmapDumpCounters(ntv);
SCLogInfo("(%s) Kernel: Packets %" PRIu64 ", dropped %" PRIu64 ", bytes %" PRIu64 "",
tv->name,
SCPerfGetLocalCounterValue(tv, ntv->capture_kernel_packets),
SCPerfGetLocalCounterValue(tv, ntv->capture_kernel_drops),
StatsGetLocalCounterValue(tv, ntv->capture_kernel_packets),
StatsGetLocalCounterValue(tv, ntv->capture_kernel_drops),
ntv->bytes);
}

@ -461,7 +461,7 @@ TmEcode ReceiveNFLOGLoop(ThreadVars *tv, void *data, void *slot)
SCLogWarning(SC_ERR_NFLOG_HANDLE_PKT,
"nflog_handle_packet error %" PRId32 "", ret);
SCPerfSyncCountersIfSignalled(tv);
StatsSyncCountersIfSignalled(tv);
}
SCReturnInt(TM_ECODE_OK);

@ -1003,7 +1003,7 @@ TmEcode ReceiveNFQLoop(ThreadVars *tv, void *data, void *slot)
}
NFQRecvPkt(nq, ntv);
SCPerfSyncCountersIfSignalled(tv);
StatsSyncCountersIfSignalled(tv);
}
SCReturnInt(TM_ECODE_OK);
}

@ -248,7 +248,7 @@ TmEcode ReceivePcapFileLoop(ThreadVars *tv, void *data, void *slot)
SCReturnInt(TM_ECODE_DONE);
}
}
SCPerfSyncCountersIfSignalled(tv);
StatsSyncCountersIfSignalled(tv);
}
SCReturnInt(TM_ECODE_OK);

@ -340,11 +340,11 @@ TmEcode ReceivePcapLoop(ThreadVars *tv, void *data, void *slot)
SCReturnInt(TM_ECODE_FAILED);
}
SCPerfSyncCountersIfSignalled(tv);
StatsSyncCountersIfSignalled(tv);
}
PcapDumpCounters(ptv);
SCPerfSyncCountersIfSignalled(tv);
StatsSyncCountersIfSignalled(tv);
SCReturnInt(TM_ECODE_OK);
}

@ -198,8 +198,8 @@ static inline void PfringDumpCounters(PfringThreadVars *ptv)
* So to get the number of packet on the interface we can add
* the newly seen packets and drops for this thread and add it
* to the interface counter */
uint64_t th_pkts = SCPerfGetLocalCounterValue(ptv->tv, ptv->capture_kernel_packets);
uint64_t th_drops = SCPerfGetLocalCounterValue(ptv->tv, ptv->capture_kernel_drops);
uint64_t th_pkts = StatsGetLocalCounterValue(ptv->tv, ptv->capture_kernel_packets);
uint64_t th_drops = StatsGetLocalCounterValue(ptv->tv, ptv->capture_kernel_drops);
SC_ATOMIC_ADD(ptv->livedev->pkts, pfring_s.recv - th_pkts);
SC_ATOMIC_ADD(ptv->livedev->drop, pfring_s.drop - th_drops);
StatsSetUI64(ptv->tv, ptv->capture_kernel_packets, pfring_s.recv);
@ -360,7 +360,7 @@ TmEcode ReceivePfringLoop(ThreadVars *tv, void *data, void *slot)
TmqhOutputPacketpool(ptv->tv, p);
SCReturnInt(TM_ECODE_FAILED);
}
SCPerfSyncCountersIfSignalled(tv);
StatsSyncCountersIfSignalled(tv);
}
return TM_ECODE_OK;
@ -548,8 +548,8 @@ void ReceivePfringThreadExitStats(ThreadVars *tv, void *data)
PfringDumpCounters(ptv);
SCLogInfo("(%s) Kernel: Packets %" PRIu64 ", dropped %" PRIu64 "",
tv->name,
SCPerfGetLocalCounterValue(tv, ptv->capture_kernel_packets),
SCPerfGetLocalCounterValue(tv, ptv->capture_kernel_drops));
StatsGetLocalCounterValue(tv, ptv->capture_kernel_packets),
StatsGetLocalCounterValue(tv, ptv->capture_kernel_drops));
SCLogInfo("(%s) Packets %" PRIu64 ", bytes %" PRIu64 "", tv->name, ptv->pkts, ptv->bytes);
}

@ -2337,7 +2337,7 @@ int main(int argc, char **argv)
/* Spawn the flow manager thread */
FlowManagerThreadSpawn();
FlowRecyclerThreadSpawn();
SCPerfSpawnThreads();
StatsSpawnThreads();
}
#ifdef __SC_CUDA_SUPPORT__
@ -2452,7 +2452,7 @@ int main(int argc, char **argv)
* the other threads are gone. */
PacketPoolDestroy();
SCPerfReleaseResources();
StatsReleaseResources();
IPPairShutdown();
FlowShutdown();
StreamTcpFreeConfig(STREAM_VERBOSE);

@ -322,7 +322,7 @@ void *TmThreadsSlotPktAcqLoop(void *td)
}
}
SCPerfSetupPrivate(tv);
StatsSetupPrivate(tv);
TmThreadsSetFlag(tv, THV_INIT_DONE);
@ -343,7 +343,7 @@ void *TmThreadsSlotPktAcqLoop(void *td)
run = 0;
}
}
SCPerfSyncCounters(tv);
StatsSyncCounters(tv);
TmThreadsSetFlag(tv, THV_FLOW_LOOP);
@ -453,7 +453,7 @@ void *TmThreadsSlotVar(void *td)
}
}
SCPerfSetupPrivate(tv);
StatsSetupPrivate(tv);
TmThreadsSetFlag(tv, THV_INIT_DONE);
@ -517,7 +517,7 @@ void *TmThreadsSlotVar(void *td)
run = 0;
}
} /* while (run) */
SCPerfSyncCounters(tv);
StatsSyncCounters(tv);
TmThreadsSetFlag(tv, THV_RUNNING_DONE);
TmThreadWaitForFlag(tv, THV_DEINIT);
@ -593,7 +593,7 @@ static void *TmThreadsManagement(void *td)
memset(&s->slot_pre_pq, 0, sizeof(PacketQueue));
memset(&s->slot_post_pq, 0, sizeof(PacketQueue));
SCPerfSetupPrivate(tv);
StatsSetupPrivate(tv);
TmThreadsSetFlag(tv, THV_INIT_DONE);
@ -604,7 +604,7 @@ static void *TmThreadsManagement(void *td)
}
if (TmThreadsCheckFlag(tv, THV_KILL)) {
SCPerfSyncCounters(tv);
StatsSyncCounters(tv);
}
TmThreadsSetFlag(tv, THV_RUNNING_DONE);

@ -85,7 +85,7 @@ Packet *TmqhInputFlow(ThreadVars *tv)
{
PacketQueue *q = &trans_q[tv->inq->id];
SCPerfSyncCountersIfSignalled(tv);
StatsSyncCountersIfSignalled(tv);
SCMutexLock(&q->mutex_q);
if (q->len == 0) {

@ -104,7 +104,7 @@ Packet *TmqhInputRingBufferMrSw(ThreadVars *t)
Packet *p = (Packet *)RingBufferMrSw8Get(rb);
SCPerfSyncCountersIfSignalled(t);
StatsSyncCountersIfSignalled(t);
return p;
}
@ -121,7 +121,7 @@ Packet *TmqhInputRingBufferSrSw(ThreadVars *t)
Packet *p = (Packet *)RingBufferSrSw8Get(rb);
SCPerfSyncCountersIfSignalled(t);
StatsSyncCountersIfSignalled(t);
return p;
}
@ -138,7 +138,7 @@ Packet *TmqhInputRingBufferSrMw(ThreadVars *t)
Packet *p = (Packet *)RingBufferSrMw8Get(rb);
SCPerfSyncCountersIfSignalled(t);
StatsSyncCountersIfSignalled(t);
return p;
}

@ -47,7 +47,7 @@ Packet *TmqhInputSimple(ThreadVars *t)
{
PacketQueue *q = &trans_q[t->inq->id];
SCPerfSyncCountersIfSignalled(t);
StatsSyncCountersIfSignalled(t);
SCMutexLock(&q->mutex_q);

@ -868,7 +868,7 @@ static TmEcode UnixManager(ThreadVars *th_v, void *thread_data)
/* set the thread name */
SCLogDebug("%s started...", th_v->name);
SCPerfSetupPrivate(th_v);
StatsSetupPrivate(th_v);
if (UnixNew(&command) == 0) {
int failure_fatal = 0;
@ -897,7 +897,7 @@ static TmEcode UnixManager(ThreadVars *th_v, void *thread_data)
UnixManagerRegisterCommand("running-mode", UnixManagerRunningModeCommand, &command, 0);
UnixManagerRegisterCommand("capture-mode", UnixManagerCaptureModeCommand, &command, 0);
UnixManagerRegisterCommand("conf-get", UnixManagerConfGetCommand, &command, UNIX_CMD_TAKE_ARGS);
UnixManagerRegisterCommand("dump-counters", SCPerfOutputCounterSocket, NULL, 0);
UnixManagerRegisterCommand("dump-counters", StatsOutputCounterSocket, NULL, 0);
UnixManagerRegisterCommand("reload-rules", UnixManagerReloadRules, NULL, 0);
TmThreadsSetFlag(th_v, THV_INIT_DONE);
@ -914,7 +914,7 @@ static TmEcode UnixManager(ThreadVars *th_v, void *thread_data)
close(item->fd);
SCFree(item);
}
SCPerfSyncCounters(th_v);
StatsSyncCounters(th_v);
break;
}

Loading…
Cancel
Save