"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 }
};
"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 }
};
#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)
{
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;
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
bool show = false;
unsigned count = 0;
+ int max_depth = -1;
};
class SO_PUBLIC MemoryContext
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;
else
table << " (all";
+ if ( max_depth >= 0 )
+ table << ", depth " << max_depth;
+
if ( sort )
table << ", sorted by " << sort.name;
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;
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);
}
}
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
bool show = false;
unsigned count = 0;
+ int max_depth = -1;
};
struct SO_PUBLIC TimeProfilerStats