From 449a72d8a227bcbee516b3c60a49a754baec601c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Fri, 9 Feb 2024 14:43:03 +0100 Subject: [PATCH] trace_recorder: get session arguments from config This commit adds support for setting the TRACE session parameters via the configuration. Fixes #5123. --- repos/gems/src/app/trace_recorder/README | 8 +++- repos/gems/src/app/trace_recorder/monitor.cc | 48 ++++++++++++++++---- repos/gems/src/app/trace_recorder/monitor.h | 23 +++++++--- 3 files changed, 63 insertions(+), 16 deletions(-) diff --git a/repos/gems/src/app/trace_recorder/README b/repos/gems/src/app/trace_recorder/README index 47c3ef5990..58560b20f6 100644 --- a/repos/gems/src/app/trace_recorder/README +++ b/repos/gems/src/app/trace_recorder/README @@ -48,9 +48,15 @@ The '' 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 '' 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'). diff --git a/repos/gems/src/app/trace_recorder/monitor.cc b/repos/gems/src/app/trace_recorder/monitor.cc index 2a1420369a..14d92824bc 100644 --- a/repos/gems/src/app/trace_recorder/monitor.cc +++ b/repos/gems/src/app/trace_recorder/monitor.cc @@ -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(); } diff --git a/repos/gems/src/app/trace_recorder/monitor.h b/repos/gems/src/app/trace_recorder/monitor.h index 0fe4904c37..a5ed3a627a 100644 --- a/repos/gems/src/app/trace_recorder/monitor.h +++ b/repos/gems/src/app/trace_recorder/monitor.h @@ -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 { }; Signal_handler _timeout_handler { _env.ep(), *this,