From b11d6be71e3d0c65328c20ff76cf69924b81e356 Mon Sep 17 00:00:00 2001 From: Hyeongseok Oh Date: Thu, 13 Jun 2024 11:53:32 +0900 Subject: [PATCH] [onert] Change TracingObserver writing policy (#13151) This commit updates TracingObserver to write file when observer is used at least once. ONE-DCO-1.0-Signed-off-by: Hyeongseok Oh --- runtime/onert/core/src/exec/ExecutionObservers.cc | 15 +++++++++++---- runtime/onert/core/src/exec/ExecutionObservers.h | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) 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