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
9{
12
13 void clear()
14 {
15 if (m_xstats_values != nullptr) {
16 free(m_xstats_values);
17 }
18 if (m_xstats_ids != nullptr) {
19 free(m_xstats_ids);
20 }
21 if (m_xstats_names != nullptr) {
22 free(m_xstats_names);
23 }
24 m_len = 0;
25 }
26
27 void setup(int iface)
28 {
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 {
72 if (m_enabled) {
73 rte_eth_xstats_reset(m_iface_id); //{
74 // TLOG() << "Cannot reset xstat values!";
75 //} else {
76 //}
77 }
78 }
79
80 void poll()
81 {
82 if (m_enabled) {
83 if (m_len != rte_eth_xstats_get_by_id(m_iface_id, nullptr, m_xstats_values, m_len)) {
84 TLOG() << "Cannot get xstat values!";
85 //} else {
86 }
87
88 rte_eth_stats_get(m_iface_id, &m_eth_stats);
89 }
90 }
91
92 void stop()
93 {
94 m_enabled = false;
95 clear();
96 TLOG() << "XstatsHelper disabled.";
97 }
98
100 bool m_enabled = false;
101 struct rte_eth_stats m_eth_stats;
102 struct rte_eth_xstat_name* m_xstats_names;
103 uint64_t* m_xstats_ids;
105 int m_len;
106};
107
108}
109
110#endif // DPDKLIBS_INCLUDE_DPDKLIBS_XSTATSHELPER_HPP_
#define TLOG(...)
Definition macro.hpp:21
struct rte_eth_stats m_eth_stats
struct rte_eth_xstat_name * m_xstats_names