htp layer: add memory usage counter

This patch adds a memory counter for HTP memory usage. As
there is no thread variables available in application layer
the counter has been added to the TCP reassembly thread.
pull/758/head
Eric Leblond 11 years ago committed by Victor Julien
parent ced01da822
commit d6d8a08a8f

@ -36,6 +36,8 @@
#include "util-mem.h"
#include "util-misc.h"
#include "app-layer-htp-mem.h"
uint64_t htp_config_memcap = 0;
SC_ATOMIC_DECLARE(uint64_t, htp_memuse);
@ -71,6 +73,12 @@ void HTPDecrMemuse(uint64_t size)
return;
}
void HTPMemuseCounter(ThreadVars *tv, TcpReassemblyThreadCtx *trt)
{
uint64_t memusecopy = SC_ATOMIC_GET(htp_memuse);
SCPerfCounterSetUI64(trt->counter_htp_memuse, tv->sc_perf_pca, memusecopy);
return;
}
/**
* \brief Check if alloc'ing "size" would mean we're over memcap
*

@ -15,7 +15,12 @@
* 02110-1301, USA.
*/
#include "stream-tcp-reassemble.h"
void HTPParseMemcap();
void *HTPMalloc(size_t size);
void *HTPRealloc(void *ptr, size_t orig_size, size_t size);
void HTPFree(void *ptr, size_t size);
void HTPMemuseCounter(ThreadVars *tv, TcpReassemblyThreadCtx *trt);

@ -41,6 +41,7 @@
#include "util-profiling.h"
#include "util-validate.h"
#include "decode-events.h"
#include "app-layer-htp-mem.h"
/**
* \brief This is for the app layer in general and it contains per thread
@ -341,6 +342,8 @@ int AppLayerHandleTCPData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,
}
}
/** \fixme a bit hacky but will be improved in 2.1 */
HTPMemuseCounter(tv, ra_ctx);
goto end;
failure:
r = -1;

@ -62,6 +62,9 @@ typedef struct TcpReassemblyThreadCtx_ {
uint16_t counter_tcp_reass_memuse;
/** count number of streams with a unrecoverable stream gap (missing pkts) */
uint16_t counter_tcp_reass_gap;
/** account memory usage by suricata to handle HTTP protocol (not counting
* libhtp memory usage)*/
uint16_t counter_htp_memuse;
} TcpReassemblyThreadCtx;
#define OS_POLICY_DEFAULT OS_POLICY_BSD

@ -4559,6 +4559,10 @@ TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data)
stt->ra_ctx->counter_tcp_reass_gap = SCPerfTVRegisterCounter("tcp.reassembly_gap", tv,
SC_PERF_TYPE_UINT64,
"NULL");
/** \fixme Find a better place in 2.1 as it is linked with app layer */
stt->ra_ctx->counter_htp_memuse = SCPerfTVRegisterCounter("http.memuse", tv,
SC_PERF_TYPE_UINT64,
"NULL");
SCLogDebug("StreamTcp thread specific ctx online at %p, reassembly ctx %p",
stt, stt->ra_ctx);

Loading…
Cancel
Save