mirror of
https://github.com/genodelabs/genode.git
synced 2025-05-28 21:24:26 +00:00
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:
parent
4025ca8ae1
commit
449a72d8a2
@ -48,9 +48,15 @@ The '<config>' node may take the following optional attributes:
|
|||||||
|
|
||||||
:'target_root': Sets the target root directory for trace output.
|
:'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:
|
Furthermore, the '<policy>' nodes may take the following optional attributes:
|
||||||
|
|
||||||
:'thread': Restricts the tracing to a certain thread of the matching component(s).
|
:'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').
|
||||||
|
@ -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)
|
void Trace_recorder::Monitor::Attached_buffer::process_events(Trace_directory &trace_directory)
|
||||||
{
|
{
|
||||||
/* start iteration for every writer */
|
/* start iteration for every writer */
|
||||||
@ -85,9 +101,17 @@ void Trace_recorder::Monitor::start(Xml_node config)
|
|||||||
/* create new trace directory */
|
/* create new trace directory */
|
||||||
_trace_directory.construct(_env, _alloc, config, _rtc);
|
_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 */
|
/* find matching subjects according to config and start tracing */
|
||||||
_trace.for_each_subject_info([&] (Trace::Subject_id const &id,
|
using SC = Genode::Trace::Session_client;
|
||||||
Trace::Subject_info const &info) {
|
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 {
|
try {
|
||||||
/* skip dead subjects */
|
/* skip dead subjects */
|
||||||
if (info.state() == Trace::Subject_info::DEAD)
|
if (info.state() == Trace::Subject_info::DEAD)
|
||||||
@ -100,14 +124,15 @@ void Trace_recorder::Monitor::start(Xml_node config)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Number_of_bytes buffer_sz =
|
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 */
|
/* find and assign policy; create/insert if not present */
|
||||||
Policy::Name const policy_name = session_policy.attribute_value("policy", Policy::Name());
|
Policy::Name const policy_name = session_policy.attribute_value("policy", Policy::Name());
|
||||||
bool const create =
|
bool const create =
|
||||||
_policies.with_element(policy_name,
|
_policies.with_element(policy_name,
|
||||||
[&] /* match */ (Policy & policy) {
|
[&] /* match */ (Policy & policy) {
|
||||||
_trace.trace(id, policy.id(), buffer_sz);
|
_trace->trace(id, policy.id(), buffer_sz);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
[&] /* no_match */ { return true; }
|
[&] /* no_match */ { return true; }
|
||||||
@ -115,8 +140,8 @@ void Trace_recorder::Monitor::start(Xml_node config)
|
|||||||
|
|
||||||
/* create policy if it did not exist */
|
/* create policy if it did not exist */
|
||||||
if (create) {
|
if (create) {
|
||||||
Policy &policy = *new (_alloc) Policy(_env, _trace, policy_name, _policies);
|
Policy &policy = *new (_alloc) Policy(_env, *_trace, policy_name, _policies);
|
||||||
_trace.trace(id, policy.id(), buffer_sz);
|
_trace->trace(id, policy.id(), buffer_sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
log("Inserting trace policy \"", policy_name, "\" into ",
|
log("Inserting trace policy \"", policy_name, "\" into ",
|
||||||
@ -125,7 +150,7 @@ void Trace_recorder::Monitor::start(Xml_node config)
|
|||||||
/* attach and remember trace buffer */
|
/* attach and remember trace buffer */
|
||||||
Attached_buffer &buffer = *new (_alloc) Attached_buffer(_trace_buffers,
|
Attached_buffer &buffer = *new (_alloc) Attached_buffer(_trace_buffers,
|
||||||
_env,
|
_env,
|
||||||
_trace.buffer(id),
|
_trace->buffer(id),
|
||||||
info,
|
info,
|
||||||
id);
|
id);
|
||||||
|
|
||||||
@ -153,6 +178,9 @@ void Trace_recorder::Monitor::start(Xml_node config)
|
|||||||
catch (Session_policy::No_policy_defined) { return; }
|
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 */
|
/* register timeout */
|
||||||
unsigned period_ms { 0 };
|
unsigned period_ms { 0 };
|
||||||
if (!config.has_attribute("period_ms"))
|
if (!config.has_attribute("period_ms"))
|
||||||
@ -171,7 +199,7 @@ void Trace_recorder::Monitor::stop()
|
|||||||
_trace_buffers.for_each([&] (Attached_buffer &buf) {
|
_trace_buffers.for_each([&] (Attached_buffer &buf) {
|
||||||
try {
|
try {
|
||||||
/* stop tracing */
|
/* stop tracing */
|
||||||
_trace.pause(buf.subject_id());
|
_trace->pause(buf.subject_id());
|
||||||
} catch (Trace::Nonexistent_subject) { }
|
} catch (Trace::Nonexistent_subject) { }
|
||||||
|
|
||||||
/* read remaining events from buffers */
|
/* read remaining events from buffers */
|
||||||
@ -184,7 +212,7 @@ void Trace_recorder::Monitor::stop()
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
/* detach buffer */
|
/* detach buffer */
|
||||||
_trace.free(buf.subject_id());
|
_trace->free(buf.subject_id());
|
||||||
} catch (Trace::Nonexistent_subject) { }
|
} catch (Trace::Nonexistent_subject) { }
|
||||||
|
|
||||||
/* destroy buffer */
|
/* destroy buffer */
|
||||||
@ -192,4 +220,6 @@ void Trace_recorder::Monitor::stop()
|
|||||||
});
|
});
|
||||||
|
|
||||||
_trace_directory.destruct();
|
_trace_directory.destruct();
|
||||||
|
|
||||||
|
_trace.destruct();
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,12 @@ namespace Trace_recorder {
|
|||||||
class Trace_recorder::Monitor
|
class Trace_recorder::Monitor
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
enum { DEFAULT_BUFFER_SIZE = 64 * 1024 };
|
|
||||||
enum { TRACE_SESSION_RAM = 1024 * 1024 };
|
enum {
|
||||||
enum { TRACE_SESSION_ARG_BUFFER = 128 * 1024 };
|
DEFAULT_BUFFER_SIZE = 64u * 1024,
|
||||||
|
DEFAULT_TRACE_SESSION_RAM = 1024u * 1024,
|
||||||
|
DEFAULT_TRACE_SESSION_ARG_BUFFER = 128u * 1024,
|
||||||
|
};
|
||||||
|
|
||||||
class Trace_directory
|
class Trace_directory
|
||||||
{
|
{
|
||||||
@ -112,9 +115,17 @@ class Trace_recorder::Monitor
|
|||||||
|
|
||||||
Rtc::Connection _rtc { _env };
|
Rtc::Connection _rtc { _env };
|
||||||
Timer::Connection _timer { _env };
|
Timer::Connection _timer { _env };
|
||||||
Trace::Connection _trace { _env,
|
|
||||||
TRACE_SESSION_RAM,
|
struct Config
|
||||||
TRACE_SESSION_ARG_BUFFER };
|
{
|
||||||
|
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(),
|
Signal_handler<Monitor> _timeout_handler { _env.ep(),
|
||||||
*this,
|
*this,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user