From 25aeeebdf7d0ab2b4753189f3fca1f41078d26d8 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 29 Oct 2013 08:19:16 +0100 Subject: [PATCH] Counters: merge SCPerfCounterName into SCPerfCounter as there was a 1 on 1 mapping --- src/counters.c | 28 ++++++++++------------------ src/counters.h | 7 +++++-- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/counters.c b/src/counters.c index 00f69cfc56..5283ef7cee 100644 --- a/src/counters.c +++ b/src/counters.c @@ -463,15 +463,12 @@ static void *SCPerfWakeupThread(void *arg) static void SCPerfReleaseCounter(SCPerfCounter *pc) { if (pc != NULL) { - if (pc->name != NULL) { - if (pc->name->cname != NULL) - SCFree(pc->name->cname); + if (pc->cname != NULL) + SCFree(pc->cname); - if (pc->name->tm_name != NULL) - SCFree(pc->name->tm_name); + if (pc->tm_name != NULL) + SCFree(pc->tm_name); - SCFree(pc->name); - } if (pc->desc != NULL) SCFree(pc->desc); @@ -519,8 +516,8 @@ static uint16_t SCPerfRegisterQualifiedCounter(char *cname, char *tm_name, while (temp != NULL) { prev = temp; - if (strcmp(cname, temp->name->cname) == 0 && - strcmp(tm_name, temp->name->tm_name) == 0) { + if (strcmp(cname, temp->cname) == 0 && + strcmp(tm_name, temp->tm_name) == 0) { break; } @@ -536,17 +533,12 @@ static uint16_t SCPerfRegisterQualifiedCounter(char *cname, char *tm_name, return 0; memset(pc, 0, sizeof(SCPerfCounter)); - if ( (pc->name = SCMalloc(sizeof(SCPerfCounterName))) == NULL) { - SCFree(pc); - return 0; - } - memset(pc->name, 0, sizeof(SCPerfCounterName)); - if ( (pc->name->cname = SCStrdup(cname)) == NULL) { + if ( (pc->cname = SCStrdup(cname)) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } - if ( (pc->name->tm_name = SCStrdup(tm_name)) == NULL) { + if ( (pc->tm_name = SCStrdup(tm_name)) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); exit(EXIT_FAILURE); } @@ -678,7 +670,7 @@ static int SCPerfOutputCounterFileIface() SCMutexLock(&pctmi->head[u]->m); - while(pc_heads[u] != NULL && strcmp(pctmi->tm_name, pc_heads[u]->name->tm_name)) { + while(pc_heads[u] != NULL && strcmp(pctmi->tm_name, pc_heads[u]->tm_name)) { pc_heads[u] = pc_heads[u]->next; } } @@ -701,7 +693,7 @@ static int SCPerfOutputCounterFileIface() } fprintf(sc_perf_op_ctx->fp, "%-25s | %-25s | %-" PRIu64 "\n", - pc->name->cname, pctmi->tm_name, ui64_result); + pc->cname, pctmi->tm_name, ui64_result); } for (u = 0; u < pctmi->size; u++) diff --git a/src/counters.h b/src/counters.h index 7aa585d922..64efcb2a3c 100644 --- a/src/counters.h +++ b/src/counters.h @@ -81,11 +81,14 @@ typedef struct SCPerfCounter_ { uint64_t value; - SCPerfCounterName *name; - /* no of times the local counter has been synced with this counter */ uint64_t updated; + /* name of the counter */ + char *cname; + /* name of the thread module this counter is registered to */ + char *tm_name; + /* the next perfcounter for this tv's tm instance */ struct SCPerfCounter_ *next;