Skip to content

Commit ab471a7

Browse files
cccclaiYIWENX14
authored andcommitted
Add event tracer for backend init (#7575)
Add event tracer for backend init (#7575) Summary: Per request, backend would like to track model loading time Reviewed By: tarun292, dbort Differential Revision: D67987445
1 parent af1d707 commit ab471a7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

runtime/backend/backend_init_context.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class BackendInitContext final {
2020
public:
2121
explicit BackendInitContext(
2222
MemoryAllocator* runtime_allocator,
23+
EventTracer* event_tracer = nullptr,
2324
const char* method_name = nullptr)
2425
: runtime_allocator_(runtime_allocator), method_name_(method_name) {}
2526

@@ -31,6 +32,15 @@ class BackendInitContext final {
3132
return runtime_allocator_;
3233
}
3334

35+
/**
36+
* Returns a pointer (null if not installed) to an instance of EventTracer to
37+
* do profiling/debugging logging inside the delegate backend. Users will need
38+
* access to this pointer to use any of the event tracer APIs.
39+
*/
40+
EventTracer* event_tracer() {
41+
return event_tracer_;
42+
}
43+
3444
/** Get the loaded method name from ExecuTorch runtime. Usually it's
3545
* "forward", however, if there are multiple methods in the .pte file, it can
3646
* be different. One example is that we may have prefill and decode methods in
@@ -44,6 +54,7 @@ class BackendInitContext final {
4454

4555
private:
4656
MemoryAllocator* runtime_allocator_ = nullptr;
57+
EventTracer* event_tracer_ = nullptr;
4758
const char* method_name_ = nullptr;
4859
};
4960

runtime/executor/method.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
628628
const auto& delegate = *delegates->Get(i);
629629
BackendInitContext backend_init_context(
630630
method_allocator,
631+
/*event_tracer=*/event_tracer_,
631632
/*method_name=*/serialization_plan_->name()->c_str());
632633
Error err = BackendDelegate::Init(
633634
delegate, program_, backend_init_context, &delegates_[i]);

0 commit comments

Comments
 (0)