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"
21 #include "ir/OpSequence.h"
23 #include "util/ITimer.h"
24 #include "exec/IExecutor.h"
25 #include "util/EventCollector.h"
26 #include "util/EventRecorder.h"
32 class IExecutionObserver
35 /// @brief Invoked just before model (not individual operation) execution begins
36 virtual void handleBegin(IExecutor *) { return; }
38 virtual void handleBegin(IExecutor *, const ir::OpSequence *, const backend::Backend *) = 0;
39 virtual void handleEnd(IExecutor *, const ir::OpSequence *, const backend::Backend *) = 0;
41 /// @brief Invoked just after model (not individual operation) execution ends
42 virtual void handleEnd(IExecutor *) { return; }
44 virtual ~IExecutionObserver() = default;
47 class ProfileObserver : public IExecutionObserver
50 explicit ProfileObserver(std::shared_ptr<ExecTime> et, const ir::Graph &graph)
51 : _et(std::move(et)), _graph(graph)
54 void handleBegin(IExecutor *, const ir::OpSequence *, const backend::Backend *) override;
55 void handleEnd(IExecutor *, const ir::OpSequence *, const backend::Backend *) override;
57 void handleEnd(IExecutor *) override { _et->uploadOperationsExecTime(); }
60 std::unique_ptr<util::ITimer> _timer;
61 std::shared_ptr<ExecTime> _et;
62 const ir::Graph &_graph;
65 class ChromeTracingObserver : public IExecutionObserver
68 ChromeTracingObserver(const std::string &filepath, const ir::Graph &graph);
69 ~ChromeTracingObserver();
70 void handleBegin(IExecutor *) override;
71 void handleBegin(IExecutor *, const ir::OpSequence *, const backend::Backend *) override;
72 void handleEnd(IExecutor *, const ir::OpSequence *, const backend::Backend *) override;
73 void handleEnd(IExecutor *) override;
76 static std::string opSequenceTag(const ir::OpSequence *op_seq, const ir::Operations &operations);
80 EventRecorder _recorder;
81 EventCollector _collector;
82 const ir::Graph &_graph;
88 #endif // __ONERT_EXEC_OBSREVERS_H__