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_UTIL_EVENT_COLLECTOR_GLOBAL_H__
18 #define __ONERT_UTIL_EVENT_COLLECTOR_GLOBAL_H__
20 #include "util/EventRecorder.h"
21 #include "util/EventCollector.h"
29 * @brief Singleton class for event collection from anywhere in code
32 class EventCollectorGlobal
36 * @brief Get the singleton object of this class
38 * @return EventCollectorGlobal& Singleton object
40 static EventCollectorGlobal &get();
44 * @brief Getter for event collector object
46 * @return EventCollector& Collector object
48 EventCollector &collector() { return _collector; }
51 EventCollectorGlobal();
52 ~EventCollectorGlobal();
55 EventRecorder _recorder;
56 EventCollector _collector;
60 * @brief Helper class for emitting duration event which is handled automatically with ctor/dtor
63 class EventDurationBlock
67 * @brief Raise a duration event with type of BEGIN
69 * @param tag A label for the duration event
71 EventDurationBlock(const std::string &tag);
73 * @brief Raise a duration event with type of END
76 ~EventDurationBlock();
83 * @brief Helper class for emitting duration event which is handled manually
88 * EventDurationManual duration("some tag");
91 * ... // Code for duration
97 class EventDurationManual
101 * @brief Construct a new Event Duration Manual object
103 * @param tag A label for the duration object
105 EventDurationManual(const std::string &tag);
107 * @brief Destroy the Event Duration Manual object
110 ~EventDurationManual();
113 * @brief Raise a duration event with type of BEGIN
118 * @brief Raise a duration event with type of END
132 * Helper Macro Definitions
138 * EVENT_DURATION_FUNCTION();
142 * EVENT_DURATION_REGION("if branch");
149 #define EVENT_DURATION_FUNCTION() \
150 ::onert::util::EventDurationBlock __event_duration__##__LINE__ { __FUNCTION__ }
152 #define EVENT_DURATION_REGION(tag) \
153 ::onert::util::EventDurationBlock __event_duration__##__LINE__ { tag }
155 #endif // __ONERT_UTIL_EVENT_COLLECTOR_GLOBAL_H__