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 clear();
13 }
14
15 void clear() {
16 if (m_xstats_values != nullptr) {
17 free(m_xstats_values);
18 }
19 if (m_xstats_ids != nullptr) {
20 free(m_xstats_ids);
21 }
22 if (m_xstats_names != nullptr) {
23 free(m_xstats_names);
24 }
25 m_len = 0;
26 }
27
28 void setup(int iface) {
29 m_iface_id = iface;
30 rte_eth_stats_reset(m_iface_id);
31 rte_eth_xstats_reset(m_iface_id);
32
33 // Get number of stats
34 m_len = rte_eth_xstats_get_names_by_id(m_iface_id, NULL, 0, NULL);
35 if (m_len < 0) {
36 printf("Cannot get xstats count\n");
37 }
38
39 // Get names of HW registered stat fields
40 m_xstats_names = (rte_eth_xstat_name*)(malloc(sizeof(struct rte_eth_xstat_name) * m_len));
41 if (m_xstats_names == nullptr) {
42 printf("Cannot allocate memory for xstat names\n");
43 }
44
45 // Retrieve xstats names, passing NULL for IDs to return all statistics
46 if (m_len != rte_eth_xstats_get_names(m_iface_id, m_xstats_names, m_len)) {
47 printf("Cannot get xstat names\n");
48 }
49
50 // Allocate value fields
51 m_xstats_values = (uint64_t*)(malloc(sizeof(m_xstats_values) * m_len));
52 if (m_xstats_values == nullptr) {
53 printf("Cannot allocate memory for xstats\n");
54 }
55
56 // Getting xstats values (this is that we call in a loop/get_info
57 if (m_len != rte_eth_xstats_get_by_id(m_iface_id, nullptr, m_xstats_values, m_len)) {
58 printf("Cannot get xstat values\n");
59 }
60
61 // Print all xstats names and values to be amazed (WOW!)
62 TLOG() << "Registered HW based metrics: ";
63 for (int i = 0; i < m_len; i++) {
64 TLOG() << " XName: " << m_xstats_names[i].name;
65 }
66
67 m_enabled = true;
68 };
69
71 if (m_enabled) {
72 rte_eth_xstats_reset(m_iface_id); //{
73 // TLOG() << "Cannot reset xstat values!";
74 //} else {
75 //}
76 }
77 }
78
79 void poll() {
80 if (m_enabled) {
81 if (m_len != rte_eth_xstats_get_by_id(m_iface_id, nullptr, m_xstats_values, m_len)) {
82 TLOG() << "Cannot get xstat values!";
83 //} else {
84 }
85
86 rte_eth_stats_get(m_iface_id, &m_eth_stats);
87 }
88 }
89
90 void stop() {
91 m_enabled = false;
92 clear();
93 TLOG() << "XstatsHelper disabled.";
94 }
95
97 bool m_enabled = false;
98 struct rte_eth_stats m_eth_stats;
99 struct rte_eth_xstat_name *m_xstats_names;
100 uint64_t *m_xstats_ids;
102 int m_len;
103
104 };
105
106}
107
108#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