2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __ONERT_EXEC_OBSREVERS_H__
18 #define __ONERT_EXEC_OBSREVERS_H__
21 #include "../util/EventCollector.h"
22 #include "../util/EventRecorder.h"
23 #include "../util/EventWriter.h"
25 #include "exec/IExecutor.h"
27 #include "ir/Operation.h"
28 #include "util/ITimer.h"
29 #include "util/TracingCtx.h"
35 class IExecutionObserver
38 /// @brief Invoked just before model (not individual operation) execution begins
39 virtual void handleSubgraphBegin(ir::SubgraphIndex) { return; }
41 virtual void handleJobBegin(IExecutor *, ir::SubgraphIndex, ir::OperationIndex,
42 const backend::Backend *) = 0;
43 virtual void handleJobEnd(IExecutor *, ir::SubgraphIndex, ir::OperationIndex,
44 const backend::Backend *) = 0;
46 /// @brief Invoked just after model (not individual operation) execution ends
47 virtual void handleSubgraphEnd(ir::SubgraphIndex) { return; }
49 virtual ~IExecutionObserver() = default;
52 class ProfileObserver : public IExecutionObserver
55 explicit ProfileObserver(std::shared_ptr<ExecTime> et, const ir::Graph &graph)
56 : _et(std::move(et)), _graph(graph)
59 void handleJobBegin(IExecutor *, ir::SubgraphIndex, ir::OperationIndex,
60 const backend::Backend *) override;
61 void handleJobEnd(IExecutor *, ir::SubgraphIndex, ir::OperationIndex,
62 const backend::Backend *) override;
64 void handleSubgraphEnd(ir::SubgraphIndex) override { _et->storeOperationsExecTime(); }
67 std::unique_ptr<util::ITimer> _timer;
68 std::shared_ptr<ExecTime> _et;
69 const ir::Graph &_graph;
72 class TracingObserver : public IExecutionObserver
75 TracingObserver(const std::string &filepath, const ir::Graph &graph,
76 const util::TracingCtx *tracing_ctx);
78 void handleSubgraphBegin(ir::SubgraphIndex) override;
79 void handleJobBegin(IExecutor *, ir::SubgraphIndex, ir::OperationIndex,
80 const backend::Backend *) override;
81 void handleJobEnd(IExecutor *, ir::SubgraphIndex, ir::OperationIndex,
82 const backend::Backend *) override;
83 void handleSubgraphEnd(ir::SubgraphIndex) override;
86 std::unique_ptr<EventRecorder> _recorder;
87 EventCollector _collector;
88 const ir::Graph &_graph;
89 EventWriter *_event_writer;
90 const util::TracingCtx *_tracing_ctx;
96 #endif // __ONERT_EXEC_OBSREVERS_H__