]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
mostly fixed profiling
authorRuss Combs <rucombs@cisco.com>
Sat, 12 Jul 2014 21:50:40 +0000 (17:50 -0400)
committerRuss Combs <rucombs@cisco.com>
Sat, 12 Jul 2014 21:50:40 +0000 (17:50 -0400)
src/main/modules.cc
src/main/snort.cc
src/time/profiler.cc

index 4ced9779020a07229e70a63e210aa35b7f8d3352..d640170f47adb12dc229de93155bdf7dd4ab3e35 100644 (file)
@@ -329,7 +329,7 @@ static const Parameter profile_rule_params[] =
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
-static const Parameter profile_preproc_params[] =
+static const Parameter profile_module_params[] =
 {
     { "count", Parameter::PT_INT, "-1:", "-1",
       "print results to given level (-1 = all, 0 = off?)" },
@@ -349,7 +349,7 @@ static const Parameter profile_params[] =
     { "rules", Parameter::PT_TABLE, profile_rule_params, nullptr,
       "" },
 
-    { "preprocs", Parameter::PT_TABLE, profile_preproc_params, nullptr,
+    { "modules", Parameter::PT_TABLE, profile_module_params, nullptr,
       "" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
@@ -360,13 +360,25 @@ class ProfileModule : public Module
 public:
     ProfileModule() : Module("profile", profile_params) { };
     bool set(const char*, Value&, SnortConfig*);
+    bool begin(const char*, int, SnortConfig*);
 };
 
+bool ProfileModule::begin(const char* fqn, int, SnortConfig* sc)
+{
+    if ( !strcmp(fqn, "profile.rules") )
+        sc->profile_rules.num = -1;
+
+    else if ( !strcmp(fqn, "profile.modules") )
+        sc->profile_preprocs.num = -1;
+
+    return true;
+}
+
 bool ProfileModule::set(const char* fqn, Value& v, SnortConfig* sc)
 {
     ProfileConfig* p;
     const char* spr = "profile.rules";
-    const char* spp = "profile.preprocs";
+    const char* spp = "profile.modules";
 
     if ( !strncmp(fqn, spr, strlen(spr)) )
         p = &sc->profile_rules;
index 365139e25de0754ab0ab886806d67a9c800dec74..f33b3281ae34de2505ab3d550727c95eef4219de 100644 (file)
@@ -266,13 +266,13 @@ static ProfileStats* get_profile(const char* key)
 
 static void register_profiles()
 {
-    RegisterProfile("detect", "total", get_profile);
+    RegisterProfile("detect", nullptr, get_profile);
     RegisterProfile("mpse", "detect", get_profile);
     RegisterProfile("rule eval", "detect", get_profile);
     RegisterProfile("rtn eval", "rule eval", get_profile);
     RegisterProfile("rule tree eval", "rule eval", get_profile);
-    RegisterProfile("decode", "total", get_profile);
-    RegisterProfile("eventq", "total", get_profile);
+    RegisterProfile("decode", nullptr, get_profile);
+    RegisterProfile("eventq", nullptr, get_profile);
     RegisterProfile("total", nullptr, get_profile);
     RegisterProfile("daq meta", nullptr, get_profile);
 }
index 72ba3147d6cdbd7ce7c81e3d77e1c84546562ee4..bfc13b2b41d10f9b73f6798beabf68da9486dcf6 100644 (file)
@@ -105,11 +105,20 @@ static int max_layers = 0;
 
 static ProfileStatsNode* get_node(const char*);
 
+#define TOTAL "total"
+
+static ProfileStatsNode* get_root(ProfileStatsNode* idx)
+{
+    while ( idx->parent )
+        idx = idx->parent;
+    return idx;
+}
+
 static void set_node(ProfileStatsNode* idx)
 {
     idx->parent = get_node(idx->pname);
 
-    if ( idx->parent )
+    if ( idx->pname && strcasecmp(idx->pname, TOTAL) )
         idx->layer = idx->parent->layer + 1;
 }
 
@@ -601,7 +610,6 @@ void RegisterProfile(
     const char* keyword, const char* parent, get_profile_func get, Module* mod)
 {
     ProfileStatsNode *node;
-
     node = (ProfileStatsNode *)SnortAlloc(sizeof(ProfileStatsNode));
 
     if (gProfileStatsNodeList == NULL)
@@ -640,6 +648,9 @@ void RegisterProfile(
     node->owner = mod;
     node->parent = nullptr;
 
+    if ( !node->pname && strcasecmp(node->name, TOTAL) )
+        node->pname = TOTAL;
+
     // FIXIT wtf?
     //if ( !strcasecmp(node->name, "mpse") )
     //    mpsePerfStats = stats;
@@ -790,34 +801,6 @@ void CleanupProfileStatsNodeList(void)
     gProfileStatsNodeList = NULL;
 }
 
-#if 0
-// FIXIT what was this for?
-// FIXIT profile stats is broken - need to accumulate across threads 
-// as each thread shuts down into the main thread data
-// looks like this was supposed to help do that
-static ProfileStatsNode* accumulate(ProfileStatsNode* node)
-{
-    ProfileStatsNode* last = NULL;
-    ProfileStatsNode* p = gProfileStatsNodeList;
-
-    while ( p && strcmp(p->name, node->name ) )
-    {
-        last = p;
-        p = p->next;
-    }
-    if ( !p )
-    {
-        if ( last )
-            last->next = node;
-        else
-            gProfileStatsNodeList = node;
-        node->next = NULL;
-        return NULL;
-    }
-    return node;
-}
-#endif
-
 // from packet thread only
 void ReleaseProfileStats(void)
 {
@@ -989,7 +972,7 @@ void PrintWorstPreprocs(int numToPrint)
          idx= idx->next, num++)
     {
         /* Skip the total counter */
-        if ( !strcasecmp(idx->node->name, "total") )
+        if ( !strcasecmp(idx->node->name, TOTAL) )
         {
             num--;
             total = idx;
@@ -1107,7 +1090,7 @@ void ShowPreprocProfiles(void)
             {
                 /* Find this idx's parent in the list */
                 parent = findPerfParent(idx, worstPreprocPerformers);
-                if (parent && strcasecmp(parent->node->name, "total"))
+                if (parent && strcasecmp(parent->node->name, TOTAL))
                 {
                     listhead = parent->children;
                 }
@@ -1117,7 +1100,7 @@ void ShowPreprocProfiles(void)
                     parent = NULL;
                 }
                 pwp->pct_of_parent = (double)idx->stats.ticks/idx->parent->stats.ticks*100.0;
-                pwp->pct_of_total = (double)idx->stats.ticks/totalPerfStats.ticks*100.0;
+                pwp->pct_of_total = (double)idx->stats.ticks/get_root(idx)->stats.ticks*100.0;
             }
             else
             {