Skip to content

Commit 41966b9

Browse files
tarun292facebook-github-bot
authored andcommitted
event_tracer logging inside method.cpp and program.cpp (#346)
Summary: Pull Request resolved: #346 Adding event_tracer logging inside method.cpp and program.cpp. Similar to D48975975 calls to both `internal::ET_EVENT_TRACER_SCOPE_PROF` and `EXECUTORCH_SCOPE_PROF` are present in `method.cpp` and `program.cpp`. Calls to `event_tracer_*` are a no-op for now and `EXECUTORCH_SCOPE_PROF` will be deprecated soon. Reviewed By: dbort Differential Revision: D49220572 fbshipit-source-id: a4bca44664b6608e93fac04a7bc4ab71696cd8ff
1 parent 4c2ef09 commit 41966b9

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

runtime/executor/method.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ Result<Method> Method::load(
505505

506506
Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
507507
EXECUTORCH_SCOPE_PROF("Method::init");
508+
internal::EventTracerProfileScope event_tracer_profile_scope =
509+
internal::EventTracerProfileScope(event_tracer_, "Method::init");
508510
ET_CHECK_OR_RETURN_ERROR(
509511
// Don't use !initialized() here because we also want to fail on the
510512
// InitializationFailed state.
@@ -902,6 +904,8 @@ Error Method::execute_instruction() {
902904
switch (instruction->instr_args_type()) {
903905
case executorch_flatbuffer::InstructionArguments::KernelCall: {
904906
EXECUTORCH_SCOPE_PROF("OPERATOR_CALL");
907+
internal::EventTracerProfileScope event_tracer_scope =
908+
internal::EventTracerProfileScope(event_tracer_, "OPERATOR_CALL");
905909
// TODO(T147221312): Also expose the temp allocator and tensor resizer
906910
// via the context.
907911
KernelRuntimeContext context(event_tracer_);
@@ -934,6 +938,8 @@ Error Method::execute_instruction() {
934938
} break;
935939
case executorch_flatbuffer::InstructionArguments::DelegateCall: {
936940
EXECUTORCH_SCOPE_PROF("DELEGATE_CALL");
941+
internal::EventTracerProfileScope event_tracer_profile_scope =
942+
internal::EventTracerProfileScope(event_tracer_, "DELEGATE_CALL");
937943
auto delegate_idx =
938944
instruction->instr_args_as_DelegateCall()->delegate_index();
939945
ET_CHECK_OR_RETURN_ERROR(
@@ -956,6 +962,8 @@ Error Method::execute_instruction() {
956962
} break;
957963
case executorch_flatbuffer::InstructionArguments::JumpFalseCall: {
958964
EXECUTORCH_SCOPE_PROF("JF_CALL");
965+
internal::EventTracerProfileScope event_tracer_profile_scope =
966+
internal::EventTracerProfileScope(event_tracer_, "JF_CALL");
959967
auto jf_call = instruction->instr_args_as_JumpFalseCall();
960968
bool jf_result = parse_cond_value(values_[jf_call->cond_value_index()]);
961969
if (!jf_result) {
@@ -965,11 +973,15 @@ Error Method::execute_instruction() {
965973
} break;
966974
case executorch_flatbuffer::InstructionArguments::MoveCall: {
967975
EXECUTORCH_SCOPE_PROF("MOVE_CALL");
976+
internal::EventTracerProfileScope event_tracer_profile_scope =
977+
internal::EventTracerProfileScope(event_tracer_, "MOVE_CALL");
968978
auto move_call = instruction->instr_args_as_MoveCall();
969979
mutable_value(move_call->move_to()) = get_value(move_call->move_from());
970980
} break;
971981
case executorch_flatbuffer::InstructionArguments::FreeCall: {
972982
EXECUTORCH_SCOPE_PROF("FREE_CALL");
983+
internal::EventTracerProfileScope event_tracer_profile_scope =
984+
internal::EventTracerProfileScope(event_tracer_, "FREE_CALL");
973985
auto free_call = instruction->instr_args_as_FreeCall();
974986
auto t = values_[free_call->value_index()].toTensor();
975987
internal::reset_data_ptr(t);
@@ -997,7 +1009,14 @@ Error Method::experimental_step() {
9971009
EXECUTORCH_PROFILE_INSTRUCTION_SCOPE(
9981010
static_cast<int32_t>(step_state_.chain_idx),
9991011
static_cast<uint32_t>(step_state_.instr_idx));
1012+
internal::EventTracerProfileInstructionScope event_tracer_instr_scope =
1013+
internal::EventTracerProfileInstructionScope(
1014+
event_tracer_,
1015+
static_cast<int32_t>(step_state_.chain_idx),
1016+
static_cast<uint32_t>(step_state_.instr_idx));
10001017
EXECUTORCH_SCOPE_PROF("Method::step");
1018+
internal::EventTracerProfileScope event_tracer_profile_scope =
1019+
internal::EventTracerProfileScope(event_tracer_, "Method::step");
10011020
ET_CHECK_OR_RETURN_ERROR(
10021021
initialized(),
10031022
InvalidState,
@@ -1032,6 +1051,9 @@ Error Method::experimental_step() {
10321051
}
10331052

10341053
Error Method::execute() {
1054+
internal::event_tracer_create_event_block(event_tracer_, "Execute");
1055+
internal::EventTracerProfileScope event_tracer_profile_scope =
1056+
internal::EventTracerProfileScope(event_tracer_, "Method::execute");
10351057
EXECUTORCH_SCOPE_PROF("Method::execute");
10361058
ET_CHECK_OR_RETURN_ERROR(
10371059
initialized(),
@@ -1056,6 +1078,11 @@ Error Method::execute() {
10561078
EXECUTORCH_PROFILE_INSTRUCTION_SCOPE(
10571079
static_cast<int32_t>(step_state_.chain_idx),
10581080
static_cast<uint32_t>(step_state_.instr_idx));
1081+
internal::EventTracerProfileInstructionScope event_tracer_instr_scope =
1082+
internal::EventTracerProfileInstructionScope(
1083+
event_tracer_,
1084+
static_cast<ChainID>(step_state_.chain_idx),
1085+
static_cast<DebugHandle>(step_state_.instr_idx));
10591086
auto status = execute_instruction();
10601087
if (status != Error::Ok) {
10611088
return status;

runtime/executor/program.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <cstddef>
1212
#include <cstdint>
1313

14+
#include <executorch/runtime/core/event_tracer_hooks.h>
1415
#include <executorch/runtime/executor/memory_manager.h>
1516
#include <executorch/runtime/executor/method.h>
1617
#include <executorch/runtime/platform/profiler.h>
@@ -170,6 +171,9 @@ Result<Method> Program::load_method(
170171
MemoryManager* memory_manager,
171172
EventTracer* event_tracer) const {
172173
EXECUTORCH_SCOPE_PROF("Program::load_method");
174+
internal::event_tracer_create_event_block(event_tracer, "Default");
175+
internal::EventTracerProfileScope event_tracer_scope =
176+
internal::EventTracerProfileScope(event_tracer, "Program::load_method");
173177
auto plan = get_execution_plan(internal_program_, method_name);
174178
if (!plan.ok()) {
175179
return plan.error();

0 commit comments

Comments
 (0)