Skip to content

Commit 7322f30

Browse files
Gasoonjiafacebook-github-bot
authored andcommitted
use datasink in example runner
Summary: devtool example runner plays a crital role for demonstrating devtool usage for users. This diff updates example_runner to use datasink instead of debug_buffer, to demonstrate our latest pipeline. Differential Revision: D70540227
1 parent b2bee8c commit 7322f30

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

examples/devtools/example_runner/example_runner.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <gflags/gflags.h>
2424

2525
#include <executorch/devtools/bundled_program/bundled_program.h>
26+
#include <executorch/devtools/etdump/data_sinks/buffer_data_sink.h>
2627
#include <executorch/devtools/etdump/etdump_flatcc.h>
2728
#include <executorch/extension/data_loader/buffer_data_loader.h>
2829
#include <executorch/runtime/executor/method.h>
@@ -75,6 +76,7 @@ DEFINE_int32(
7576
262144, // 256 KB
7677
"Size of the debug buffer in bytes to allocate for intermediate outputs and program outputs logging.");
7778

79+
using executorch::etdump::BufferDataSink;
7880
using executorch::etdump::ETDumpGen;
7981
using executorch::etdump::ETDumpResult;
8082
using executorch::extension::BufferDataLoader;
@@ -215,27 +217,36 @@ int main(int argc, char** argv) {
215217
// be used by a single thread at at time, but it can be reused.
216218
//
217219
ETDumpGen etdump_gen;
218-
Result<Method> method =
219-
program->load_method(method_name, &memory_manager, &etdump_gen);
220-
ET_CHECK_MSG(
221-
method.ok(),
222-
"Loading of method %s failed with status 0x%" PRIx32,
223-
method_name,
224-
static_cast<int>(method.error()));
225-
ET_LOG(Info, "Method loaded.");
226220

227221
void* debug_buffer = malloc(FLAGS_debug_buffer_size);
222+
223+
Result<BufferDataSink> data_sink_ret =
224+
BufferDataSink::create(debug_buffer, FLAGS_debug_buffer_size);
225+
ET_CHECK_MSG(
226+
data_sink_ret.ok(),
227+
"Creating Datasink for etdump failed with status 0x%" PRIx32,
228+
static_cast<int>(data_sink_ret.error()));
229+
230+
BufferDataSink* data_sink = &data_sink_ret.get();
231+
etdump_gen.set_data_sink(data_sink);
232+
228233
if (FLAGS_dump_intermediate_outputs) {
229-
Span<uint8_t> buffer((uint8_t*)debug_buffer, FLAGS_debug_buffer_size);
230-
etdump_gen.set_debug_buffer(buffer);
231234
etdump_gen.set_event_tracer_debug_level(
232235
EventTracerDebugLogLevel::kIntermediateOutputs);
233236
} else if (FLAGS_dump_outputs) {
234-
Span<uint8_t> buffer((uint8_t*)debug_buffer, FLAGS_debug_buffer_size);
235-
etdump_gen.set_debug_buffer(buffer);
236237
etdump_gen.set_event_tracer_debug_level(
237238
EventTracerDebugLogLevel::kProgramOutputs);
238239
}
240+
241+
Result<Method> method =
242+
program->load_method(method_name, &memory_manager, &etdump_gen);
243+
ET_CHECK_MSG(
244+
method.ok(),
245+
"Loading of method %s failed with status 0x%" PRIx32,
246+
method_name,
247+
static_cast<int>(method.error()));
248+
ET_LOG(Info, "Method loaded.");
249+
239250
// Use the inputs embedded in the bundled program.
240251
status = executorch::bundled_program::load_bundled_input(
241252
*method, file_data.data(), FLAGS_testset_idx);

0 commit comments

Comments
 (0)