]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #203 in SNORT/snort3 from ~JOCORNET/snort3:limit_profiler_output_d...
authorRuss Combs (rucombs) <rucombs@cisco.com>
Mon, 11 Jan 2016 20:44:49 +0000 (15:44 -0500)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Mon, 11 Jan 2016 20:44:49 +0000 (15:44 -0500)
Squashed commit of the following:

commit be02d7ffef766f395ca70617203f45ce379d13fa
Author: Joel Cornett <joel.cornett@gmail.com>
Date:   Mon Jan 11 13:39:34 2016 -0500

    updated config help

commit 25400abe4b5931b92a0f486002681038cf5b8e49
Author: Joel Cornett <joel.cornett@gmail.com>
Date:   Mon Jan 11 12:48:01 2016 -0500

    initial

src/main/modules.cc
src/profiler/memory_profiler.cc
src/profiler/memory_profiler_defs.h
src/profiler/profiler_printer.h
src/profiler/time_profiler.cc
src/profiler/time_profiler_defs.h

index 9c7683044edd6009ca65351f266dee2879c3dc0e..e8b1197cd45ee7f2151948bc22e771c91c2592ad 100644 (file)
@@ -322,12 +322,15 @@ static const Parameter profiler_time_params[] =
       "show module time profile stats" },
 
     { "count", Parameter::PT_INT, "0:", "0",
-      "print results to given level (0 = all)" },
+      "limit results to count items per level (0 = no limit)" },
 
     { "sort", Parameter::PT_ENUM,
       "none | checks | avg_check | total_time ",
       "total_time", "sort by given field" },
 
+    { "max_depth", Parameter::PT_INT, "-1:", "-1",
+      "limit depth to max_depth (-1 = no limit)" },
+
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
@@ -337,12 +340,15 @@ static const Parameter profiler_memory_params[] =
       "show module memory profile stats" },
 
     { "count", Parameter::PT_INT, "0:", "0",
-      "print results to given level (0 = all)" },
+      "limit results to count items per level (0 = no limit)" },
 
     { "sort", Parameter::PT_ENUM,
       "none | allocations | total_used | avg_allocation ",
       "total_used", "sort by given field" },
 
+    { "max_depth", Parameter::PT_INT, "-1:", "-1",
+      "limit depth to max_depth (-1 = no limit)" },
+
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
@@ -380,6 +386,13 @@ static const Parameter profiler_params[] =
 #define profiler_help \
     "configure profiling of rules and/or modules"
 
+template<typename T>
+static bool s_profiler_module_set_max_depth(T& config, Value& v)
+{ config.max_depth = v.get_long(); return true; }
+
+static bool s_profiler_module_set_max_depth(RuleProfilerConfig&, Value&)
+{ return false; }
+
 template<typename T>
 static bool s_profiler_module_set(T& config, Value& v)
 {
@@ -392,6 +405,9 @@ static bool s_profiler_module_set(T& config, Value& v)
     else if ( v.is("sort") )
         config.sort = static_cast<typename T::Sort>(v.get_long());
 
+    else if ( v.is("max_depth") )
+        return s_profiler_module_set_max_depth(config, v);
+
     else
         return false;
 
index 3f52d9dc36dc3baf6c5943ff0571d90e3d081b36..22dfd2e74fdce152ce6560d4eb351142961d4a3a 100644 (file)
@@ -171,7 +171,7 @@ void show_memory_profiler_stats(ProfilerNodeMap& nodes, const MemoryProfilerConf
     const auto& sorter = memory_stats::sorters[config.sort];
 
     ProfilerPrinter<memory_stats::View> printer(memory_stats::fields, memory_stats::print_fn, sorter);
-    printer.print_table(s_memory_table_title, root, config.count);
+    printer.print_table(s_memory_table_title, root, config.count, config.max_depth);
 }
 
 #ifdef UNIT_TEST
index 9a3d1daf169431fdb5f710ae2095e406aa4f91a0..91711b032f94ee76aff3b6c18a5cb19e0f0f28e8 100644 (file)
@@ -37,6 +37,7 @@ struct MemoryProfilerConfig
 
     bool show = false;
     unsigned count = 0;
+    int max_depth = -1;
 };
 
 class SO_PUBLIC MemoryContext
index ca249e8790a6eb71961a296d9a75113b8a672353..82c3d9854b3d72616614806bfce54ea1cd1d815a 100644 (file)
@@ -65,7 +65,7 @@ public:
     ProfilerPrinter(const StatsTable::Field* fields, const PrintFn print, const Sorter& sort) :
         fields(fields), print(print), sort(sort) { }
 
-    void print_table(std::string title, Entry& root, unsigned count)
+    void print_table(std::string title, Entry& root, unsigned count, int max_depth = -1)
     {
         std::ostringstream ss;
 
@@ -80,6 +80,9 @@ public:
             else
                 table << " (all";
 
+            if ( max_depth >= 0 )
+                table << ", depth " << max_depth;
+
             if ( sort )
                 table << ", sorted by " << sort.name;
 
@@ -90,11 +93,12 @@ public:
 
         LogMessage("%s", ss.str().c_str());
 
-        print_children(root, root, 0, count);
+        print_children(root, root, 0, count, max_depth);
         print_row(root, root, 0, 0);
     }
 
-    void print_children(const Entry& root, Entry& cur, int layer, unsigned count)
+    void print_children(const Entry& root, Entry& cur, int layer, unsigned count,
+        int max_depth = -1)
     {
         auto& entries = cur.children;
 
@@ -107,8 +111,13 @@ public:
         for ( unsigned i = 0; i < count; ++i )
         {
             auto& entry = entries[i];
+
             print_row(root, entry, layer + 1, i + 1);
-            print_children(root, entry, layer + 1, count);
+
+            if ( max_depth < 0 )
+                print_children(root, entry, layer + 1, count, max_depth);
+            else if ( max_depth > 0 )
+                print_children(root, entry, layer + 1, count, max_depth - 1);
         }
     }
 
index 12f167adffe794b8873beb44554b7478c0e60783..7089d37924a9feec116cd6b15a34d882c2d29176 100644 (file)
@@ -153,7 +153,7 @@ void show_time_profiler_stats(ProfilerNodeMap& nodes, const TimeProfilerConfig&
     const auto& sorter = time_stats::sorters[config.sort];
 
     ProfilerPrinter<time_stats::View> printer(time_stats::fields, time_stats::print_fn, sorter);
-    printer.print_table(s_time_table_title, root, config.count);
+    printer.print_table(s_time_table_title, root, config.count, config.max_depth);
 }
 
 #ifdef UNIT_TEST
index 5f59f69bb565c4a0aa29156d14d0b918322768a6..d650e3d59446dc0fa9c049eb101072c1edb01a5e 100644 (file)
@@ -37,6 +37,7 @@ struct TimeProfilerConfig
 
     bool show = false;
     unsigned count = 0;
+    int max_depth = -1;
 };
 
 struct SO_PUBLIC TimeProfilerStats