DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
XstatsHelper.hpp
Go to the documentation of this file.
1#ifndef DPDKLIBS_INCLUDE_DPDKLIBS_XSTATSHELPER_HPP_
2#define DPDKLIBS_INCLUDE_DPDKLIBS_XSTATSHELPER_HPP_
3
4#include <rte_ethdev.h>
5
6namespace dunedaq::dpdklibs {
7
8 struct IfaceXstats {
11 {
12 if (m_xstats_values != nullptr) {
13 free(m_xstats_values);
14 }
15 if (m_xstats_ids != nullptr) {
16 free(m_xstats_ids);
17 }
18 if (m_xstats_names != nullptr) {
19 free(m_xstats_names);
20 }
21 }
22
23 void setup(int iface) {
24 m_iface_id = iface;
25 rte_eth_stats_reset(m_iface_id);
26 rte_eth_xstats_reset(m_iface_id);
27
28 // Get number of stats
29 m_len = rte_eth_xstats_get_names_by_id(m_iface_id, NULL, 0, NULL);
30 if (m_len < 0) {
31 printf("Cannot get xstats count\n");
32 }
33
34 // Get names of HW registered stat fields
35 m_xstats_names = (rte_eth_xstat_name*)(malloc(sizeof(struct rte_eth_xstat_name) * m_len));
36 if (m_xstats_names == nullptr) {
37 printf("Cannot allocate memory for xstat names\n");
38 }
39
40 // Retrieve xstats names, passing NULL for IDs to return all statistics
41 if (m_len != rte_eth_xstats_get_names(m_iface_id, m_xstats_names, m_len)) {
42 printf("Cannot get xstat names\n");
43 }
44
45 // Allocate value fields
46 m_xstats_values = (uint64_t*)(malloc(sizeof(m_xstats_values) * m_len));
47 if (m_xstats_values == nullptr) {
48 printf("Cannot allocate memory for xstats\n");
49 }
50
51 // Getting xstats values (this is that we call in a loop/get_info
52 if (m_len != rte_eth_xstats_get_by_id(m_iface_id, nullptr, m_xstats_values, m_len)) {
53 printf("Cannot get xstat values\n");
54 }
55
56 // Print all xstats names and values to be amazed (WOW!)
57 TLOG() << "Registered HW based metrics: ";
58 for (int i = 0; i < m_len; i++) {
59 TLOG() << " XName: " << m_xstats_names[i].name;
60 }
61
62 m_allocated = true;
63 };
64
66 if (m_allocated) {
67 rte_eth_xstats_reset(m_iface_id); //{
68 // TLOG() << "Cannot reset xstat values!";
69 //} else {
70 //}
71 }
72 }
73
74 void poll() {
75 if (m_allocated) {
76 if (m_len != rte_eth_xstats_get_by_id(m_iface_id, nullptr, m_xstats_values, m_len)) {
77 TLOG() << "Cannot get xstat values!";
78 //} else {
79 }
80
81 rte_eth_stats_get(m_iface_id, &m_eth_stats);
82 }
83 }
84
86 bool m_allocated = false;
87 struct rte_eth_stats m_eth_stats;
88 struct rte_eth_xstat_name *m_xstats_names;
89 uint64_t *m_xstats_ids;
90 uint64_t *m_xstats_values;
91 int m_len;
92
93 };
94
95}
96
97#endif // DPDKLIBS_INCLUDE_DPDKLIBS_XSTATSHELPER_HPP_
#define TLOG(...)
Definition macro.hpp:22
struct rte_eth_stats m_eth_stats
struct rte_eth_xstat_name * m_xstats_names