From 7efc8dfcaefbebe1ff68da2b9e055d84793d74ef Mon Sep 17 00:00:00 2001 From: Alfredo Cardigliano Date: Thu, 25 Jul 2019 16:33:41 +0000 Subject: [PATCH] flowProcess profiling --- include/NetworkInterface.h | 2 +- src/NetworkInterface.cpp | 24 ++++++++++++++++++++++++ src/ZMQCollectorInterface.cpp | 11 +++++++++++ src/ZMQParserInterface.cpp | 1 + 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/NetworkInterface.h b/include/NetworkInterface.h index 49717cd197..ac0679908a 100644 --- a/include/NetworkInterface.h +++ b/include/NetworkInterface.h @@ -192,7 +192,7 @@ class NetworkInterface : public AlertableEntity { InterfaceStatsHash *interfaceStats; dhcp_range* dhcp_ranges, *dhcp_ranges_shadow; - PROFILING_DECLARE(24); + PROFILING_DECLARE(32); void init(); void deleteDataStructures(); diff --git a/src/NetworkInterface.cpp b/src/NetworkInterface.cpp index 1f4f382323..eb2e36ab29 100644 --- a/src/NetworkInterface.cpp +++ b/src/NetworkInterface.cpp @@ -1172,13 +1172,19 @@ void NetworkInterface::processFlow(ParsedFlow *zflow, bool zmq_flow) { return; } + PROFILING_SECTION_ENTER("processFlow getMac", 20); + if(!ntop->getPrefs()->do_ignore_macs()) { srcMac = getMac((u_int8_t*)zflow->src_mac, true /* Create if missing */, true /* Inline call */); dstMac = getMac((u_int8_t*)zflow->dst_mac, true /* Create if missing */, true /* Inline call */); } + PROFILING_SECTION_EXIT(20); + srcIP.set(&zflow->src_ip), dstIP.set(&zflow->dst_ip); + PROFILING_SECTION_ENTER("processFlow getFlow", 21); + /* Updating Flow */ flow = getFlow(srcMac, dstMac, zflow->vlan_id, @@ -1192,6 +1198,8 @@ void NetworkInterface::processFlow(ParsedFlow *zflow, bool zmq_flow) { zflow->last_switched, 0, &new_flow, true); + PROFILING_SECTION_EXIT(21); + if(flow == NULL) return; @@ -1288,6 +1296,8 @@ void NetworkInterface::processFlow(ParsedFlow *zflow, bool zmq_flow) { (src2dst_direction) ? 1 : 0); #endif + PROFILING_SECTION_ENTER("processFlow Inc", 22); + /* Update Mac stats Note: do not use src2dst_direction to inc the stats as in_bytes/in_pkts and out_bytes/out_pkts are already relative to the current @@ -1328,6 +1338,8 @@ void NetworkInterface::processFlow(ParsedFlow *zflow, bool zmq_flow) { zflow->tcp.lost_out_pkts, 0 /* TODO: add keepalive */); } + PROFILING_SECTION_EXIT(22); + #ifdef NTOPNG_PRO if(zflow->deviceIP) { // if(ntop->getPrefs()->is_flow_device_port_rrd_creation_enabled() && ntop->getPro()->has_valid_license()) { @@ -1355,6 +1367,9 @@ void NetworkInterface::processFlow(ParsedFlow *zflow, bool zmq_flow) { zflow->pkt_sampling_rate*zflow->in_fragments, zflow->pkt_sampling_rate*zflow->out_fragments, zflow->last_switched); + + PROFILING_SECTION_ENTER("processFlow Misc", 23); + p.app_protocol = zflow->l7_proto.app_protocol, p.master_protocol = zflow->l7_proto.master_protocol; p.category = NDPI_PROTOCOL_CATEGORY_UNSPECIFIED; flow->setDetectedProtocol(p, true); @@ -1381,9 +1396,17 @@ void NetworkInterface::processFlow(ParsedFlow *zflow, bool zmq_flow) { } #endif + PROFILING_SECTION_EXIT(23); + + PROFILING_SECTION_ENTER("processFlow fillZmqFlowCategory", 24); + // NOTE: fill the category only after the server name is set flow->fillZmqFlowCategory(); + PROFILING_SECTION_EXIT(24); + + PROFILING_SECTION_ENTER("processFlow incStats", 25); + /* Do not put incStats before guessing the flow protocol */ incStats(true /* ingressPacket */, now, srcIP.isIPv4() ? ETHERTYPE_IP : ETHERTYPE_IPV6, @@ -1392,6 +1415,7 @@ void NetworkInterface::processFlow(ParsedFlow *zflow, bool zmq_flow) { zflow->pkt_sampling_rate*(zflow->in_pkts + zflow->out_pkts), 24 /* 8 Preamble + 4 CRC + 12 IFG */ + 14 /* Ethernet header */); + PROFILING_SECTION_EXIT(25); /* purge is actually performed at most one time every FLOW_PURGE_FREQUENCY */ // purgeIdle(zflow->last_switched); diff --git a/src/ZMQCollectorInterface.cpp b/src/ZMQCollectorInterface.cpp index 5226f6eb3f..3b3a13c43f 100644 --- a/src/ZMQCollectorInterface.cpp +++ b/src/ZMQCollectorInterface.cpp @@ -126,6 +126,17 @@ ZMQCollectorInterface::ZMQCollectorInterface(const char *_endpoint) : ZMQParserI /* **************************************************** */ ZMQCollectorInterface::~ZMQCollectorInterface() { +#ifdef PROFILING + u_int64_t n = recvStats.num_flows; + if (n > 0) { + for (u_int i = 20; i < PROFILING_NUM_SECTIONS; i++) { + if (PROFILING_SECTION_LABEL(i) != NULL) + ntop->getTrace()->traceEvent(TRACE_NORMAL, "[PROFILING] Section #%d '%s': AVG %llu ticks", + i, PROFILING_SECTION_LABEL(i), PROFILING_SECTION_AVG(i, n)); + } + } +#endif + for(int i=0; ihasParsedeBPF()) { /* Direction already reliable when the event is an accept or a connect. Heuristic is only used in the other cases. */