]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3885: profiler: change date output format in rule profiler from microse...
authorVitalii Serhiiovych Horbatov -X (vhorbato - SOFTSERVE INC at Cisco) <vhorbato@cisco.com>
Mon, 26 Jun 2023 09:04:01 +0000 (09:04 +0000)
committerOleksii Shumeiko -X (oshumeik - SOFTSERVE INC at Cisco) <oshumeik@cisco.com>
Mon, 26 Jun 2023 09:04:01 +0000 (09:04 +0000)
Merge in SNORT/snort3 from ~VHORBATO/snort3:rule_prof_date to master

Squashed commit of the following:

commit cbcd8133dd4f0d2d61460719414507319fa82c5d
Author: vhorbato <vhorbato@cisco.com>
Date:   Fri Jun 16 18:55:11 2023 +0300

    profiler: fix date related problems in rule_profiling json output

src/profiler/json_view.cc
src/profiler/profiler_module.cc
src/profiler/table_view.cc

index bd2a90bcd25b213ba3c1fdd8f210b88dcf020a8f..ec3f62d583cb26b522961e5ddd56a352f602abfd 100644 (file)
@@ -30,7 +30,6 @@
 #include "control/control.h"
 #include "helpers/json_stream.h"
 #include "main/snort_config.h"
-#include "utils/stats.h"
 
 #include "profiler_printer.h"
 #include "rule_profiler.h"
@@ -80,19 +79,11 @@ void print_json_entries(ControlConn* ctrlcon, std::vector<rule_stats::View>& ent
     std::ostringstream ss;
     JsonStream json(ss);
 
-    RuleContext::set_end_time(get_time_curr());
     RuleContext::count_total_time();
 
-    double start_time_usec =
-        RuleContext::get_start_time()->tv_sec * 1000000.0 + RuleContext::get_start_time()->tv_usec;
-    double end_time_usec =
-        RuleContext::get_end_time()->tv_sec * 1000000.0 + RuleContext::get_end_time()->tv_usec;
-    double total_time_usec =
-        RuleContext::get_total_time()->tv_sec * 1000000.0 + RuleContext::get_total_time()->tv_usec;
-
     json.open();
-    json.put("startTime", start_time_usec);
-    json.put("endTime", end_time_usec);
+    json.put("startTime", RuleContext::get_start_time()->tv_sec);
+    json.put("endTime", RuleContext::get_end_time()->tv_sec);
     json.open_array("rules");
     json.put_eol();
 
@@ -104,6 +95,9 @@ void print_json_entries(ControlConn* ctrlcon, std::vector<rule_stats::View>& ent
     if ( sort )
         std::partial_sort(entries.begin(), entries.begin() + count, entries.end(), sort);
 
+    double total_time_usec =
+        RuleContext::get_total_time()->tv_sec * 1000000.0 + RuleContext::get_total_time()->tv_usec;
+
     for ( unsigned i = 0; i < count; ++i )
         print_single_entry(ctrlcon, entries[i], i + 1, count, total_time_usec);
 
index 66c6a4b5eb55b5f3f9b061f26737c2560204049f..4cb82f845ce37b0767649e94446ca1dafbd0c643 100644 (file)
@@ -33,6 +33,7 @@
 #include "main/snort.h"
 #include "main/snort_config.h"
 #include "managers/module_manager.h"
+#include "utils/stats.h"
 
 #include "rule_profiler.h"
 #include "rule_profiler_defs.h"
@@ -109,6 +110,7 @@ public:
         const auto* config = SnortConfig::get_conf()->get_profiler();
         assert(config);
 
+        RuleContext::set_end_time(get_time_curr());
         print_rule_profiler_stats(config->rule, stats, ctrlcon, out_type);
     }
 
@@ -170,6 +172,7 @@ static int rule_profiling_start(lua_State* L)
     }
 
     RuleContext::set_enabled(true);
+    RuleContext::set_start_time(get_time_curr());
     main_broadcast_command(new ProfilerControl(ProfilerControl::CommandType::ENABLE), ctrlcon);
     main_broadcast_command(new ProfilerRuleReset(), ctrlcon);
     LogRespond(ctrlcon, "Rule profiler started\n");
@@ -189,6 +192,7 @@ static int rule_profiling_stop(lua_State* L)
     }
 
     RuleContext::set_enabled(false);
+    RuleContext::set_end_time(get_time_curr());
     main_broadcast_command(new ProfilerControl(ProfilerControl::CommandType::DISABLE), ctrlcon);
     LogRespond(ctrlcon, "Rule profiler stopped\n");
 
@@ -246,7 +250,7 @@ static int rule_profiling_dump(lua_State* L)
 static const Parameter profiler_dump_params[] =
 {
     { "output", Parameter::PT_ENUM, "table | json",
-      "table", "print rule statistics in table or json format" },
+      "table", "output format for rule statistics" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
@@ -263,7 +267,7 @@ static const Command profiler_cmds[] =
       nullptr, "print rule profiler status" },
 
     { "rule_dump", rule_profiling_dump,
-      profiler_dump_params, "print rule statistics" },
+      profiler_dump_params, "print rule statistics in table or json format (json format prints dates as Unix epoch)" },
 
     { nullptr, nullptr, nullptr, nullptr }
 };
index 675a0342378aff9532485b26dd3b873919c4668c..90d98b90bddb1175cc13cbcaeae7d7692ae7fbc7 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "control/control.h"
 #include "detection/treenodes.h"
-#include "utils/stats.h"
 
 #include "profiler_printer.h"
 #include "profiler_stats_table.h"
@@ -100,7 +99,6 @@ void print_entries(ControlConn* ctrlcon, std::vector<rule_stats::View>& entries,
     ProfilerSorter<rule_stats::View>& sort, unsigned count)
 {
     std::ostringstream ss;
-    RuleContext::set_end_time(get_time_curr());
     RuleContext::count_total_time();
 
     double total_time_usec =