From: 이한종/On-Device Lab(SR)/Engineer/삼성전자 Date: Tue, 19 Nov 2019 07:55:24 +0000 (+0900) Subject: [xtrace] Decouple EventCollector from xray (#9024) X-Git-Tag: submit/tizen/20191205.083104~238 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8af9aa04e1df2803aeb39be845f98afde655f10c;p=platform%2Fcore%2Fml%2Fnnfw.git [xtrace] Decouple EventCollector from xray (#9024) - Introduce new EventCollector class that is not dependent on xray framework - Rename as-is `EventCollector` to `EventCollectingListener` Signed-off-by: Hanjoung Lee --- diff --git a/runtime/contrib/xtrace/src/event_collector.cc b/runtime/contrib/xtrace/src/event_collector.cc index 2b37bf4..59484ee 100644 --- a/runtime/contrib/xtrace/src/event_collector.cc +++ b/runtime/contrib/xtrace/src/event_collector.cc @@ -106,7 +106,26 @@ std::ostream &operator<<(std::ostream &os, const std::chrono::milliseconds &dur) } // namespace -void EventCollector::notify(const xray::event *e) +void EventCollector::onEvent(const Event &event) +{ + auto ts = timestamp(); + + switch (event.edge) + { + case Edge::BEGIN: + _rec->emit(DurationEventBuilder(ts).build(event.label, "B")); + break; + + case Edge::END: + _rec->emit(DurationEventBuilder(ts).build(event.label, "E")); + break; + } + + // Trace resource usage per each event notification + emit_rusage(_rec, ts); +} + +void EventCollectingListener::notify(const xray::event *e) { auto ts = timestamp(); @@ -118,11 +137,11 @@ void EventCollector::notify(const xray::event *e) switch (info->action()) { case xdata::trace::enter: - _rec->emit(DurationEventBuilder(ts).build(info->region()->name(), "B")); + _ec.onEvent({EventCollector::Edge::BEGIN, info->region()->name()}); break; case xdata::trace::leave: - _rec->emit(DurationEventBuilder(ts).build(info->region()->name(), "E")); + _ec.onEvent({EventCollector::Edge::END, info->region()->name()}); break; } } @@ -135,7 +154,7 @@ void EventCollector::notify(const xray::event *e) if (auto info = dynamic_cast(BMCategory::get()->event())) { auto name = str(info->phase, info->cur_iter); - _rec->emit(DurationEventBuilder(ts).build(name, "B")); + _ec.onEvent({EventCollector::Edge::BEGIN, name}); auto head = make_head(info->phase, info->cur_iter); std::cout << head << std::endl; @@ -144,14 +163,11 @@ void EventCollector::notify(const xray::event *e) if (auto info = dynamic_cast(BMCategory::get()->event())) { auto name = str(info->phase, info->cur_iter); - _rec->emit(DurationEventBuilder(ts).build(name, "E")); + _ec.onEvent({EventCollector::Edge::END, name}); auto head = make_head(info->phase, info->cur_iter); std::cout << head << " - done " << std::endl; std::cout << head << " takes " << info->elapsed << "ms" << std::endl; } } - - // Trace resource usage per each event notification - emit_rusage(_rec, ts); } diff --git a/runtime/contrib/xtrace/src/event_collector.h b/runtime/contrib/xtrace/src/event_collector.h index f088ecd..eeef0d7 100644 --- a/runtime/contrib/xtrace/src/event_collector.h +++ b/runtime/contrib/xtrace/src/event_collector.h @@ -21,19 +21,47 @@ #include -class EventCollector final : public xray::listener +class EventCollector { public: + enum class Edge + { + BEGIN, + END + }; + + struct Event + { + Edge edge; + std::string label; + }; + +public: EventCollector(EventRecorder *rec) : _rec{rec} { // DO NOTHING } public: + void onEvent(const Event &event); + +protected: + EventRecorder *_rec; +}; + +class EventCollectingListener final : public xray::listener +{ +public: + EventCollectingListener(EventRecorder *rec) : _ec{rec} + { + // DO NOTHING + } + +public: void notify(const xray::event *e) final; private: - EventRecorder *_rec = nullptr; + EventCollector _ec; }; #endif // __EVENT_COLLECTOR_H__ diff --git a/runtime/contrib/xtrace/src/xtrace.cc b/runtime/contrib/xtrace/src/xtrace.cc index 117a2e6..78a1c7e 100644 --- a/runtime/contrib/xtrace/src/xtrace.cc +++ b/runtime/contrib/xtrace/src/xtrace.cc @@ -37,13 +37,13 @@ static int entry(int argc, char **argv) recorder.init(); - EventCollector event_collector{&recorder}; + EventCollectingListener event_collecting_listener{&recorder}; - xray::mux::get().attach(&event_collector); + xray::mux::get().attach(&event_collecting_listener); BMRunner().run(argv[3]); - xray::mux::get().detach(&event_collector); + xray::mux::get().detach(&event_collecting_listener); recorder.fini();