1313#include < cstdio>
1414
1515#include < executorch/runtime/backend/interface.h>
16+ #include < executorch/runtime/core/event_tracer_hooks.h>
1617#include < executorch/runtime/core/exec_aten/util/dim_order_util.h>
1718#include < executorch/runtime/core/exec_aten/util/scalar_type_util.h>
1819#include < executorch/runtime/core/exec_aten/util/tensor_util.h>
@@ -506,6 +507,8 @@ Result<Method> Method::load(
506507
507508Error Method::init (executorch_flatbuffer::ExecutionPlan* s_plan) {
508509 EXECUTORCH_SCOPE_PROF (" Method::init" );
510+ internal::EventTracerProfileScope event_tracer_profile_scope =
511+ internal::EventTracerProfileScope (event_tracer_, " Method::init" );
509512 ET_CHECK_OR_RETURN_ERROR (
510513 // Don't use !initialized() here because we also want to fail on the
511514 // InitializationFailed state.
@@ -903,6 +906,8 @@ Error Method::execute_instruction() {
903906 switch (instruction->instr_args_type ()) {
904907 case executorch_flatbuffer::InstructionArguments::KernelCall: {
905908 EXECUTORCH_SCOPE_PROF (" OPERATOR_CALL" );
909+ internal::EventTracerProfileScope event_tracer_scope =
910+ internal::EventTracerProfileScope (event_tracer_, " OPERATOR_CALL" );
906911 // TODO(T147221312): Also expose the temp allocator and tensor resizer
907912 // via the context.
908913 KernelRuntimeContext context (event_tracer_);
@@ -935,6 +940,8 @@ Error Method::execute_instruction() {
935940 } break ;
936941 case executorch_flatbuffer::InstructionArguments::DelegateCall: {
937942 EXECUTORCH_SCOPE_PROF (" DELEGATE_CALL" );
943+ internal::EventTracerProfileScope event_tracer_profile_scope =
944+ internal::EventTracerProfileScope (event_tracer_, " DELEGATE_CALL" );
938945 auto delegate_idx =
939946 instruction->instr_args_as_DelegateCall ()->delegate_index ();
940947 ET_CHECK_OR_RETURN_ERROR (
@@ -960,6 +967,8 @@ Error Method::execute_instruction() {
960967 } break ;
961968 case executorch_flatbuffer::InstructionArguments::JumpFalseCall: {
962969 EXECUTORCH_SCOPE_PROF (" JF_CALL" );
970+ internal::EventTracerProfileScope event_tracer_profile_scope =
971+ internal::EventTracerProfileScope (event_tracer_, " JF_CALL" );
963972 auto jf_call = instruction->instr_args_as_JumpFalseCall ();
964973 bool jf_result = parse_cond_value (values_[jf_call->cond_value_index ()]);
965974 if (!jf_result) {
@@ -969,11 +978,15 @@ Error Method::execute_instruction() {
969978 } break ;
970979 case executorch_flatbuffer::InstructionArguments::MoveCall: {
971980 EXECUTORCH_SCOPE_PROF (" MOVE_CALL" );
981+ internal::EventTracerProfileScope event_tracer_profile_scope =
982+ internal::EventTracerProfileScope (event_tracer_, " MOVE_CALL" );
972983 auto move_call = instruction->instr_args_as_MoveCall ();
973984 mutable_value (move_call->move_to ()) = get_value (move_call->move_from ());
974985 } break ;
975986 case executorch_flatbuffer::InstructionArguments::FreeCall: {
976987 EXECUTORCH_SCOPE_PROF (" FREE_CALL" );
988+ internal::EventTracerProfileScope event_tracer_profile_scope =
989+ internal::EventTracerProfileScope (event_tracer_, " FREE_CALL" );
977990 auto free_call = instruction->instr_args_as_FreeCall ();
978991 auto t = values_[free_call->value_index ()].toTensor ();
979992 internal::reset_data_ptr (t);
@@ -1001,7 +1014,14 @@ Error Method::experimental_step() {
10011014 EXECUTORCH_PROFILE_INSTRUCTION_SCOPE (
10021015 static_cast <int32_t >(step_state_.chain_idx ),
10031016 static_cast <uint32_t >(step_state_.instr_idx ));
1017+ internal::EventTracerProfileInstructionScope event_tracer_instr_scope =
1018+ internal::EventTracerProfileInstructionScope (
1019+ event_tracer_,
1020+ static_cast <int32_t >(step_state_.chain_idx ),
1021+ static_cast <uint32_t >(step_state_.instr_idx ));
10041022 EXECUTORCH_SCOPE_PROF (" Method::step" );
1023+ internal::EventTracerProfileScope event_tracer_profile_scope =
1024+ internal::EventTracerProfileScope (event_tracer_, " Method::step" );
10051025 ET_CHECK_OR_RETURN_ERROR (
10061026 initialized (),
10071027 InvalidState,
@@ -1036,6 +1056,9 @@ Error Method::experimental_step() {
10361056}
10371057
10381058Error Method::execute () {
1059+ internal::event_tracer_create_event_block (event_tracer_, " Execute" );
1060+ internal::EventTracerProfileScope event_tracer_profile_scope =
1061+ internal::EventTracerProfileScope (event_tracer_, " Method::execute" );
10391062 EXECUTORCH_SCOPE_PROF (" Method::execute" );
10401063 ET_CHECK_OR_RETURN_ERROR (
10411064 initialized (),
@@ -1060,6 +1083,11 @@ Error Method::execute() {
10601083 EXECUTORCH_PROFILE_INSTRUCTION_SCOPE (
10611084 static_cast <int32_t >(step_state_.chain_idx ),
10621085 static_cast <uint32_t >(step_state_.instr_idx ));
1086+ internal::EventTracerProfileInstructionScope event_tracer_instr_scope =
1087+ internal::EventTracerProfileInstructionScope (
1088+ event_tracer_,
1089+ static_cast <ChainID>(step_state_.chain_idx ),
1090+ static_cast <DebugHandle>(step_state_.instr_idx ));
10631091 auto status = execute_instruction ();
10641092 if (status != Error::Ok) {
10651093 return status;
0 commit comments