9#include "../formatters/json.hpp"
10#include "../microfmt.hpp"
11#include "../reloco.hpp"
37 out.write(
"SUSPENDED");
43 out.write(
"SLEEPING");
46 out.write(
"TERMINATED");
60 uint64_t thread_id{0};
64 uint32_t cpu_ticks{0};
65 uint32_t stack_size{0};
66 uint32_t stack_usage{0};
73 void *extended_metadata_ctx{
nullptr};
81 bool in_extended{
false};
90 the_state.thread =
this;
92 the_state.in_extended =
false;
96 if (s ==
nullptr || s->thread ==
nullptr)
100 if (!s->in_extended) {
103 out.
key =
"thread_id";
104 out.
val_ptr = &s->thread->thread_id;
105 out.
print_fn = [](
const void *p,
const sink &s_out)
noexcept {
106 detail::format_unsigned<detail::radix::decimal>(s_out, *
static_cast<const uint64_t *
>(p),
false);
111 out.
val_ptr = &s->thread->name;
112 out.
print_fn = [](
const void *p,
const sink &s_out)
noexcept {
113 json::write_escaped_string(s_out, *
static_cast<const string_view *
>(p));
117 out.
key =
"priority";
118 out.
val_ptr = &s->thread->priority;
119 out.
print_fn = [](
const void *p,
const sink &s_out)
noexcept {
120 detail::format_unsigned<detail::radix::decimal>(s_out, *
static_cast<const uint8_t *
>(p),
false);
125 out.
val_ptr = &s->thread->state;
126 out.
print_fn = [](
const void *p,
const sink &s_out)
noexcept {
129 fmt.parse(parse_context);
134 out.
key =
"cpu_ticks";
135 out.
val_ptr = &s->thread->cpu_ticks;
136 out.
print_fn = [](
const void *p,
const sink &s_out)
noexcept {
137 detail::format_unsigned<detail::radix::decimal>(s_out, *
static_cast<const uint32_t *
>(p),
false);
141 out.
key =
"stack_size_bytes";
142 out.
val_ptr = &s->thread->stack_size;
143 out.
print_fn = [](
const void *p,
const sink &s_out)
noexcept {
144 detail::format_unsigned<detail::radix::decimal>(s_out, *
static_cast<const uint32_t *
>(p),
false);
148 out.
key =
"stack_usage_bytes";
149 out.
val_ptr = &s->thread->stack_usage;
150 out.
print_fn = [](
const void *p,
const sink &s_out)
noexcept {
151 detail::format_unsigned<detail::radix::decimal>(s_out, *
static_cast<const uint32_t *
>(p),
false);
155 s->in_extended =
true;
161 if (s->in_extended) {
162 if (s->thread->extended_metadata_fn !=
nullptr && s->thread->extended_metadata_ctx !=
nullptr) {
163 return s->thread->extended_metadata_fn(s->thread->extended_metadata_ctx, out);
Definition microfmt.hpp:881
Zero-allocation, type-erased handle for inspecting and modifying CPU registers from a frame context.
Definition register_context.hpp:118
#define MICROFMT_API_CLASS
Definition compat.hpp:181
reloco::sink sink
Type-erased, zero-allocation output sink.
Definition microfmt.hpp:46
bool(*)(void *ctx, property_entry &out) noexcept metadata_next_fn_t
Function pointer signature for fetching the next property entry.
Definition metadata_map.hpp:48
thread_state
Detailed execution state of an individual thread.
Definition thread.hpp:20
Type-erased property entry synthesized during generation.
Definition metadata_map.hpp:24
property_print_fn_t print_fn
Definition metadata_map.hpp:27
microfmt::string_view key
Definition metadata_map.hpp:25
value_ptr< const void > val_ptr
Definition metadata_map.hpp:26
Thread descriptor containing thread-specific attributes and CPU register context access.
Definition thread.hpp:58
constexpr metadata_map make_metadata_view(metadata_state &the_state) const &noexcept RELOCO_LIFETIMEBOUND
Exposes a unified metadata_map view that automatically forwards from core thread properties to any at...
Definition thread.hpp:89
metadata_map make_metadata_view(metadata_state &) const &&=delete