Skip to content

Commit 39bf2e3

Browse files
committed
mac: improve logging of slot_point_extended types
1 parent c6a8219 commit 39bf2e3

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

apps/units/flexible_o_du/o_du_high/du_high/metrics/consumers/mac_metrics_consumers.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#include "mac_metrics_consumers.h"
12+
#include "srsran/support/format/custom_formattable.h"
1213
#include "srsran/support/format/fmt_to_c_str.h"
1314

1415
using namespace srsran;
@@ -37,14 +38,25 @@ void mac_metrics_consumer_log::handle_metric(const mac_dl_metric_report& report)
3738
for (unsigned i = 0, e = report.cells.size(); i != e; ++i) {
3839
const mac_dl_cell_metric_report& cell = report.cells[i];
3940

40-
fmt::format_to(std::back_inserter(buffer),
41-
"MAC cell pci={} metrics: nof_slots={} slot_duration={}usec nof_voluntary_context_switches={} "
42-
"nof_involuntary_context_switches={} ",
43-
static_cast<unsigned>(cell.pci),
44-
cell.nof_slots,
45-
std::round(cell.slot_duration.count() * 1e-3),
46-
cell.count_voluntary_context_switches,
47-
cell.count_involuntary_context_switches);
41+
fmt::format_to(
42+
std::back_inserter(buffer),
43+
"MAC cell pci={} metrics: slots=[{}, {}{}) nof_slots={} slot_duration={}usec nof_voluntary_context_switches={} "
44+
"nof_involuntary_context_switches={} ",
45+
static_cast<unsigned>(cell.pci),
46+
cell.start_slot,
47+
cell.start_slot + cell.nof_slots,
48+
// Also print the number of HFN wrap-arounds. Useful for long report periods.
49+
make_formattable([x = cell.start_slot, n = cell.nof_slots](auto& out) {
50+
auto nof_wrap_arounds = (x.count() + n) / x.nof_slots_per_hyper_system_frame();
51+
if (nof_wrap_arounds > 0) {
52+
return fmt::format_to(out.out(), "(+{} HFNs)", nof_wrap_arounds);
53+
}
54+
return out.out();
55+
}),
56+
cell.nof_slots,
57+
std::chrono::duration_cast<std::chrono::microseconds>(cell.slot_duration).count(),
58+
cell.count_voluntary_context_switches,
59+
cell.count_involuntary_context_switches);
4860

4961
write_latency_information(buffer, cell.wall_clock_latency, "wall_clock_latency");
5062
write_latency_information(buffer, cell.sched_latency, "sched_latency");

include/srsran/ran/slot_point.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class slot_point
103103
constexpr uint32_t slot_index() const { return static_cast<uint32_t>(count_val) % nof_slots_per_frame(); }
104104

105105
/// Radio Frame Number. Value: (0..1023).
106-
constexpr uint32_t sfn() const { return static_cast<uint32_t>(count_val) / nof_slots_per_frame(); }
106+
constexpr uint32_t sfn() const { return (static_cast<uint32_t>(count_val) / nof_slots_per_frame()) % NOF_SFNS; }
107107

108108
/// Number of slots per hyper system frame. Values: (0..1023).
109109
constexpr uint32_t nof_slots_per_hyper_system_frame() const { return nof_slots_per_frame() * NOF_SFNS; }
@@ -299,4 +299,5 @@ struct formatter<srsran::slot_point> {
299299
return format_to(ctx.out(), "{}.{}", slot.sfn(), slot.slot_index());
300300
}
301301
};
302+
302303
} // namespace fmt

include/srsran/ran/slot_point_extended.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,22 @@ inline slot_point_extended min(slot_point_extended lhs, slot_point_extended rhs)
192192
}
193193

194194
} // namespace srsran
195+
196+
namespace fmt {
197+
198+
/// FMT formatter of slot_point type.
199+
template <>
200+
struct formatter<srsran::slot_point_extended> {
201+
template <typename ParseContext>
202+
auto parse(ParseContext& ctx)
203+
{
204+
return ctx.begin();
205+
}
206+
template <typename FormatContext>
207+
auto format(srsran::slot_point_extended slot, FormatContext& ctx) const
208+
{
209+
return format_to(ctx.out(), "{}.{}.{}", slot.hyper_sfn(), slot.sfn(), slot.slot_index());
210+
}
211+
};
212+
213+
} // namespace fmt

lib/mac/mac_ctrl/mac_metrics_aggregator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ void mac_metrics_aggregator::try_send_new_report()
357357
if (ring_elem.start_slot != next_report_start_slot) {
358358
// Invalid ring slot.
359359
logger.warning("Discarding metric report for slot={}. Cause: Expected report for slot={}",
360-
ring_elem.start_slot.without_hyper_sfn(),
361-
next_report_start_slot.without_hyper_sfn());
360+
ring_elem.start_slot,
361+
next_report_start_slot);
362362
return;
363363
}
364364

@@ -367,8 +367,8 @@ void mac_metrics_aggregator::try_send_new_report()
367367

368368
logger.debug("Metric report of {} cells completed for slots=[{}, {})",
369369
next_report.dl.cells.size(),
370-
next_report_start_slot.without_hyper_sfn(),
371-
(next_report_start_slot + period_slots).without_hyper_sfn());
370+
next_report_start_slot,
371+
(next_report_start_slot + period_slots));
372372
}
373373

374374
void mac_metrics_aggregator::handle_cell_activation(du_cell_index_t cell_index, slot_point_extended report_end_sl_tx)

0 commit comments

Comments
 (0)