Skip to content

Commit 1f3ab9b

Browse files
tarun292facebook-github-bot
authored andcommitted
event_tracer logging inside method.cpp and program.cpp
Differential Revision: D49220572 fbshipit-source-id: 0ab9a2595697dcf6c9f38ae2851a0e3ac450e836
1 parent b6c4f41 commit 1f3ab9b

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
@@ -506,6 +506,8 @@ Result<Method> Method::load(
506506

507507
Error Method::init(executorch_flatbuffer::ExecutionPlan* s_plan) {
508508
EXECUTORCH_SCOPE_PROF("Method::init");
509+
internal::EventTracerProfileScope event_tracer_profile_scope =
510+
internal::EventTracerProfileScope(event_tracer_, "Method::init");
509511
ET_CHECK_OR_RETURN_ERROR(
510512
// Don't use !initialized() here because we also want to fail on the
511513
// InitializationFailed state.
@@ -903,6 +905,8 @@ Error Method::execute_instruction() {
903905
switch (instruction->instr_args_type()) {
904906
case executorch_flatbuffer::InstructionArguments::KernelCall: {
905907
EXECUTORCH_SCOPE_PROF("OPERATOR_CALL");
908+
internal::EventTracerProfileScope event_tracer_scope =
909+
internal::EventTracerProfileScope(event_tracer_, "OPERATOR_CALL");
906910
// TODO(T147221312): Also expose the temp allocator and tensor resizer
907911
// via the context.
908912
KernelRuntimeContext context(event_tracer_);
@@ -935,6 +939,8 @@ Error Method::execute_instruction() {
935939
} break;
936940
case executorch_flatbuffer::InstructionArguments::DelegateCall: {
937941
EXECUTORCH_SCOPE_PROF("DELEGATE_CALL");
942+
internal::EventTracerProfileScope event_tracer_profile_scope =
943+
internal::EventTracerProfileScope(event_tracer_, "DELEGATE_CALL");
938944
auto delegate_idx =
939945
instruction->instr_args_as_DelegateCall()->delegate_index();
940946
ET_CHECK_OR_RETURN_ERROR(
@@ -960,6 +966,8 @@ Error Method::execute_instruction() {
960966
} break;
961967
case executorch_flatbuffer::InstructionArguments::JumpFalseCall: {
962968
EXECUTORCH_SCOPE_PROF("JF_CALL");
969+
internal::EventTracerProfileScope event_tracer_profile_scope =
970+
internal::EventTracerProfileScope(event_tracer_, "JF_CALL");
963971
auto jf_call = instruction->instr_args_as_JumpFalseCall();
964972
bool jf_result = parse_cond_value(values_[jf_call->cond_value_index()]);
965973
if (!jf_result) {
@@ -969,11 +977,15 @@ Error Method::execute_instruction() {
969977
} break;
970978
case executorch_flatbuffer::InstructionArguments::MoveCall: {
971979
EXECUTORCH_SCOPE_PROF("MOVE_CALL");
980+
internal::EventTracerProfileScope event_tracer_profile_scope =
981+
internal::EventTracerProfileScope(event_tracer_, "MOVE_CALL");
972982
auto move_call = instruction->instr_args_as_MoveCall();
973983
mutable_value(move_call->move_to()) = get_value(move_call->move_from());
974984
} break;
975985
case executorch_flatbuffer::InstructionArguments::FreeCall: {
976986
EXECUTORCH_SCOPE_PROF("FREE_CALL");
987+
internal::EventTracerProfileScope event_tracer_profile_scope =
988+
internal::EventTracerProfileScope(event_tracer_, "FREE_CALL");
977989
auto free_call = instruction->instr_args_as_FreeCall();
978990
auto t = values_[free_call->value_index()].toTensor();
979991
internal::reset_data_ptr(t);
@@ -1001,7 +1013,14 @@ Error Method::experimental_step() {
10011013
EXECUTORCH_PROFILE_INSTRUCTION_SCOPE(
10021014
static_cast<int32_t>(step_state_.chain_idx),
10031015
static_cast<uint32_t>(step_state_.instr_idx));
1016+
internal::EventTracerProfileInstructionScope event_tracer_instr_scope =
1017+
internal::EventTracerProfileInstructionScope(
1018+
event_tracer_,
1019+
static_cast<int32_t>(step_state_.chain_idx),
1020+
static_cast<uint32_t>(step_state_.instr_idx));
10041021
EXECUTORCH_SCOPE_PROF("Method::step");
1022+
internal::EventTracerProfileScope event_tracer_profile_scope =
1023+
internal::EventTracerProfileScope(event_tracer_, "Method::step");
10051024
ET_CHECK_OR_RETURN_ERROR(
10061025
initialized(),
10071026
InvalidState,
@@ -1036,6 +1055,9 @@ Error Method::experimental_step() {
10361055
}
10371056

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