From e54ff599ca9d41cb3e4ac00bff8c8ba54d287ee7 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Fri, 6 Dec 2019 17:26:01 +0100 Subject: [PATCH] base-hw: trace execution time of core threads Fixes #3572 --- repos/base-hw/src/core/thread_start.cc | 39 +++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/repos/base-hw/src/core/thread_start.cc b/repos/base-hw/src/core/thread_start.cc index cf7cc38c6..ffe974987 100644 --- a/repos/base-hw/src/core/thread_start.cc +++ b/repos/base-hw/src/core/thread_start.cc @@ -26,6 +26,7 @@ #include #include #include +#include using namespace Genode; @@ -35,8 +36,44 @@ namespace Hw { extern Untyped_capability _main_thread_cap; } void Thread::start() { /* start thread with stack pointer at the top of stack */ - if (native_thread().platform_thread->start((void *)&_thread_start, stack_top())) + if (native_thread().platform_thread->start((void *)&_thread_start, stack_top())) { error("failed to start thread"); + return; + } + + struct Trace_source : public Trace::Source::Info_accessor, + private Trace::Control, + private Trace::Source + { + Genode::Thread &thread; + + /** + * Trace::Source::Info_accessor interface + */ + Info trace_source_info() const override + { + Platform_thread * t = thread.native_thread().platform_thread; + + Trace::Execution_time execution_time { 0, 0 }; + if (t) + execution_time = t->execution_time(); + + return { Session_label("core"), thread.name(), + execution_time, thread.affinity() }; + } + + Trace_source(Trace::Source_registry ®istry, Genode::Thread &thread) + : + Trace::Control(), + Trace::Source(*this, *this), + thread(thread) + { + registry.insert(this); + } + }; + + /* create trace sources for core threads */ + new (platform().core_mem_alloc()) Trace_source(Trace::sources(), *this); }