diff --git a/runtime/onert/core/src/exec/ExecutionObservers.cc b/runtime/onert/core/src/exec/ExecutionObservers.cc index ee71ebf2c8f..a58daeabdc0 100644 --- a/runtime/onert/core/src/exec/ExecutionObservers.cc +++ b/runtime/onert/core/src/exec/ExecutionObservers.cc @@ -116,17 +116,22 @@ void ProfileObserver::handleJobEnd(IExecutor *exec, ir::SubgraphIndex, TracingObserver::TracingObserver(const std::string &workspace_dir, const ir::Graph &graph, const util::TracingCtx *tracing_ctx) : _recorder{std::make_unique()}, _collector{_recorder.get()}, _graph{graph}, - _tracing_ctx{tracing_ctx} + _workspace_dir{workspace_dir}, _tracing_ctx{tracing_ctx}, _triggered{false} { - _event_writer = EventWriter::get(workspace_dir); - _event_writer->startToUse(); + // DO NOTHING } TracingObserver::~TracingObserver() { try { - _event_writer->readyToFlush(std::move(_recorder)); + // Write file if this observer is triggered at least once + if (_triggered) + { + auto event_writer = EventWriter::get(_workspace_dir); + event_writer->startToUse(); + event_writer->readyToFlush(std::move(_recorder)); + } } catch (const std::exception &e) { @@ -136,6 +141,8 @@ TracingObserver::~TracingObserver() void TracingObserver::handleSubgraphBegin(ir::SubgraphIndex subg_ind) { + _triggered = true; + _collector.onEvent( EventCollector::SubgEvent{_tracing_ctx, EventCollector::Edge::BEGIN, subg_ind.value()}); } diff --git a/runtime/onert/core/src/exec/ExecutionObservers.h b/runtime/onert/core/src/exec/ExecutionObservers.h index a02e2d5f33e..f0f3420db02 100644 --- a/runtime/onert/core/src/exec/ExecutionObservers.h +++ b/runtime/onert/core/src/exec/ExecutionObservers.h @@ -86,8 +86,9 @@ class TracingObserver : public IExecutionObserver std::unique_ptr _recorder; EventCollector _collector; const ir::Graph &_graph; - EventWriter *_event_writer; + std::string _workspace_dir; const util::TracingCtx *_tracing_ctx; + bool _triggered; }; } // namespace exec