profiling: minor code cleanups

pull/7652/head
Victor Julien 3 years ago
parent e69e99f820
commit 21f76773c7

@ -348,7 +348,6 @@ static void DumpFlowWorker(FILE *fp)
void SCProfilingDumpPacketStats(void) void SCProfilingDumpPacketStats(void)
{ {
int i;
FILE *fp; FILE *fp;
char totalstr[256]; char totalstr[256];
uint64_t total; uint64_t total;
@ -375,16 +374,15 @@ void SCProfilingDumpPacketStats(void)
fprintf(fp, "%-6s %-5s %-12s %-12s %-12s %-12s %-12s %-3s\n", fprintf(fp, "%-6s %-5s %-12s %-12s %-12s %-12s %-12s %-3s\n",
"------", "-----", "----------", "------------", "------------", "-----------", "-----------", "---"); "------", "-----", "----------", "------------", "------------", "-----------", "-----------", "---");
total = 0; total = 0;
for (i = 0; i < 257; i++) { for (int i = 0; i < 257; i++) {
SCProfilePacketData *pd = &packet_profile_data4[i]; SCProfilePacketData *pd = &packet_profile_data4[i];
total += pd->tot; total += pd->tot;
pd = &packet_profile_data6[i]; pd = &packet_profile_data6[i];
total += pd->tot; total += pd->tot;
} }
for (i = 0; i < 257; i++) { for (int i = 0; i < 257; i++) {
SCProfilePacketData *pd = &packet_profile_data4[i]; SCProfilePacketData *pd = &packet_profile_data4[i];
if (pd->cnt == 0) { if (pd->cnt == 0) {
continue; continue;
} }
@ -397,9 +395,8 @@ void SCProfilingDumpPacketStats(void)
pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent);
} }
for (i = 0; i < 257; i++) { for (int i = 0; i < 257; i++) {
SCProfilePacketData *pd = &packet_profile_data6[i]; SCProfilePacketData *pd = &packet_profile_data6[i];
if (pd->cnt == 0) { if (pd->cnt == 0) {
continue; continue;
} }
@ -431,14 +428,12 @@ void SCProfilingDumpPacketStats(void)
#else #else
fprintf(fp, "\n"); fprintf(fp, "\n");
#endif #endif
int m;
total = 0; total = 0;
for (m = 0; m < TMM_SIZE; m++) { for (int m = 0; m < TMM_SIZE; m++) {
if (tmm_modules[m].flags & TM_FLAG_LOGAPI_TM) if (tmm_modules[m].flags & TM_FLAG_LOGAPI_TM)
continue; continue;
int p; for (int p = 0; p < 257; p++) {
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_tmm_data4[m][p]; SCProfilePacketData *pd = &packet_profile_tmm_data4[m][p];
total += pd->tot; total += pd->tot;
@ -447,14 +442,12 @@ void SCProfilingDumpPacketStats(void)
} }
} }
for (m = 0; m < TMM_SIZE; m++) { for (int m = 0; m < TMM_SIZE; m++) {
if (tmm_modules[m].flags & TM_FLAG_LOGAPI_TM) if (tmm_modules[m].flags & TM_FLAG_LOGAPI_TM)
continue; continue;
int p; for (int p = 0; p < 257; p++) {
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_tmm_data4[m][p]; SCProfilePacketData *pd = &packet_profile_tmm_data4[m][p];
if (pd->cnt == 0) { if (pd->cnt == 0) {
continue; continue;
} }
@ -474,14 +467,12 @@ void SCProfilingDumpPacketStats(void)
} }
} }
for (m = 0; m < TMM_SIZE; m++) { for (int m = 0; m < TMM_SIZE; m++) {
if (tmm_modules[m].flags & TM_FLAG_LOGAPI_TM) if (tmm_modules[m].flags & TM_FLAG_LOGAPI_TM)
continue; continue;
int p; for (int p = 0; p < 257; p++) {
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_tmm_data6[m][p]; SCProfilePacketData *pd = &packet_profile_tmm_data6[m][p];
if (pd->cnt == 0) { if (pd->cnt == 0) {
continue; continue;
} }
@ -505,21 +496,18 @@ void SCProfilingDumpPacketStats(void)
"--------------------", "------", "-----", "----------", "------------", "------------", "-----------"); "--------------------", "------", "-----", "----------", "------------", "------------", "-----------");
total = 0; total = 0;
for (m = 0; m < ALPROTO_MAX; m++) { for (AppProto a = 0; a < ALPROTO_MAX; a++) {
int p; for (int p = 0; p < 257; p++) {
for (p = 0; p < 257; p++) { SCProfilePacketData *pd = &packet_profile_app_data4[a][p];
SCProfilePacketData *pd = &packet_profile_app_data4[m][p];
total += pd->tot; total += pd->tot;
pd = &packet_profile_app_data6[m][p]; pd = &packet_profile_app_data6[a][p];
total += pd->tot; total += pd->tot;
} }
} }
for (AppProto a = 0; a < ALPROTO_MAX; a++) { for (AppProto a = 0; a < ALPROTO_MAX; a++) {
int p; for (int p = 0; p < 257; p++) {
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_app_data4[a][p]; SCProfilePacketData *pd = &packet_profile_app_data4[a][p];
if (pd->cnt == 0) { if (pd->cnt == 0) {
continue; continue;
} }
@ -537,10 +525,8 @@ void SCProfilingDumpPacketStats(void)
} }
for (AppProto a = 0; a < ALPROTO_MAX; a++) { for (AppProto a = 0; a < ALPROTO_MAX; a++) {
int p; for (int p = 0; p < 257; p++) {
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_app_data6[a][p]; SCProfilePacketData *pd = &packet_profile_app_data6[a][p];
if (pd->cnt == 0) { if (pd->cnt == 0) {
continue; continue;
} }
@ -559,10 +545,8 @@ void SCProfilingDumpPacketStats(void)
/* proto detect output */ /* proto detect output */
{ {
int p; for (int p = 0; p < 257; p++) {
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_app_pd_data4[p]; SCProfilePacketData *pd = &packet_profile_app_pd_data4[p];
if (pd->cnt == 0) { if (pd->cnt == 0) {
continue; continue;
} }
@ -572,9 +556,8 @@ void SCProfilingDumpPacketStats(void)
"Proto detect", p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr); "Proto detect", p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr);
} }
for (p = 0; p < 257; p++) { for (int p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_app_pd_data6[p]; SCProfilePacketData *pd = &packet_profile_app_pd_data6[p];
if (pd->cnt == 0) { if (pd->cnt == 0) {
continue; continue;
} }
@ -586,9 +569,8 @@ void SCProfilingDumpPacketStats(void)
} }
total = 0; total = 0;
for (m = 0; m < PROF_DETECT_SIZE; m++) { for (int m = 0; m < PROF_DETECT_SIZE; m++) {
int p; for (int p = 0; p < 257; p++) {
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_detect_data4[m][p]; SCProfilePacketData *pd = &packet_profile_detect_data4[m][p];
total += pd->tot; total += pd->tot;
@ -597,7 +579,6 @@ void SCProfilingDumpPacketStats(void)
} }
} }
fprintf(fp, "\n%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s %-3s", fprintf(fp, "\n%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s %-3s",
"Log Thread Module", "IP ver", "Proto", "cnt", "min", "max", "avg", "tot", "%%"); "Log Thread Module", "IP ver", "Proto", "cnt", "min", "max", "avg", "tot", "%%");
#ifdef PROFILE_LOCKING #ifdef PROFILE_LOCKING
@ -615,12 +596,11 @@ void SCProfilingDumpPacketStats(void)
fprintf(fp, "\n"); fprintf(fp, "\n");
#endif #endif
total = 0; total = 0;
for (m = 0; m < TMM_SIZE; m++) { for (int m = 0; m < TMM_SIZE; m++) {
if (!(tmm_modules[m].flags & TM_FLAG_LOGAPI_TM)) if (!(tmm_modules[m].flags & TM_FLAG_LOGAPI_TM))
continue; continue;
int p; for (int p = 0; p < 257; p++) {
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_tmm_data4[m][p]; SCProfilePacketData *pd = &packet_profile_tmm_data4[m][p];
total += pd->tot; total += pd->tot;
@ -629,14 +609,12 @@ void SCProfilingDumpPacketStats(void)
} }
} }
for (m = 0; m < TMM_SIZE; m++) { for (int m = 0; m < TMM_SIZE; m++) {
if (!(tmm_modules[m].flags & TM_FLAG_LOGAPI_TM)) if (!(tmm_modules[m].flags & TM_FLAG_LOGAPI_TM))
continue; continue;
int p; for (int p = 0; p < 257; p++) {
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_tmm_data4[m][p]; SCProfilePacketData *pd = &packet_profile_tmm_data4[m][p];
if (pd->cnt == 0) { if (pd->cnt == 0) {
continue; continue;
} }
@ -656,14 +634,12 @@ void SCProfilingDumpPacketStats(void)
} }
} }
for (m = 0; m < TMM_SIZE; m++) { for (int m = 0; m < TMM_SIZE; m++) {
if (!(tmm_modules[m].flags & TM_FLAG_LOGAPI_TM)) if (!(tmm_modules[m].flags & TM_FLAG_LOGAPI_TM))
continue; continue;
int p; for (int p = 0; p < 257; p++) {
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_tmm_data6[m][p]; SCProfilePacketData *pd = &packet_profile_tmm_data6[m][p];
if (pd->cnt == 0) { if (pd->cnt == 0) {
continue; continue;
} }
@ -680,9 +656,8 @@ void SCProfilingDumpPacketStats(void)
fprintf(fp, "\nLogger/output stats:\n"); fprintf(fp, "\nLogger/output stats:\n");
total = 0; total = 0;
for (m = 0; m < LOGGER_SIZE; m++) { for (int m = 0; m < LOGGER_SIZE; m++) {
int p; for (int p = 0; p < 256; p++) {
for (p = 0; p < 256; p++) {
SCProfilePacketData *pd = &packet_profile_log_data4[m][p]; SCProfilePacketData *pd = &packet_profile_log_data4[m][p];
total += pd->tot; total += pd->tot;
pd = &packet_profile_log_data6[m][p]; pd = &packet_profile_log_data6[m][p];
@ -694,11 +669,9 @@ void SCProfilingDumpPacketStats(void)
"Logger", "IP ver", "Proto", "cnt", "min", "max", "avg", "tot"); "Logger", "IP ver", "Proto", "cnt", "min", "max", "avg", "tot");
fprintf(fp, "%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s\n", fprintf(fp, "%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s\n",
"------------------------", "------", "-----", "----------", "------------", "------------", "-----------", "-----------"); "------------------------", "------", "-----", "----------", "------------", "------------", "-----------", "-----------");
for (m = 0; m < LOGGER_SIZE; m++) { for (int m = 0; m < LOGGER_SIZE; m++) {
int p; for (int p = 0; p < 256; p++) {
for (p = 0; p < 256; p++) {
SCProfilePacketData *pd = &packet_profile_log_data4[m][p]; SCProfilePacketData *pd = &packet_profile_log_data4[m][p];
if (pd->cnt == 0) { if (pd->cnt == 0) {
continue; continue;
} }
@ -711,11 +684,9 @@ void SCProfilingDumpPacketStats(void)
PacketProfileLoggertIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); PacketProfileLoggertIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent);
} }
} }
for (m = 0; m < LOGGER_SIZE; m++) { for (int m = 0; m < LOGGER_SIZE; m++) {
int p; for (int p = 0; p < 256; p++) {
for (p = 0; p < 256; p++) {
SCProfilePacketData *pd = &packet_profile_log_data6[m][p]; SCProfilePacketData *pd = &packet_profile_log_data6[m][p];
if (pd->cnt == 0) { if (pd->cnt == 0) {
continue; continue;
} }
@ -732,9 +703,8 @@ void SCProfilingDumpPacketStats(void)
fprintf(fp, "\nGeneral detection engine stats:\n"); fprintf(fp, "\nGeneral detection engine stats:\n");
total = 0; total = 0;
for (m = 0; m < PROF_DETECT_SIZE; m++) { for (int m = 0; m < PROF_DETECT_SIZE; m++) {
int p; for (int p = 0; p < 257; p++) {
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_detect_data4[m][p]; SCProfilePacketData *pd = &packet_profile_detect_data4[m][p];
total += pd->tot; total += pd->tot;
pd = &packet_profile_detect_data6[m][p]; pd = &packet_profile_detect_data6[m][p];
@ -746,11 +716,9 @@ void SCProfilingDumpPacketStats(void)
"Detection phase", "IP ver", "Proto", "cnt", "min", "max", "avg", "tot"); "Detection phase", "IP ver", "Proto", "cnt", "min", "max", "avg", "tot");
fprintf(fp, "%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s\n", fprintf(fp, "%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s\n",
"------------------------", "------", "-----", "----------", "------------", "------------", "-----------", "-----------"); "------------------------", "------", "-----", "----------", "------------", "------------", "-----------", "-----------");
for (m = 0; m < PROF_DETECT_SIZE; m++) { for (int m = 0; m < PROF_DETECT_SIZE; m++) {
int p; for (int p = 0; p < 257; p++) {
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_detect_data4[m][p]; SCProfilePacketData *pd = &packet_profile_detect_data4[m][p];
if (pd->cnt == 0) { if (pd->cnt == 0) {
continue; continue;
} }
@ -763,11 +731,9 @@ void SCProfilingDumpPacketStats(void)
PacketProfileDetectIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent); PacketProfileDetectIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent);
} }
} }
for (m = 0; m < PROF_DETECT_SIZE; m++) { for (int m = 0; m < PROF_DETECT_SIZE; m++) {
int p; for (int p = 0; p < 257; p++) {
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_detect_data6[m][p]; SCProfilePacketData *pd = &packet_profile_detect_data6[m][p];
if (pd->cnt == 0) { if (pd->cnt == 0) {
continue; continue;
} }

Loading…
Cancel
Save