From 8a735a9b90fed6ecdeb43317bc0a7adc110fabd9 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 3 Feb 2014 17:40:45 +0100 Subject: [PATCH] profiling: add sample-rate yaml option Add option "profiling.sample-rate": # Run profiling for every xth packet. The default is 1, which means we # profile every packet. If set to 1000, one packet is profiled for every # 1000 received. #sample-rate: 1000 This allows for configuration of the sample rate. --- src/util-profiling.c | 16 +++++++++++++--- suricata.yaml.in | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/util-profiling.c b/src/util-profiling.c index e4b047697e..9dfb53099d 100644 --- a/src/util-profiling.c +++ b/src/util-profiling.c @@ -96,6 +96,9 @@ char *profiling_packets_file_name; char *profiling_csv_file_name; const char *profiling_packets_file_mode = "a"; +static int rate = 1; +static SC_ATOMIC_DECL_AND_INIT(uint64_t, samples); + /** * Used as a check so we don't double enter a profiling run. */ @@ -123,6 +126,16 @@ SCProfilingInit(void) { ConfNode *conf; + intmax_t rate_v = 0; + (void)ConfGetInt("profiling.sample-rate", &rate_v); + if (rate_v > 0 && rate_v < INT_MAX) { + rate = (int)rate_v; + if (rate != 1) + SCLogInfo("profiling runs for every %dth packet", rate); + else + SCLogInfo("profiling runs for every packet"); + } + conf = ConfGetNode("profiling.packets"); if (conf != NULL) { if (ConfNodeChildValueIsTrue(conf, "enabled")) { @@ -843,9 +856,6 @@ void SCProfilingAddPacket(Packet *p) { pthread_mutex_unlock(&packet_profile_lock); } -static int rate = 1; -static SC_ATOMIC_DECL_AND_INIT(uint64_t, samples); - PktProfiling *SCProfilePacketStart(void) { uint64_t sample = SC_ATOMIC_ADD(samples, 1); if (sample % rate == 0) diff --git a/suricata.yaml.in b/suricata.yaml.in index 463c4014e6..dc06ceae0e 100644 --- a/suricata.yaml.in +++ b/suricata.yaml.in @@ -1218,6 +1218,10 @@ app-layer: # the --enable-profiling configure flag. # profiling: + # Run profiling for every xth packet. The default is 1, which means we + # profile every packet. If set to 1000, one packet is profiled for every + # 1000 received. + #sample-rate: 1000 # rule profiling rules: