mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 05:37:54 +00:00
base: add 'trace' function to base/log.h
The 'Genode::trace' convenience function prints messages to Genode's trace buffer (if tracing is enabled). issue #3294
This commit is contained in:
parent
18b3253cac
commit
24eea0b653
@ -16,11 +16,13 @@
|
||||
|
||||
#include <base/output.h>
|
||||
#include <base/lock.h>
|
||||
#include <trace/timestamp.h>
|
||||
|
||||
namespace Genode {
|
||||
|
||||
class Log;
|
||||
class Raw;
|
||||
class Trace_output;
|
||||
}
|
||||
|
||||
|
||||
@ -101,6 +103,36 @@ class Genode::Raw
|
||||
};
|
||||
|
||||
|
||||
class Genode::Trace_output
|
||||
{
|
||||
private:
|
||||
|
||||
Lock _lock { };
|
||||
|
||||
Output &_output;
|
||||
|
||||
void _acquire();
|
||||
void _release();
|
||||
|
||||
public:
|
||||
|
||||
Trace_output(Output &output) : _output(output) { }
|
||||
|
||||
template <typename... ARGS>
|
||||
void output(ARGS &&... args)
|
||||
{
|
||||
_acquire();
|
||||
Output::out_args(_output, args...);
|
||||
_release();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return component-global singleton instance of the 'Trace_output'
|
||||
*/
|
||||
static Trace_output &trace_output();
|
||||
};
|
||||
|
||||
|
||||
namespace Genode {
|
||||
|
||||
/**
|
||||
@ -140,6 +172,16 @@ namespace Genode {
|
||||
*/
|
||||
template <typename... ARGS>
|
||||
void raw(ARGS &&... args) { Raw::output(args...); }
|
||||
|
||||
|
||||
/**
|
||||
* Write 'args' to the trace buffer if tracing is enabled
|
||||
*
|
||||
* The message is prefixed with a timestamp value
|
||||
*/
|
||||
template <typename... ARGS>
|
||||
void trace(ARGS && ... args) {
|
||||
Trace_output::trace_output().output(Trace::timestamp(), ": ", args...); }
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__BASE__LOG_H_ */
|
||||
|
@ -80,6 +80,9 @@ _ZN6Genode11Sliced_heapD1Ev T
|
||||
_ZN6Genode11Sliced_heapD2Ev T
|
||||
_ZN6Genode12Address_infoC1Em T
|
||||
_ZN6Genode12Address_infoC2Em T
|
||||
_ZN6Genode12Trace_output12trace_outputEv T
|
||||
_ZN6Genode12Trace_output8_acquireEv T
|
||||
_ZN6Genode12Trace_output8_releaseEv T
|
||||
_ZN6Genode13Avl_node_base15_rotate_subtreeEPS0_bRNS0_6PolicyE T
|
||||
_ZN6Genode13Avl_node_base18_rebalance_subtreeEPS0_RNS0_6PolicyE T
|
||||
_ZN6Genode13Avl_node_base6_adoptEPS0_bRNS0_6PolicyE T
|
||||
@ -587,11 +590,11 @@ _ZThn8_N6Genode23Alarm_timeout_scheduler14handle_timeoutENS_8DurationE T
|
||||
_ZThn8_N6Genode23Alarm_timeout_schedulerD0Ev T
|
||||
_ZThn8_N6Genode23Alarm_timeout_schedulerD1Ev T
|
||||
_ZdlPv W
|
||||
_ZdlPvm W
|
||||
_ZdlPvPN6Genode11DeallocatorE T
|
||||
_ZdlPvPN6Genode9AllocatorE W
|
||||
_ZdlPvRN6Genode11DeallocatorE T
|
||||
_ZdlPvRN6Genode9AllocatorE W
|
||||
_ZdlPvm W
|
||||
_ZnajPN6Genode9AllocatorE T
|
||||
_ZnajRN6Genode9AllocatorE T
|
||||
_ZnamPN6Genode9AllocatorE T
|
||||
|
@ -62,6 +62,18 @@ Log &Log::log()
|
||||
}
|
||||
|
||||
|
||||
static Trace_output *trace_ptr;
|
||||
|
||||
Trace_output &Trace_output::trace_output()
|
||||
{
|
||||
if (trace_ptr)
|
||||
return *trace_ptr;
|
||||
|
||||
raw("Error: Missing call of init_log");
|
||||
sleep_forever();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Hook for support the 'fork' implementation of the noux libc backend
|
||||
*/
|
||||
@ -95,5 +107,16 @@ void Genode::init_log(Parent &parent)
|
||||
unmanaged_singleton<Buffered_log_output>(Write_fn());
|
||||
|
||||
log_ptr = unmanaged_singleton<Log>(*buffered_log_output);
|
||||
|
||||
/* enable trace back end */
|
||||
struct Write_trace_fn { void operator () (char const *s) { Thread::trace(s); } };
|
||||
|
||||
typedef Buffered_output<Log_session::MAX_STRING_LEN, Write_trace_fn>
|
||||
Buffered_trace_output;
|
||||
|
||||
static Buffered_trace_output *buffered_trace_output =
|
||||
unmanaged_singleton<Buffered_trace_output>(Write_trace_fn());
|
||||
|
||||
trace_ptr = unmanaged_singleton<Trace_output>(*buffered_trace_output);
|
||||
}
|
||||
|
||||
|
@ -59,3 +59,20 @@ void Raw::_release()
|
||||
*/
|
||||
_output().out_string("\033[0m\n");
|
||||
}
|
||||
|
||||
|
||||
void Trace_output::_acquire()
|
||||
{
|
||||
_lock.lock();
|
||||
}
|
||||
|
||||
|
||||
void Trace_output::_release()
|
||||
{
|
||||
/*
|
||||
* Add newline
|
||||
*/
|
||||
_output.out_string("\n");
|
||||
|
||||
_lock.unlock();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user