diff --git a/runtime/backend/backend_init_context.h b/runtime/backend/backend_init_context.h index 051266662c..49bf4adbf9 100644 --- a/runtime/backend/backend_init_context.h +++ b/runtime/backend/backend_init_context.h @@ -20,6 +20,7 @@ class BackendInitContext final { public: explicit BackendInitContext( MemoryAllocator* runtime_allocator, + EventTracer* event_tracer = nullptr, const char* method_name = nullptr) : runtime_allocator_(runtime_allocator), method_name_(method_name) {} @@ -31,6 +32,15 @@ class BackendInitContext final { return runtime_allocator_; } + /** + * Returns a pointer (null if not installed) to an instance of EventTracer to + * do profiling/debugging logging inside the delegate backend. Users will need + * access to this pointer to use any of the event tracer APIs. + */ + EventTracer* event_tracer() { + return event_tracer_; + } + /** Get the loaded method name from ExecuTorch runtime. Usually it's * "forward", however, if there are multiple methods in the .pte file, it can * be different. One example is that we may have prefill and decode methods in @@ -44,6 +54,7 @@ class BackendInitContext final { private: MemoryAllocator* runtime_allocator_ = nullptr; + EventTracer* event_tracer_ = nullptr; const char* method_name_ = nullptr; }; diff --git a/runtime/executor/method.cpp b/runtime/executor/method.cpp index 90d4c71953..db9417dd88 100644 --- a/runtime/executor/method.cpp +++ b/runtime/executor/method.cpp @@ -628,6 +628,7 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) { const auto& delegate = *delegates->Get(i); BackendInitContext backend_init_context( method_allocator, + /*event_tracer=*/event_tracer_, /*method_name=*/serialization_plan_->name()->c_str()); Error err = BackendDelegate::Init( delegate, program_, backend_init_context, &delegates_[i]);