]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
profiling: add sample-rate yaml option
authorVictor Julien <victor@inliniac.net>
Mon, 3 Feb 2014 16:40:45 +0000 (17:40 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 4 Feb 2014 12:42:21 +0000 (13:42 +0100)
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
suricata.yaml.in

index e4b047697e083562d8b254c09e8a6123a3429f1b..9dfb53099d8714478182676e823f945850a73a20 100644 (file)
@@ -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)
index 463c4014e6b97c35c0c05fcf58fee60c2b54c554..dc06ceae0efc9e1876c4de546e3e2f64d10c76bc 100644 (file)
@@ -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: