Skip to content

Commit 68bcfab

Browse files
tarun292facebook-github-bot
authored andcommitted
event_tracer logging inside method.cpp and program.cpp
Differential Revision: D49220572 fbshipit-source-id: 3f09d07d49bebee0c4aa41ad8d3e9e831a2c66b5
1 parent 6953934 commit 68bcfab

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(
@@ -959,6 +965,8 @@ Error Method::execute_instruction() {
959965
} break;
960966
case executorch_flatbuffer::InstructionArguments::JumpFalseCall: {
961967
EXECUTORCH_SCOPE_PROF("JF_CALL");
968+
internal::EventTracerProfileScope event_tracer_profile_scope =
969+
internal::EventTracerProfileScope(event_tracer_, "JF_CALL");
962970
auto jf_call = instruction->instr_args_as_JumpFalseCall();
963971
bool jf_result = parse_cond_value(values_[jf_call->cond_value_index()]);
964972
if (!jf_result) {
@@ -968,11 +976,15 @@ Error Method::execute_instruction() {
968976
} break;
969977
case executorch_flatbuffer::InstructionArguments::MoveCall: {
970978
EXECUTORCH_SCOPE_PROF("MOVE_CALL");
979+
internal::EventTracerProfileScope event_tracer_profile_scope =
980+
internal::EventTracerProfileScope(event_tracer_, "MOVE_CALL");
971981
auto move_call = instruction->instr_args_as_MoveCall();
972982
mutable_value(move_call->move_to()) = get_value(move_call->move_from());
973983
} break;
974984
case executorch_flatbuffer::InstructionArguments::FreeCall: {
975985
EXECUTORCH_SCOPE_PROF("FREE_CALL");
986+
internal::EventTracerProfileScope event_tracer_profile_scope =
987+
internal::EventTracerProfileScope(event_tracer_, "FREE_CALL");
976988
auto free_call = instruction->instr_args_as_FreeCall();
977989
auto t = values_[free_call->value_index()].toTensor();
978990
internal::reset_data_ptr(t);
@@ -1000,7 +1012,14 @@ Error Method::experimental_step() {
10001012
EXECUTORCH_PROFILE_INSTRUCTION_SCOPE(
10011013
static_cast<int32_t>(step_state_.chain_idx),
10021014
static_cast<uint32_t>(step_state_.instr_idx));
1015+
internal::EventTracerProfileInstructionScope event_tracer_instr_scope =
1016+
internal::EventTracerProfileInstructionScope(
1017+
event_tracer_,
1018+
static_cast<int32_t>(step_state_.chain_idx),
1019+
static_cast<uint32_t>(step_state_.instr_idx));
10031020
EXECUTORCH_SCOPE_PROF("Method::step");
1021+
internal::EventTracerProfileScope event_tracer_profile_scope =
1022+
internal::EventTracerProfileScope(event_tracer_, "Method::step");
10041023
ET_CHECK_OR_RETURN_ERROR(
10051024
initialized(),
10061025
InvalidState,
@@ -1035,6 +1054,9 @@ Error Method::experimental_step() {
10351054
}
10361055

10371056
Error Method::execute() {
1057+
internal::event_tracer_create_event_block(event_tracer_, "Execute");
1058+
internal::EventTracerProfileScope event_tracer_profile_scope =
1059+
internal::EventTracerProfileScope(event_tracer_, "Method::execute");
10381060
EXECUTORCH_SCOPE_PROF("Method::execute");
10391061
ET_CHECK_OR_RETURN_ERROR(
10401062
initialized(),
@@ -1059,6 +1081,11 @@ Error Method::execute() {
10591081
EXECUTORCH_PROFILE_INSTRUCTION_SCOPE(
10601082
static_cast<int32_t>(step_state_.chain_idx),
10611083
static_cast<uint32_t>(step_state_.instr_idx));
1084+
internal::EventTracerProfileInstructionScope event_tracer_instr_scope =
1085+
internal::EventTracerProfileInstructionScope(
1086+
event_tracer_,
1087+
static_cast<ChainID>(step_state_.chain_idx),
1088+
static_cast<DebugHandle>(step_state_.instr_idx));
10621089
auto status = execute_instruction();
10631090
if (status != Error::Ok) {
10641091
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)