mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-18 18:56:29 +00:00
trace: redirect logs to trace based on policy
If trace is enabled for component than an attempt to put message into trace buffer is performed using log_output policy. If it succeeds than message is not put to logs using log service. Fixes #3714
This commit is contained in:
parent
db8ec81e9f
commit
870d348d77
@ -417,6 +417,16 @@ class Genode::Thread
|
||||
_logger()->log(cstring, strlen(cstring));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log null-terminated string as trace event using log_output policy
|
||||
*
|
||||
* \return true if trace is really put to buffer
|
||||
*/
|
||||
static bool trace_captured(char const *cstring)
|
||||
{
|
||||
return _logger()->log_captured(cstring, strlen(cstring));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log binary data as trace event
|
||||
*/
|
||||
|
@ -67,6 +67,13 @@ struct Genode::Trace::Logger
|
||||
*/
|
||||
void log(char const *, size_t);
|
||||
|
||||
/**
|
||||
* Log binary data to trace buffer using log_output policy
|
||||
*
|
||||
* \return true if log is really put to buffer
|
||||
*/
|
||||
bool log_captured(char const *, size_t);
|
||||
|
||||
/**
|
||||
* Log event to trace buffer
|
||||
*/
|
||||
|
@ -98,7 +98,12 @@ void Genode::init_log(Parent &parent)
|
||||
|
||||
back_end_ptr = unmanaged_singleton<Back_end>(parent);
|
||||
|
||||
struct Write_fn { void operator () (char const *s) { back_end_ptr->write(s); } };
|
||||
struct Write_fn {
|
||||
void operator () (char const *s) {
|
||||
if (Thread::trace_captured(s)) return;
|
||||
back_end_ptr->write(s);
|
||||
}
|
||||
};
|
||||
|
||||
typedef Buffered_output<Log_session::MAX_STRING_LEN, Write_fn>
|
||||
Buffered_log_output;
|
||||
|
@ -157,6 +157,18 @@ void Trace::Logger::log(char const *msg, size_t len)
|
||||
}
|
||||
|
||||
|
||||
__attribute__((optimize("-fno-delete-null-pointer-checks")))
|
||||
bool Trace::Logger::log_captured(char const *msg, size_t len)
|
||||
{
|
||||
if (!this || !_evaluate_control()) return false;
|
||||
|
||||
len = policy_module->log_output(buffer->reserve(len), msg, len);
|
||||
buffer->commit(len);
|
||||
|
||||
return len != 0;
|
||||
}
|
||||
|
||||
|
||||
void Trace::Logger::init(Thread_capability thread, Cpu_session *cpu_session,
|
||||
Trace::Control *attached_control)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user