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"
24 #include "util/EventWriter.h"
31 EventCollectorGlobal::EventCollectorGlobal() : _recorder{}, _collector{&_recorder}
36 EventCollectorGlobal::~EventCollectorGlobal()
38 if (!_recorder.empty())
42 // TODO Need better way for saved file path than the hardcoded path
43 EventWriter{_recorder}.writeToFile("trace.global.json",
44 EventWriter::WriteFormat::CHROME_TRACING);
46 catch (const std::exception &e)
48 std::cerr << "E: Fail to record event in EventCollectorGlobal: " << e.what() << std::endl;
53 EventCollectorGlobal &EventCollectorGlobal::get()
55 static EventCollectorGlobal instance;
59 EventDurationBlock::EventDurationBlock(const std::string &tag) : _tag{tag}
61 auto &glob = EventCollectorGlobal::get();
62 glob.collector().onEvent(EventCollector::Event{EventCollector::Edge::BEGIN, "0", _tag});
64 EventDurationBlock::~EventDurationBlock()
66 auto &glob = EventCollectorGlobal::get();
67 glob.collector().onEvent(EventCollector::Event{EventCollector::Edge::END, "0", _tag});
70 EventDurationManual::EventDurationManual(const std::string &tag) : _tag{tag}, _pair{true} {}
72 EventDurationManual::~EventDurationManual()
74 // Check if it has called begin-end pair
78 void EventDurationManual::begin()
81 auto &glob = EventCollectorGlobal::get();
82 glob.collector().onEvent(EventCollector::Event{EventCollector::Edge::BEGIN, "0", _tag});
85 void EventDurationManual::end()
89 auto &glob = EventCollectorGlobal::get();
90 glob.collector().onEvent(EventCollector::Event{EventCollector::Edge::END, "0", _tag});