aboutsummaryrefslogtreecommitdiff
path: root/example/ndpiReader.c
diff options
context:
space:
mode:
authorIvan Nardi <12729895+IvanNardi@users.noreply.github.com>2021-07-13 12:28:39 +0200
committerGitHub <noreply@github.com>2021-07-13 12:28:39 +0200
commitcccf794265dee24f25e16f21753972b20f7593c5 (patch)
treeeacc03e4e831ff7be5a0372c6e7cbbf386affeb3 /example/ndpiReader.c
parent96b71def49e46c7fbc7ba5fae3f355eb7d90151b (diff)
ndpiReader: add statistics about nDPI performance (#1240)
The goal is to have a (roughly) idea about how many packets nDPI needs to properly classify a flow. Log this information (and guessed flows number too) during unit tests, to keep track of improvements/regressions across commits.
Diffstat (limited to 'example/ndpiReader.c')
-rw-r--r--example/ndpiReader.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c
index 4acaea4bb..ef74a5a99 100644
--- a/example/ndpiReader.c
+++ b/example/ndpiReader.c
@@ -2916,6 +2916,9 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
}
cumulative_stats.ndpi_flow_count += ndpi_thread_info[thread_id].workflow->stats.ndpi_flow_count;
+ cumulative_stats.flow_count[0] += ndpi_thread_info[thread_id].workflow->stats.flow_count[0];
+ cumulative_stats.flow_count[1] += ndpi_thread_info[thread_id].workflow->stats.flow_count[1];
+ cumulative_stats.flow_count[2] += ndpi_thread_info[thread_id].workflow->stats.flow_count[2];
cumulative_stats.tcp_count += ndpi_thread_info[thread_id].workflow->stats.tcp_count;
cumulative_stats.udp_count += ndpi_thread_info[thread_id].workflow->stats.udp_count;
cumulative_stats.mpls_count += ndpi_thread_info[thread_id].workflow->stats.mpls_count;
@@ -2925,6 +2928,10 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
for(i = 0; i < sizeof(cumulative_stats.packet_len)/sizeof(cumulative_stats.packet_len[0]); i++)
cumulative_stats.packet_len[i] += ndpi_thread_info[thread_id].workflow->stats.packet_len[i];
cumulative_stats.max_packet_len += ndpi_thread_info[thread_id].workflow->stats.max_packet_len;
+
+ cumulative_stats.dpi_packet_count[0] += ndpi_thread_info[thread_id].workflow->stats.dpi_packet_count[0];
+ cumulative_stats.dpi_packet_count[1] += ndpi_thread_info[thread_id].workflow->stats.dpi_packet_count[1];
+ cumulative_stats.dpi_packet_count[2] += ndpi_thread_info[thread_id].workflow->stats.dpi_packet_count[2];
}
if(cumulative_stats.total_wire_bytes == 0)
@@ -2996,8 +3003,39 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
if(enable_protocol_guess)
printf("\tGuessed flow protos: %-13u\n", cumulative_stats.guessed_flow_protocols);
+
+ if(cumulative_stats.flow_count[0])
+ printf("\tDPI Packets (TCP): %-13llu (%.2f pkts/flow)\n",
+ (long long unsigned int)cumulative_stats.dpi_packet_count[0],
+ cumulative_stats.dpi_packet_count[0] / (float)cumulative_stats.flow_count[0]);
+ if(cumulative_stats.flow_count[1])
+ printf("\tDPI Packets (UDP): %-13llu (%.2f pkts/flow)\n",
+ (long long unsigned int)cumulative_stats.dpi_packet_count[1],
+ cumulative_stats.dpi_packet_count[1] / (float)cumulative_stats.flow_count[1]);
+ if(cumulative_stats.flow_count[2])
+ printf("\tDPI Packets (other): %-13llu (%.2f pkts/flow)\n",
+ (long long unsigned int)cumulative_stats.dpi_packet_count[2],
+ cumulative_stats.dpi_packet_count[2] / (float)cumulative_stats.flow_count[2]);
}
+ if(results_file) {
+ if(enable_protocol_guess)
+ fprintf(results_file, "Guessed flow protos:\t%u\n\n", cumulative_stats.guessed_flow_protocols);
+
+ if(cumulative_stats.flow_count[0])
+ fprintf(results_file, "DPI Packets (TCP):\t%llu\t(%.2f pkts/flow)\n",
+ (long long unsigned int)cumulative_stats.dpi_packet_count[0],
+ cumulative_stats.dpi_packet_count[0] / (float)cumulative_stats.flow_count[0]);
+ if(cumulative_stats.flow_count[1])
+ fprintf(results_file, "DPI Packets (UDP):\t%llu\t(%.2f pkts/flow)\n",
+ (long long unsigned int)cumulative_stats.dpi_packet_count[1],
+ cumulative_stats.dpi_packet_count[1] / (float)cumulative_stats.flow_count[1]);
+ if(cumulative_stats.flow_count[2])
+ fprintf(results_file, "DPI Packets (other):\t%llu\t(%.2f pkts/flow)\n",
+ (long long unsigned int)cumulative_stats.dpi_packet_count[2],
+ cumulative_stats.dpi_packet_count[2] / (float)cumulative_stats.flow_count[2]);
+ fprintf(results_file, "\n");
+ }
if(!quiet_mode) printf("\n\nDetected protocols:\n");
for(i = 0; i <= ndpi_get_num_supported_protocols(ndpi_thread_info[0].workflow->ndpi_struct); i++) {