From: Russ Combs Date: Sat, 12 Jul 2014 21:50:40 +0000 (-0400) Subject: mostly fixed profiling X-Git-Tag: 3.0.0-233~1444^2~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=46fc5f3c97fc02790d86e0f7923dcf213d9df6c2;p=thirdparty%2Fsnort3.git mostly fixed profiling --- diff --git a/src/main/modules.cc b/src/main/modules.cc index 4ced97790..d640170f4 100644 --- a/src/main/modules.cc +++ b/src/main/modules.cc @@ -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; diff --git a/src/main/snort.cc b/src/main/snort.cc index 365139e25..f33b3281a 100644 --- a/src/main/snort.cc +++ b/src/main/snort.cc @@ -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); } diff --git a/src/time/profiler.cc b/src/time/profiler.cc index 72ba3147d..bfc13b2b4 100644 --- a/src/time/profiler.cc +++ b/src/time/profiler.cc @@ -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 {