trace_recorder: get session arguments from config

This commit adds support for setting the TRACE session parameters via
the configuration.

Fixes #5123.
This commit is contained in:
Josef Söntgen 2024-02-09 14:43:03 +01:00
parent 4025ca8ae1
commit 449a72d8a2
No known key found for this signature in database
GPG Key ID: CFCD8B5D2D93D80E
3 changed files with 63 additions and 16 deletions

View File

@ -48,9 +48,15 @@ The '<config>' node may take the following optional attributes:
:'target_root': Sets the target root directory for trace output.
:'default_buffer': Sets the default buffer size (default: '64K'), can be overriden
via policy.
:'session_ram': Sets the session RAM quota (default: '1024K').
:'session_arg_buffer': Sets the session argument buffer size (default: '128K').
Furthermore, the '<policy>' nodes may take the following optional attributes:
:'thread': Restricts the tracing to a certain thread of the matching component(s).
:'buffer': Sets the size of the trace buffer (default: '64K').
:'buffer': Sets the size of the trace buffer (default: see 'default_buffer').

View File

@ -27,6 +27,22 @@ Directory::Path Trace_recorder::Monitor::Trace_directory::subject_path(::Subject
}
Trace_recorder::Monitor::Config Trace_recorder::Monitor::Config::from_xml(Xml_node const &config)
{
return {
.session_ram =
config.attribute_value("session_ram",
Number_of_bytes(DEFAULT_TRACE_SESSION_RAM)),
.session_arg_buffer =
config.attribute_value("session_arg_buffer",
Number_of_bytes(DEFAULT_TRACE_SESSION_ARG_BUFFER)),
.default_buf_sz =
config.attribute_value("default_buffer",
Number_of_bytes(DEFAULT_BUFFER_SIZE)),
};
}
void Trace_recorder::Monitor::Attached_buffer::process_events(Trace_directory &trace_directory)
{
/* start iteration for every writer */
@ -85,9 +101,17 @@ void Trace_recorder::Monitor::start(Xml_node config)
/* create new trace directory */
_trace_directory.construct(_env, _alloc, config, _rtc);
using TM = Trace_recorder::Monitor;
TM::Config const trace_config = TM::Config::from_xml(config);
_trace.construct(_env, trace_config.session_ram,
trace_config.session_arg_buffer);
/* find matching subjects according to config and start tracing */
_trace.for_each_subject_info([&] (Trace::Subject_id const &id,
Trace::Subject_info const &info) {
using SC = Genode::Trace::Session_client;
SC::For_each_subject_info_result const info_result =
_trace->for_each_subject_info([&] (Trace::Subject_id const &id,
Trace::Subject_info const &info) {
try {
/* skip dead subjects */
if (info.state() == Trace::Subject_info::DEAD)
@ -100,14 +124,15 @@ void Trace_recorder::Monitor::start(Xml_node config)
return;
Number_of_bytes buffer_sz =
session_policy.attribute_value("buffer", Number_of_bytes(DEFAULT_BUFFER_SIZE));
session_policy.attribute_value("buffer",
Number_of_bytes(trace_config.default_buf_sz));
/* find and assign policy; create/insert if not present */
Policy::Name const policy_name = session_policy.attribute_value("policy", Policy::Name());
bool const create =
_policies.with_element(policy_name,
[&] /* match */ (Policy & policy) {
_trace.trace(id, policy.id(), buffer_sz);
_trace->trace(id, policy.id(), buffer_sz);
return false;
},
[&] /* no_match */ { return true; }
@ -115,8 +140,8 @@ void Trace_recorder::Monitor::start(Xml_node config)
/* create policy if it did not exist */
if (create) {
Policy &policy = *new (_alloc) Policy(_env, _trace, policy_name, _policies);
_trace.trace(id, policy.id(), buffer_sz);
Policy &policy = *new (_alloc) Policy(_env, *_trace, policy_name, _policies);
_trace->trace(id, policy.id(), buffer_sz);
}
log("Inserting trace policy \"", policy_name, "\" into ",
@ -125,7 +150,7 @@ void Trace_recorder::Monitor::start(Xml_node config)
/* attach and remember trace buffer */
Attached_buffer &buffer = *new (_alloc) Attached_buffer(_trace_buffers,
_env,
_trace.buffer(id),
_trace->buffer(id),
info,
id);
@ -153,6 +178,9 @@ void Trace_recorder::Monitor::start(Xml_node config)
catch (Session_policy::No_policy_defined) { return; }
});
if (info_result.count == info_result.limit)
warning("number of subjects equals limit, results may be truncated");
/* register timeout */
unsigned period_ms { 0 };
if (!config.has_attribute("period_ms"))
@ -171,7 +199,7 @@ void Trace_recorder::Monitor::stop()
_trace_buffers.for_each([&] (Attached_buffer &buf) {
try {
/* stop tracing */
_trace.pause(buf.subject_id());
_trace->pause(buf.subject_id());
} catch (Trace::Nonexistent_subject) { }
/* read remaining events from buffers */
@ -184,7 +212,7 @@ void Trace_recorder::Monitor::stop()
try {
/* detach buffer */
_trace.free(buf.subject_id());
_trace->free(buf.subject_id());
} catch (Trace::Nonexistent_subject) { }
/* destroy buffer */
@ -192,4 +220,6 @@ void Trace_recorder::Monitor::stop()
});
_trace_directory.destruct();
_trace.destruct();
}

View File

@ -38,9 +38,12 @@ namespace Trace_recorder {
class Trace_recorder::Monitor
{
private:
enum { DEFAULT_BUFFER_SIZE = 64 * 1024 };
enum { TRACE_SESSION_RAM = 1024 * 1024 };
enum { TRACE_SESSION_ARG_BUFFER = 128 * 1024 };
enum {
DEFAULT_BUFFER_SIZE = 64u * 1024,
DEFAULT_TRACE_SESSION_RAM = 1024u * 1024,
DEFAULT_TRACE_SESSION_ARG_BUFFER = 128u * 1024,
};
class Trace_directory
{
@ -112,9 +115,17 @@ class Trace_recorder::Monitor
Rtc::Connection _rtc { _env };
Timer::Connection _timer { _env };
Trace::Connection _trace { _env,
TRACE_SESSION_RAM,
TRACE_SESSION_ARG_BUFFER };
struct Config
{
size_t session_ram;
size_t session_arg_buffer;
size_t default_buf_sz;
static Config from_xml(Xml_node const &);
};
Constructible<Trace::Connection> _trace { };
Signal_handler<Monitor> _timeout_handler { _env.ep(),
*this,