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__
20 #include "exec/IFunction.h"
22 #include "ir/OpSequence.h"
24 #include "util/ITimer.h"
25 #include "exec/IExecutor.h"
26 #include "util/EventCollector.h"
27 #include "util/EventRecorder.h"
28 #include "util/EventWriter.h"
29 #include "util/TracingCtx.h"
30 #include "util/EventWriter.h"
36 class IExecutionObserver
39 /// @brief Invoked just before model (not individual operation) execution begins
40 virtual void handleSubgraphBegin(ir::SubgraphIndex) { return; }
42 virtual void handleJobBegin(IExecutor *, ir::SubgraphIndex, const ir::OpSequence *,
43 const backend::Backend *) = 0;
44 virtual void handleJobEnd(IExecutor *, ir::SubgraphIndex, const ir::OpSequence *,
45 const backend::Backend *) = 0;
47 /// @brief Invoked just after model (not individual operation) execution ends
48 virtual void handleSubgraphEnd(ir::SubgraphIndex) { return; }
50 virtual ~IExecutionObserver() = default;
53 class ProfileObserver : public IExecutionObserver
56 explicit ProfileObserver(std::shared_ptr<ExecTime> et, const ir::Graph &graph)
57 : _et(std::move(et)), _graph(graph)
60 void handleJobBegin(IExecutor *, ir::SubgraphIndex, const ir::OpSequence *,
61 const backend::Backend *) override;
62 void handleJobEnd(IExecutor *, ir::SubgraphIndex, const ir::OpSequence *,
63 const backend::Backend *) override;
65 void handleSubgraphEnd(ir::SubgraphIndex) override { _et->storeOperationsExecTime(); }
68 std::unique_ptr<util::ITimer> _timer;
69 std::shared_ptr<ExecTime> _et;
70 const ir::Graph &_graph;
73 class TracingObserver : public IExecutionObserver
76 TracingObserver(const std::string &filepath, const ir::Graph &graph,
77 const util::TracingCtx *tracing_ctx);
79 void handleSubgraphBegin(ir::SubgraphIndex) override;
80 void handleJobBegin(IExecutor *, ir::SubgraphIndex, const ir::OpSequence *,
81 const backend::Backend *) override;
82 void handleJobEnd(IExecutor *, ir::SubgraphIndex, const ir::OpSequence *,
83 const backend::Backend *) override;
84 void handleSubgraphEnd(ir::SubgraphIndex) override;
87 static std::string opSequenceTag(const ir::OpSequence *op_seq, const ir::Operations &operations);
90 std::unique_ptr<EventRecorder> _recorder;
91 EventCollector _collector;
92 const ir::Graph &_graph;
93 EventWriter *_event_writer;
94 const util::TracingCtx *_tracing_ctx;
100 #endif // __ONERT_EXEC_OBSREVERS_H__