L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
utrace
Go to the documentation of this file.
1// vim:set ft=cpp: -*- Mode: C++ -*-
2/*
3 * Copyright (C) 2026 Kernkonzept GmbH.
4 * Author(s): Martin Decky <martin.decky@kernkonzept.com>
5 *
6 * License: see LICENSE.spdx (in this directory or the directories above)
7 */
8
17
18#pragma once
19
20#include <version>
21#include <bit>
22#include <string>
23#include <optional>
24#include <l4/sys/ktrace_events.h>
25#include <l4/sys/consts.h>
26#include <l4/sys/capability>
27#include <l4/sys/debugger>
28#include <l4/utrace/ring_buffer>
29
30#if defined(__cpp_lib_generator)
31#include <generator>
32#else
33#include <vector>
34#endif
35
36namespace utrace {
37
44class Tracebuffer
45{
46public:
47 using Sequence = L4_ktrace_t__Mword;
48 using Item = l4_tracebuffer_entry_t;
49
51 using Drop_policy = Buffer::Drop_policy;
52 using Status = Buffer::Status;
53 using Slot = Buffer::Slot;
54
55 static_assert(sizeof(Status) <= L4_PAGESIZE);
56
59 {
60 unsigned index;
61 std::string name;
62 std::string shortname;
63 };
64
74 static void validate();
75
77 static unsigned version();
78
80 static std::endian endianness();
81
90 static std::optional<Index_desc> index(unsigned idx);
91
98#if defined(__cpp_lib_generator)
99 static std::generator<Index_desc> indexes();
100#else
101 static std::vector<Index_desc> indexes();
102#endif
103
105 static Tracebuffer &instance();
106
108 size_t items() const;
109
129 size_t dequeue(Item *items, size_t capacity, size_t burst, Drop_policy policy,
130 Sequence *drops = nullptr);
131
132private:
133 static constexpr unsigned tracebuffer_version = 0;
134 static constexpr size_t yield_cycles = 100;
135
140 class Factory
141 {
142 public:
144 static Factory &instance();
145
147 Status &status();
148
150 Slot *slots();
151
152 private:
163 Factory();
164
171 ~Factory();
172
186 static l4_fpage_t reserve(size_t size);
187
198 static Status *map_status(l4_fpage_t fpage);
199
211 static Slot *map_slots(l4_fpage_t fpage, size_t items);
212
213 l4_fpage_t _fpage_status;
214 l4_fpage_t _fpage_slots;
215
216 Status *_status;
217 Slot *_slots;
218 };
219
220 Tracebuffer() = delete;
221
227 Tracebuffer(Factory &factory);
228
229 static L4::Cap<L4::Debugger> _jdb;
230 Buffer _buffer;
231};
232
233}; // namespace utrace
L4::Cap related definitions.
C++ interface for capabilities.
Definition capability.h:224
Blocking ring buffer consumer.
Definition ring_buffer:512
Tracebuffer abstraction.
Definition utrace:45
static std::endian endianness()
Get the endianness supported by this class.
static void validate()
Check that the base debugger (JDB) capability is valid and accessible.
static std::optional< Index_desc > index(unsigned idx)
Map a dynamic tracebuffer log index to names.
static std::vector< Index_desc > indexes()
Get all mappings of dynamic tracebuffer log indexes to names.
static Tracebuffer & instance()
Get the singleton instance of this class.
size_t dequeue(Item *items, size_t capacity, size_t burst, Drop_policy policy, Sequence *drops=nullptr)
Dequeue items from the tracebuffer.
static unsigned version()
Get the tracebuffer format version supported by this class.
size_t items() const
Get the capacity (in items) of the tracebuffer ring buffer.
The debugger interface specifies common debugging related definitions.
#define L4_PAGESIZE
Minimal page size (in bytes).
Definition consts.h:410
Common constants.
Shared-memory multiple-producer multiple-consumer head-drop ring buffer implementation.
Data buffer used to transfer packets.
Mapping of the dynamic tracebuffer log indexes to names.
Definition utrace:59
L4 flexpage type.
Definition __l4_fpage.h:76