From: Russ Combs (rucombs) Date: Mon, 11 Jan 2016 20:44:49 +0000 (-0500) Subject: Merge pull request #203 in SNORT/snort3 from ~JOCORNET/snort3:limit_profiler_output_d... X-Git-Tag: 3.0.0-233~664 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f01ba4062145fdba8adfe830377dd759f77c3815;p=thirdparty%2Fsnort3.git Merge pull request #203 in SNORT/snort3 from ~JOCORNET/snort3:limit_profiler_output_depth to master Squashed commit of the following: commit be02d7ffef766f395ca70617203f45ce379d13fa Author: Joel Cornett Date: Mon Jan 11 13:39:34 2016 -0500 updated config help commit 25400abe4b5931b92a0f486002681038cf5b8e49 Author: Joel Cornett Date: Mon Jan 11 12:48:01 2016 -0500 initial --- diff --git a/src/main/modules.cc b/src/main/modules.cc index 9c7683044..e8b1197cd 100644 --- a/src/main/modules.cc +++ b/src/main/modules.cc @@ -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 +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 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(v.get_long()); + else if ( v.is("max_depth") ) + return s_profiler_module_set_max_depth(config, v); + else return false; diff --git a/src/profiler/memory_profiler.cc b/src/profiler/memory_profiler.cc index 3f52d9dc3..22dfd2e74 100644 --- a/src/profiler/memory_profiler.cc +++ b/src/profiler/memory_profiler.cc @@ -171,7 +171,7 @@ void show_memory_profiler_stats(ProfilerNodeMap& nodes, const MemoryProfilerConf const auto& sorter = memory_stats::sorters[config.sort]; ProfilerPrinter 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 diff --git a/src/profiler/memory_profiler_defs.h b/src/profiler/memory_profiler_defs.h index 9a3d1daf1..91711b032 100644 --- a/src/profiler/memory_profiler_defs.h +++ b/src/profiler/memory_profiler_defs.h @@ -37,6 +37,7 @@ struct MemoryProfilerConfig bool show = false; unsigned count = 0; + int max_depth = -1; }; class SO_PUBLIC MemoryContext diff --git a/src/profiler/profiler_printer.h b/src/profiler/profiler_printer.h index ca249e879..82c3d9854 100644 --- a/src/profiler/profiler_printer.h +++ b/src/profiler/profiler_printer.h @@ -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); } } diff --git a/src/profiler/time_profiler.cc b/src/profiler/time_profiler.cc index 12f167adf..7089d3792 100644 --- a/src/profiler/time_profiler.cc +++ b/src/profiler/time_profiler.cc @@ -153,7 +153,7 @@ void show_time_profiler_stats(ProfilerNodeMap& nodes, const TimeProfilerConfig& const auto& sorter = time_stats::sorters[config.sort]; ProfilerPrinter 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 diff --git a/src/profiler/time_profiler_defs.h b/src/profiler/time_profiler_defs.h index 5f59f69bb..d650e3d59 100644 --- a/src/profiler/time_profiler_defs.h +++ b/src/profiler/time_profiler_defs.h @@ -37,6 +37,7 @@ struct TimeProfilerConfig bool show = false; unsigned count = 0; + int max_depth = -1; }; struct SO_PUBLIC TimeProfilerStats