Skip to content

Commit c19b58f

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: 626246470b40e8eebaf0b9ab9aad61d0835f90de
1 parent 57c328c commit c19b58f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

runtime/executor/method.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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

507508
Error 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

10381058
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");
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;

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)