13
13
#include < cstdio>
14
14
15
15
#include < executorch/runtime/backend/interface.h>
16
+ #include < executorch/runtime/core/event_tracer_hooks.h>
16
17
#include < executorch/runtime/core/exec_aten/util/dim_order_util.h>
17
18
#include < executorch/runtime/core/exec_aten/util/scalar_type_util.h>
18
19
#include < executorch/runtime/core/exec_aten/util/tensor_util.h>
@@ -506,6 +507,8 @@ Result<Method> Method::load(
506
507
507
508
Error Method::init (executorch_flatbuffer::ExecutionPlan* s_plan) {
508
509
EXECUTORCH_SCOPE_PROF (" Method::init" );
510
+ internal::EventTracerProfileScope event_tracer_profile_scope =
511
+ internal::EventTracerProfileScope (event_tracer_, " Method::init" );
509
512
ET_CHECK_OR_RETURN_ERROR (
510
513
// Don't use !initialized() here because we also want to fail on the
511
514
// InitializationFailed state.
@@ -903,6 +906,8 @@ Error Method::execute_instruction() {
903
906
switch (instruction->instr_args_type ()) {
904
907
case executorch_flatbuffer::InstructionArguments::KernelCall: {
905
908
EXECUTORCH_SCOPE_PROF (" OPERATOR_CALL" );
909
+ internal::EventTracerProfileScope event_tracer_scope =
910
+ internal::EventTracerProfileScope (event_tracer_, " OPERATOR_CALL" );
906
911
// TODO(T147221312): Also expose the temp allocator and tensor resizer
907
912
// via the context.
908
913
KernelRuntimeContext context (event_tracer_);
@@ -935,6 +940,8 @@ Error Method::execute_instruction() {
935
940
} break ;
936
941
case executorch_flatbuffer::InstructionArguments::DelegateCall: {
937
942
EXECUTORCH_SCOPE_PROF (" DELEGATE_CALL" );
943
+ internal::EventTracerProfileScope event_tracer_profile_scope =
944
+ internal::EventTracerProfileScope (event_tracer_, " DELEGATE_CALL" );
938
945
auto delegate_idx =
939
946
instruction->instr_args_as_DelegateCall ()->delegate_index ();
940
947
ET_CHECK_OR_RETURN_ERROR (
@@ -960,6 +967,8 @@ Error Method::execute_instruction() {
960
967
} break ;
961
968
case executorch_flatbuffer::InstructionArguments::JumpFalseCall: {
962
969
EXECUTORCH_SCOPE_PROF (" JF_CALL" );
970
+ internal::EventTracerProfileScope event_tracer_profile_scope =
971
+ internal::EventTracerProfileScope (event_tracer_, " JF_CALL" );
963
972
auto jf_call = instruction->instr_args_as_JumpFalseCall ();
964
973
bool jf_result = parse_cond_value (values_[jf_call->cond_value_index ()]);
965
974
if (!jf_result) {
@@ -969,11 +978,15 @@ Error Method::execute_instruction() {
969
978
} break ;
970
979
case executorch_flatbuffer::InstructionArguments::MoveCall: {
971
980
EXECUTORCH_SCOPE_PROF (" MOVE_CALL" );
981
+ internal::EventTracerProfileScope event_tracer_profile_scope =
982
+ internal::EventTracerProfileScope (event_tracer_, " MOVE_CALL" );
972
983
auto move_call = instruction->instr_args_as_MoveCall ();
973
984
mutable_value (move_call->move_to ()) = get_value (move_call->move_from ());
974
985
} break ;
975
986
case executorch_flatbuffer::InstructionArguments::FreeCall: {
976
987
EXECUTORCH_SCOPE_PROF (" FREE_CALL" );
988
+ internal::EventTracerProfileScope event_tracer_profile_scope =
989
+ internal::EventTracerProfileScope (event_tracer_, " FREE_CALL" );
977
990
auto free_call = instruction->instr_args_as_FreeCall ();
978
991
auto t = values_[free_call->value_index ()].toTensor ();
979
992
internal::reset_data_ptr (t);
@@ -1001,7 +1014,14 @@ Error Method::experimental_step() {
1001
1014
EXECUTORCH_PROFILE_INSTRUCTION_SCOPE (
1002
1015
static_cast <int32_t >(step_state_.chain_idx ),
1003
1016
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 ));
1004
1022
EXECUTORCH_SCOPE_PROF (" Method::step" );
1023
+ internal::EventTracerProfileScope event_tracer_profile_scope =
1024
+ internal::EventTracerProfileScope (event_tracer_, " Method::step" );
1005
1025
ET_CHECK_OR_RETURN_ERROR (
1006
1026
initialized (),
1007
1027
InvalidState,
@@ -1036,6 +1056,9 @@ Error Method::experimental_step() {
1036
1056
}
1037
1057
1038
1058
Error 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" );
1039
1062
EXECUTORCH_SCOPE_PROF (" Method::execute" );
1040
1063
ET_CHECK_OR_RETURN_ERROR (
1041
1064
initialized (),
@@ -1060,6 +1083,11 @@ Error Method::execute() {
1060
1083
EXECUTORCH_PROFILE_INSTRUCTION_SCOPE (
1061
1084
static_cast <int32_t >(step_state_.chain_idx ),
1062
1085
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 ));
1063
1091
auto status = execute_instruction ();
1064
1092
if (status != Error::Ok) {
1065
1093
return status;
0 commit comments