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 #include "util/EventCollectorGlobal.h"
23 #include "util/ConfigSource.h"
30 EventCollectorGlobal::EventCollectorGlobal() : _recorder{}, _collector{&_recorder}
35 EventCollectorGlobal::~EventCollectorGlobal()
37 if (!_recorder.empty())
41 // TODO Need better way for saved file path than the hardcoded path
42 std::ofstream ofs{"trace.global.json"};
43 _recorder.writeToFile(ofs);
45 catch (const std::exception &e)
47 std::cerr << "E: Fail to record event in EventCollectorGlobal: " << e.what() << std::endl;
52 EventCollectorGlobal &EventCollectorGlobal::get()
54 static EventCollectorGlobal instance;
58 EventDurationBlock::EventDurationBlock(const std::string &tag) : _tag{tag}
60 auto &glob = EventCollectorGlobal::get();
61 glob.collector().onEvent(EventCollector::Event{EventCollector::Edge::BEGIN, "0", _tag});
63 EventDurationBlock::~EventDurationBlock()
65 auto &glob = EventCollectorGlobal::get();
66 glob.collector().onEvent(EventCollector::Event{EventCollector::Edge::END, "0", _tag});
69 EventDurationManual::EventDurationManual(const std::string &tag) : _tag{tag}, _pair{true} {}
71 EventDurationManual::~EventDurationManual()
73 // Check if it has called begin-end pair
77 void EventDurationManual::begin()
80 auto &glob = EventCollectorGlobal::get();
81 glob.collector().onEvent(EventCollector::Event{EventCollector::Edge::BEGIN, "0", _tag});
84 void EventDurationManual::end()
88 auto &glob = EventCollectorGlobal::get();
89 glob.collector().onEvent(EventCollector::Event{EventCollector::Edge::END, "0", _tag});