profiling: add formatted totals, percents to packet stats

pull/346/head
Victor Julien 12 years ago
parent 4165de4771
commit ffffe6c10e

@ -104,6 +104,17 @@ __thread int profiling_rules_entered = 0;
void SCProfilingDumpPacketStats(void); void SCProfilingDumpPacketStats(void);
const char * PacketProfileDetectIdToString(PacketProfileDetectId id); const char * PacketProfileDetectIdToString(PacketProfileDetectId id);
static void FormatNumber(uint64_t num, char *str, size_t size) {
if (num < 1000UL)
snprintf(str, size, "%"PRIu64, num);
else if (num < 1000000UL)
snprintf(str, size, "%3.1fk", (float)num/1000UL);
else if (num < 1000000000UL)
snprintf(str, size, "%3.1fm", (float)num/1000000UL);
else
snprintf(str, size, "%3.1fb", (float)num/1000000000UL);
}
/** /**
* \brief Initialize profiling. * \brief Initialize profiling.
*/ */
@ -278,6 +289,8 @@ SCProfilingDump(void)
void SCProfilingDumpPacketStats(void) { void SCProfilingDumpPacketStats(void) {
int i; int i;
FILE *fp; FILE *fp;
char totalstr[256];
uint64_t total;
if (profiling_packets_enabled == 0) if (profiling_packets_enabled == 0)
return; return;
@ -296,10 +309,17 @@ void SCProfilingDumpPacketStats(void) {
fprintf(fp, "\n\nPacket profile dump:\n"); fprintf(fp, "\n\nPacket profile dump:\n");
fprintf(fp, "\n%-6s %-5s %-12s %-12s %-12s %-12s\n", fprintf(fp, "\n%-6s %-5s %-12s %-12s %-12s %-12s %-12s %-3s\n",
"IP ver", "Proto", "cnt", "min", "max", "avg"); "IP ver", "Proto", "cnt", "min", "max", "avg", "tot", "%%");
fprintf(fp, "%-6s %-5s %-12s %-12s %-12s %-12s\n", fprintf(fp, "%-6s %-5s %-12s %-12s %-12s %-12s %-12s %-3s\n",
"------", "-----", "----------", "------------", "------------", "-----------"); "------", "-----", "----------", "------------", "------------", "-----------", "-----------", "---");
total = 0;
for (i = 0; i < 257; i++) {
SCProfilePacketData *pd = &packet_profile_data4[i];
total += pd->tot;
pd = &packet_profile_data6[i];
total += pd->tot;
}
for (i = 0; i < 257; i++) { for (i = 0; i < 257; i++) {
SCProfilePacketData *pd = &packet_profile_data4[i]; SCProfilePacketData *pd = &packet_profile_data4[i];
@ -308,8 +328,12 @@ void SCProfilingDumpPacketStats(void) {
continue; continue;
} }
fprintf(fp, " IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64"\n", i, pd->cnt, FormatNumber(pd->tot, totalstr, sizeof(totalstr));
pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt)); double percent = (long double)pd->tot /
(long double)total * 100;
fprintf(fp, " IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %6.2f\n", i, pd->cnt,
pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent);
} }
for (i = 0; i < 257; i++) { for (i = 0; i < 257; i++) {
@ -319,23 +343,27 @@ void SCProfilingDumpPacketStats(void) {
continue; continue;
} }
fprintf(fp, " IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64"\n", i, pd->cnt, FormatNumber(pd->tot, totalstr, sizeof(totalstr));
pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt)); double percent = (long double)pd->tot /
(long double)total * 100;
fprintf(fp, " IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %6.2f\n", i, pd->cnt,
pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent);
} }
fprintf(fp, "Note: Protocol 256 tracks pseudo/tunnel packets.\n"); fprintf(fp, "Note: Protocol 256 tracks pseudo/tunnel packets.\n");
fprintf(fp, "\nPer Thread module stats:\n"); fprintf(fp, "\nPer Thread module stats:\n");
fprintf(fp, "\n%-24s %-6s %-5s %-12s %-12s %-12s %-12s", fprintf(fp, "\n%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s %-3s",
"Thread Module", "IP ver", "Proto", "cnt", "min", "max", "avg"); "Thread Module", "IP ver", "Proto", "cnt", "min", "max", "avg", "tot", "%%");
#ifdef PROFILE_LOCKING #ifdef PROFILE_LOCKING
fprintf(fp, " %-10s %-10s %-12s %-12s %-10s %-10s %-12s %-12s\n", fprintf(fp, " %-10s %-10s %-12s %-12s %-10s %-10s %-12s %-12s\n",
"locks", "ticks", "cont.", "cont.avg", "slocks", "sticks", "scont.", "scont.avg"); "locks", "ticks", "cont.", "cont.avg", "slocks", "sticks", "scont.", "scont.avg");
#else #else
fprintf(fp, "\n"); fprintf(fp, "\n");
#endif #endif
fprintf(fp, "%-24s %-6s %-5s %-12s %-12s %-12s %-12s", fprintf(fp, "%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s %-3s",
"------------------------", "------", "-----", "----------", "------------", "------------", "-----------"); "------------------------", "------", "-----", "----------", "------------", "------------", "-----------", "-----------", "---");
#ifdef PROFILE_LOCKING #ifdef PROFILE_LOCKING
fprintf(fp, " %-10s %-10s %-12s %-12s %-10s %-10s %-12s %-12s\n", fprintf(fp, " %-10s %-10s %-12s %-12s %-10s %-10s %-12s %-12s\n",
"--------", "--------", "----------", "-----------", "--------", "--------", "------------", "-----------"); "--------", "--------", "----------", "-----------", "--------", "--------", "------------", "-----------");
@ -343,6 +371,18 @@ void SCProfilingDumpPacketStats(void) {
fprintf(fp, "\n"); fprintf(fp, "\n");
#endif #endif
int m; int m;
total = 0;
for (m = 0; m < TMM_SIZE; m++) {
int p;
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_tmm_data4[m][p];
total += pd->tot;
pd = &packet_profile_tmm_data6[m][p];
total += pd->tot;
}
}
for (m = 0; m < TMM_SIZE; m++) { for (m = 0; m < TMM_SIZE; m++) {
int p; int p;
for (p = 0; p < 257; p++) { for (p = 0; p < 257; p++) {
@ -352,8 +392,12 @@ void SCProfilingDumpPacketStats(void) {
continue; continue;
} }
fprintf(fp, "%-24s IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64, FormatNumber(pd->tot, totalstr, sizeof(totalstr));
TmModuleTmmIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt)); double percent = (long double)pd->tot /
(long double)total * 100;
fprintf(fp, "%-24s IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %6.2f",
TmModuleTmmIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent);
#ifdef PROFILE_LOCKING #ifdef PROFILE_LOCKING
fprintf(fp, " %10.2f %12"PRIu64" %12"PRIu64" %10.2f %10.2f %12"PRIu64" %12"PRIu64" %10.2f\n", fprintf(fp, " %10.2f %12"PRIu64" %12"PRIu64" %10.2f %10.2f %12"PRIu64" %12"PRIu64" %10.2f\n",
(float)pd->lock/pd->cnt, (uint64_t)pd->ticks/pd->cnt, pd->contention, (float)pd->contention/pd->cnt, (float)pd->slock/pd->cnt, (uint64_t)pd->sticks/pd->cnt, pd->scontention, (float)pd->scontention/pd->cnt); (float)pd->lock/pd->cnt, (uint64_t)pd->ticks/pd->cnt, pd->contention, (float)pd->contention/pd->cnt, (float)pd->slock/pd->cnt, (uint64_t)pd->sticks/pd->cnt, pd->scontention, (float)pd->scontention/pd->cnt);
@ -372,8 +416,12 @@ void SCProfilingDumpPacketStats(void) {
continue; continue;
} }
fprintf(fp, "%-24s IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64"\n", FormatNumber(pd->tot, totalstr, sizeof(totalstr));
TmModuleTmmIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt)); double percent = (long double)pd->tot /
(long double)total * 100;
fprintf(fp, "%-24s IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %6.2f\n",
TmModuleTmmIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent);
} }
} }
fprintf(fp, "Note: TMM_STREAMTCP includes TCP app layer parsers, see below.\n"); fprintf(fp, "Note: TMM_STREAMTCP includes TCP app layer parsers, see below.\n");
@ -384,6 +432,18 @@ void SCProfilingDumpPacketStats(void) {
"App Layer", "IP ver", "Proto", "cnt", "min", "max", "avg"); "App Layer", "IP ver", "Proto", "cnt", "min", "max", "avg");
fprintf(fp, "%-20s %-6s %-5s %-12s %-12s %-12s %-12s\n", fprintf(fp, "%-20s %-6s %-5s %-12s %-12s %-12s %-12s\n",
"--------------------", "------", "-----", "----------", "------------", "------------", "-----------"); "--------------------", "------", "-----", "----------", "------------", "------------", "-----------");
total = 0;
for (m = 0; m < ALPROTO_MAX; m++) {
int p;
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_app_data4[m][p];
total += pd->tot;
pd = &packet_profile_app_data6[m][p];
total += pd->tot;
}
}
for (m = 0; m < ALPROTO_MAX; m++) { for (m = 0; m < ALPROTO_MAX; m++) {
int p; int p;
for (p = 0; p < 257; p++) { for (p = 0; p < 257; p++) {
@ -393,8 +453,12 @@ void SCProfilingDumpPacketStats(void) {
continue; continue;
} }
fprintf(fp, "%-20s IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64"\n", FormatNumber(pd->tot, totalstr, sizeof(totalstr));
TmModuleAlprotoToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt)); double percent = (long double)pd->tot /
(long double)total * 100;
fprintf(fp, "%-20s IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %-6.2f\n",
TmModuleAlprotoToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent);
} }
} }
@ -407,8 +471,12 @@ void SCProfilingDumpPacketStats(void) {
continue; continue;
} }
fprintf(fp, "%-20s IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64"\n", FormatNumber(pd->tot, totalstr, sizeof(totalstr));
TmModuleAlprotoToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt)); double percent = (long double)pd->tot /
(long double)total * 100;
fprintf(fp, "%-20s IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %-6.2f\n",
TmModuleAlprotoToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent);
} }
} }
@ -422,8 +490,9 @@ void SCProfilingDumpPacketStats(void) {
continue; continue;
} }
fprintf(fp, "%-20s IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64"\n", FormatNumber(pd->tot, totalstr, sizeof(totalstr));
"Proto detect", p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt)); fprintf(fp, "%-20s IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s\n",
"Proto detect", p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr);
} }
for (p = 0; p < 257; p++) { for (p = 0; p < 257; p++) {
@ -433,17 +502,29 @@ void SCProfilingDumpPacketStats(void) {
continue; continue;
} }
fprintf(fp, "%-20s IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64"\n", FormatNumber(pd->tot, totalstr, sizeof(totalstr));
"Proto detect", p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt)); fprintf(fp, "%-20s IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s\n",
"Proto detect", p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr);
} }
} }
total = 0;
for (m = 0; m < PROF_DETECT_SIZE; m++) {
int p;
for (p = 0; p < 257; p++) {
SCProfilePacketData *pd = &packet_profile_detect_data4[m][p];
total += pd->tot;
pd = &packet_profile_detect_data6[m][p];
total += pd->tot;
}
}
fprintf(fp, "\nGeneral detection engine stats:\n"); fprintf(fp, "\nGeneral detection engine stats:\n");
fprintf(fp, "\n%-24s %-6s %-5s %-12s %-12s %-12s %-12s\n", fprintf(fp, "\n%-24s %-6s %-5s %-12s %-12s %-12s %-12s %-12s\n",
"Detection phase", "IP ver", "Proto", "cnt", "min", "max", "avg"); "Detection phase", "IP ver", "Proto", "cnt", "min", "max", "avg", "tot");
fprintf(fp, "%-24s %-6s %-5s %-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 (m = 0; m < PROF_DETECT_SIZE; m++) {
int p; int p;
for (p = 0; p < 257; p++) { for (p = 0; p < 257; p++) {
@ -453,8 +534,12 @@ void SCProfilingDumpPacketStats(void) {
continue; continue;
} }
fprintf(fp, "%-24s IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64"\n", FormatNumber(pd->tot, totalstr, sizeof(totalstr));
PacketProfileDetectIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt)); double percent = (long double)pd->tot /
(long double)total * 100;
fprintf(fp, "%-24s IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %-6.2f\n",
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 (m = 0; m < PROF_DETECT_SIZE; m++) {
@ -466,8 +551,12 @@ void SCProfilingDumpPacketStats(void) {
continue; continue;
} }
fprintf(fp, "%-24s IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64"\n", FormatNumber(pd->tot, totalstr, sizeof(totalstr));
PacketProfileDetectIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt)); double percent = (long double)pd->tot /
(long double)total * 100;
fprintf(fp, "%-24s IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %-6.2f\n",
PacketProfileDetectIdToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent);
} }
} }
fclose(fp); fclose(fp);
@ -769,7 +858,7 @@ const char * PacketProfileDetectIdToString(PacketProfileDetectId id)
switch (id) { switch (id) {
CASE_CODE (PROF_DETECT_MPM); CASE_CODE (PROF_DETECT_MPM);
CASE_CODE (PROF_DETECT_MPM_PACKET); CASE_CODE (PROF_DETECT_MPM_PACKET);
CASE_CODE (PROF_DETECT_MPM_PKT_STREAM); // CASE_CODE (PROF_DETECT_MPM_PKT_STREAM);
CASE_CODE (PROF_DETECT_MPM_STREAM); CASE_CODE (PROF_DETECT_MPM_STREAM);
CASE_CODE (PROF_DETECT_MPM_URI); CASE_CODE (PROF_DETECT_MPM_URI);
CASE_CODE (PROF_DETECT_MPM_HCBD); CASE_CODE (PROF_DETECT_MPM_HCBD);
@ -789,7 +878,8 @@ const char * PacketProfileDetectIdToString(PacketProfileDetectId id)
CASE_CODE (PROF_DETECT_ALERT); CASE_CODE (PROF_DETECT_ALERT);
CASE_CODE (PROF_DETECT_CLEANUP); CASE_CODE (PROF_DETECT_CLEANUP);
CASE_CODE (PROF_DETECT_GETSGH); CASE_CODE (PROF_DETECT_GETSGH);
case PROF_DETECT_MPM_PKT_STREAM:
return "PROF_DETECT_MPM_PKT_STR";
default: default:
return "UNKNOWN"; return "UNKNOWN";
} }

Loading…
Cancel
Save