]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dpdk: print debug xstats counters of all DPDK ports on shutdown
authorLukas Sismis <lsismis@oisf.net>
Wed, 21 Sep 2022 14:16:36 +0000 (16:16 +0200)
committerVictor Julien <vjulien@oisf.net>
Tue, 24 Jan 2023 09:44:49 +0000 (10:44 +0100)
src/source-dpdk.c

index 6bdd3167b8901a992c3b26efa4fcfda2cc3d7c8c..dd7aef11ababd1715e71962d2918515cdc24fb66 100644 (file)
@@ -526,6 +526,48 @@ fail:
     SCReturnInt(TM_ECODE_FAILED);
 }
 
+static void PrintDPDKPortXstats(uint32_t port_id, const char *port_name)
+{
+    struct rte_eth_xstat *xstats;
+    struct rte_eth_xstat_name *xstats_names;
+
+    int32_t len = rte_eth_xstats_get(port_id, NULL, 0);
+    if (len < 0)
+        FatalError("Error (%s) getting count of rte_eth_xstats failed on port %s",
+                rte_strerror(-len), port_name);
+
+    xstats = SCCalloc(len, sizeof(*xstats));
+    if (xstats == NULL)
+        FatalError("Failed to allocate memory for the rte_eth_xstat structure");
+
+    int32_t ret = rte_eth_xstats_get(port_id, xstats, len);
+    if (ret < 0 || ret > len) {
+        SCFree(xstats);
+        FatalError("Error (%s) getting rte_eth_xstats failed on port %s", rte_strerror(-ret),
+                port_name);
+    }
+    xstats_names = SCCalloc(len, sizeof(*xstats_names));
+    if (xstats_names == NULL) {
+        SCFree(xstats);
+        FatalError("Failed to allocate memory for the rte_eth_xstat_name array");
+    }
+    ret = rte_eth_xstats_get_names(port_id, xstats_names, len);
+    if (ret < 0 || ret > len) {
+        SCFree(xstats);
+        SCFree(xstats_names);
+        FatalError("Error (%s) getting names of rte_eth_xstats failed on port %s",
+                rte_strerror(-ret), port_name);
+    }
+    for (int32_t i = 0; i < len; i++) {
+        if (xstats[i].value > 0)
+            SCLogPerf("Port %u (%s) - %s: %" PRIu64, port_id, port_name, xstats_names[i].name,
+                    xstats[i].value);
+    }
+
+    SCFree(xstats);
+    SCFree(xstats_names);
+}
+
 /**
  * \brief This function prints stats to the screen at exit.
  * \param tv pointer to ThreadVars
@@ -547,6 +589,9 @@ static void ReceiveDPDKThreadExitStats(ThreadVars *tv, void *data)
                     strerror(-retval));
             SCReturn;
         }
+
+        PrintDPDKPortXstats(ptv->port_id, port_name);
+
         retval = rte_eth_stats_get(ptv->port_id, &eth_stats);
         if (unlikely(retval != 0)) {
             SCLogError("Failed to get stats for interface %s: %s", port_name, strerror(-retval));