counters: reduce global usage

pull/1562/head
Victor Julien 10 years ago
parent a5168d5977
commit 21db5ee691

@ -611,15 +611,19 @@ static int StatsOutput(ThreadVars *tv)
stats_table.start_time = stats_start_time; stats_table.start_time = stats_start_time;
} }
const uint16_t max_id = counters_global_id;
if (max_id == 0)
return -1;
/** temporary local table to merge the per thread counters, /** temporary local table to merge the per thread counters,
* especially needed for the average counters */ * especially needed for the average counters */
struct CountersMergeTable { struct CountersMergeTable {
int type; int type;
uint64_t value; uint64_t value;
uint64_t updates; uint64_t updates;
} merge_table[counters_global_id]; } merge_table[max_id];
memset(&merge_table, 0x00, memset(&merge_table, 0x00,
counters_global_id * sizeof(struct CountersMergeTable)); max_id * sizeof(struct CountersMergeTable));
int thread = stats_ctx->sts_cnt - 1; int thread = stats_ctx->sts_cnt - 1;
StatsRecord *table = stats_table.stats; StatsRecord *table = stats_table.stats;
@ -636,9 +640,9 @@ static int StatsOutput(ThreadVars *tv)
/* temporay table for quickly storing the counters for this /* temporay table for quickly storing the counters for this
* thread store, so that we can post process them outside * thread store, so that we can post process them outside
* of the thread store lock */ * of the thread store lock */
struct CountersMergeTable thread_table[counters_global_id]; struct CountersMergeTable thread_table[max_id];
memset(&thread_table, 0x00, memset(&thread_table, 0x00,
counters_global_id * sizeof(struct CountersMergeTable)); max_id * sizeof(struct CountersMergeTable));
SCMutexLock(&sts->ctx->m); SCMutexLock(&sts->ctx->m);
pc = sts->ctx->head; pc = sts->ctx->head;
@ -666,7 +670,7 @@ static int StatsOutput(ThreadVars *tv)
/* update merge table */ /* update merge table */
uint16_t c; uint16_t c;
for (c = 0; c < counters_global_id; c++) { for (c = 0; c < max_id; c++) {
struct CountersMergeTable *e = &thread_table[c]; struct CountersMergeTable *e = &thread_table[c];
/* thread only sets type if it has a counter /* thread only sets type if it has a counter
* of this type. */ * of this type. */
@ -691,7 +695,7 @@ static int StatsOutput(ThreadVars *tv)
} }
/* update per thread stats table */ /* update per thread stats table */
for (c = 0; c < counters_global_id; c++) { for (c = 0; c < max_id; c++) {
struct CountersMergeTable *e = &thread_table[c]; struct CountersMergeTable *e = &thread_table[c];
/* thread only sets type if it has a counter /* thread only sets type if it has a counter
* of this type. */ * of this type. */
@ -721,7 +725,7 @@ static int StatsOutput(ThreadVars *tv)
/* transfer 'merge table' to final stats table */ /* transfer 'merge table' to final stats table */
uint16_t x; uint16_t x;
for (x = 0; x < counters_global_id; x++) { for (x = 0; x < max_id; x++) {
/* xfer previous value to pvalue and reset value */ /* xfer previous value to pvalue and reset value */
table[x].pvalue = table[x].value; table[x].pvalue = table[x].value;
table[x].value = 0; table[x].value = 0;

Loading…
Cancel
Save