counters: make DNS counters globals

pull/1508/head
Victor Julien 11 years ago
parent ac069c579a
commit 0a262acdfb

@ -103,12 +103,22 @@ int DNSCheckMemcap(uint32_t want, DNSState *state)
return 0;
}
void DNSMemcapGetCounters(uint64_t *memuse, uint64_t *memcap_state,
uint64_t *memcap_global)
uint64_t DNSMemcapGetMemuseCounter(void)
{
*memuse = SC_ATOMIC_GET(dns_memuse);
*memcap_state = SC_ATOMIC_GET(dns_memcap_state);
*memcap_global = SC_ATOMIC_GET(dns_memcap_global);
uint64_t x = SC_ATOMIC_GET(dns_memuse);
return x;
}
uint64_t DNSMemcapGetMemcapStateCounter(void)
{
uint64_t x = SC_ATOMIC_GET(dns_memcap_state);
return x;
}
uint64_t DNSMemcapGetMemcapGlobalCounter(void)
{
uint64_t x = SC_ATOMIC_GET(dns_memcap_global);
return x;
}
SCEnumCharMap dns_decoder_event_table[ ] = {

@ -206,8 +206,9 @@ void DNSConfigSetGlobalMemcap(uint64_t value);
void DNSIncrMemcap(uint32_t size, DNSState *state);
void DNSDecrMemcap(uint32_t size, DNSState *state);
int DNSCheckMemcap(uint32_t want, DNSState *state);
void DNSMemcapGetCounters(uint64_t *memuse, uint64_t *memcap_state,
uint64_t *memcap_global);
uint64_t DNSMemcapGetMemuseCounter(void);
uint64_t DNSMemcapGetMemcapStateCounter(void);
uint64_t DNSMemcapGetMemcapGlobalCounter(void);
void RegisterDNSParsers(void);
void DNSParserTests(void);

@ -358,6 +358,10 @@ void RegisterDNSUDPParsers(void)
{
char *proto_name = "dns";
StatsRegisterGlobalCounter("dns.memuse", DNSMemcapGetMemuseCounter);
StatsRegisterGlobalCounter("dns.memcap_state", DNSMemcapGetMemcapStateCounter);
StatsRegisterGlobalCounter("dns.memcap_global", DNSMemcapGetMemcapGlobalCounter);
/** DNS */
if (AppLayerProtoDetectConfProtoDetectionEnabled("udp", proto_name)) {
AppLayerProtoDetectRegisterProtocol(ALPROTO_DNS, proto_name);

@ -55,10 +55,6 @@ struct AppLayerThreadCtx_ {
/* App layer parser thread context, from AppLayerParserThreadCtxAlloc(). */
AppLayerParserThreadCtx *alp_tctx;
uint16_t counter_dns_memuse;
uint16_t counter_dns_memcap_state;
uint16_t counter_dns_memcap_global;
#ifdef PROFILING
uint64_t ticks_start;
uint64_t ticks_end;
@ -70,19 +66,6 @@ struct AppLayerThreadCtx_ {
#endif
};
/** \todo move this into the DNS code. Problem is that there we can't
* access AppLayerThreadCtx internals. */
static void DNSUpdateCounters(ThreadVars *tv, AppLayerThreadCtx *app_tctx)
{
uint64_t memuse = 0, memcap_state = 0, memcap_global = 0;
DNSMemcapGetCounters(&memuse, &memcap_state, &memcap_global);
StatsSetUI64(tv, app_tctx->counter_dns_memuse, memuse);
StatsSetUI64(tv, app_tctx->counter_dns_memcap_state, memcap_state);
StatsSetUI64(tv, app_tctx->counter_dns_memcap_global, memcap_global);
}
/***** L7 layer dispatchers *****/
static void DisableAppLayer(Flow *f)
@ -434,9 +417,6 @@ int AppLayerHandleTCPData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,
}
}
/** \fixme a bit hacky but will be improved in 2.1 */
if (*alproto == ALPROTO_DNS)
DNSUpdateCounters(tv, app_tctx);
goto end;
failure:
r = -1;
@ -461,7 +441,6 @@ int AppLayerHandleUdp(ThreadVars *tv, AppLayerThreadCtx *tctx, Packet *p, Flow *
SCEnter();
int r = 0;
AppProto alproto;
FLOWLOCK_WRLOCK(f);
@ -516,13 +495,10 @@ int AppLayerHandleUdp(ThreadVars *tv, AppLayerThreadCtx *tctx, Packet *p, Flow *
"for l7");
}
}
alproto = f->alproto;
FLOWLOCK_UNLOCK(f);
PACKET_PROFILING_APP_STORE(tctx, p);
if (alproto == ALPROTO_DNS)
DNSUpdateCounters(tv, tctx);
SCReturnInt(r);
}
@ -599,13 +575,6 @@ AppLayerThreadCtx *AppLayerGetCtxThread(ThreadVars *tv)
if ((app_tctx->alp_tctx = AppLayerParserThreadCtxAlloc()) == NULL)
goto error;
/* tv is allowed to be NULL in unittests */
if (tv != NULL) {
app_tctx->counter_dns_memuse = StatsRegisterCounter("dns.memuse", tv);
app_tctx->counter_dns_memcap_state = StatsRegisterCounter("dns.memcap_state", tv);
app_tctx->counter_dns_memcap_global = StatsRegisterCounter("dns.memcap_global", tv);
}
goto done;
error:
AppLayerDestroyCtxThread(app_tctx);

Loading…
Cancel
Save