log-stats: expand membuffer if necessary

Many threads could lead to a membuffer size requirement bigger than
64k. So use the expansion call to grow the buffer as needed.
pull/1234/head
Victor Julien 11 years ago
parent 6277d2e0e4
commit 81c42f4916

@ -47,7 +47,7 @@
#define DEFAULT_LOG_FILENAME "stats.log"
#define MODULE_NAME "LogStatsLog"
#define OUTPUT_BUFFER_SIZE 65535
#define OUTPUT_BUFFER_SIZE 16384
TmEcode LogStatsLogThreadInit(ThreadVars *, void *, void **);
TmEcode LogStatsLogThreadDeinit(ThreadVars *, void *);
@ -102,8 +102,18 @@ int LogStatsLogger(ThreadVars *tv, void *thread_data, const StatsTable *st)
for (u = 0; u < st->nstats; u++) {
if (st->stats[u].name == NULL)
break;
MemBufferWriteString(aft->buffer, "%-25s | %-25s | %-" PRIu64 "\n",
char line[1024];
size_t len = snprintf(line, sizeof(line), "%-25s | %-25s | %-" PRIu64 "\n",
st->stats[u].name, st->stats[u].tm_name, st->stats[u].value);
/* since we can have many threads, the buffer might not be big enough.
* Expand if necessary. */
if (MEMBUFFER_OFFSET(aft->buffer) + len > MEMBUFFER_SIZE(aft->buffer)) {
MemBufferExpand(&aft->buffer, OUTPUT_BUFFER_SIZE);
}
MemBufferWriteString(aft->buffer, "%s", line);
}
SCMutexLock(&aft->statslog_ctx->file_ctx->fp_mutex);

Loading…
Cancel
Save