提交 b7e6bd7b 编写于 作者: M Megvii Engine Team

feat(profiler): custom event support device

GitOrigin-RevId: 4709c44b399b22e6f84b198730f4cdb6d78d6074
上级 defbc20e
...@@ -78,6 +78,20 @@ void imperative_log_profile(const char* message){ ...@@ -78,6 +78,20 @@ void imperative_log_profile(const char* message){
imperative_log_profile_end(message); imperative_log_profile_end(message);
} }
SYMBOL_EXPORT
void imperative_log_profile_begin(const char* message, const char* device) {
auto comp_node = CompNode::load(device);
MGB_RECORD_EVENT(CustomEvent, std::string{message}, {}, comp_node);
MGB_RECORD_EVENT(RecordDeviceEvent, EventPool::with_timer().alloc_shared(comp_node));
}
SYMBOL_EXPORT
void imperative_log_profile_end(const char* message, const char* device) {
auto comp_node = CompNode::load(device);
MGB_RECORD_EVENT(RecordDeviceEvent, EventPool::with_timer().alloc_shared(comp_node));
MGB_RECORD_EVENT(CustomFinishEvent, std::string{message}, {}, comp_node);
}
} }
std::thread::id ChannelImpl::get_worker_tid() { std::thread::id ChannelImpl::get_worker_tid() {
......
...@@ -350,8 +350,14 @@ struct ChromeTimelineEventVisitor: EventVisitor<ChromeTimelineEventVisitor> { ...@@ -350,8 +350,14 @@ struct ChromeTimelineEventVisitor: EventVisitor<ChromeTimelineEventVisitor> {
new_host_event("StopProfile", 'E'); new_host_event("StopProfile", 'E');
} else if constexpr (std::is_same_v<TEvent, CustomEvent>) { } else if constexpr (std::is_same_v<TEvent, CustomEvent>) {
new_host_event(event.title, 'B'); new_host_event(event.title, 'B');
if (event.device.valid()) {
new_device_event(event.title, 'B', event.device);
}
} else if constexpr (std::is_same_v<TEvent, CustomFinishEvent>) { } else if constexpr (std::is_same_v<TEvent, CustomFinishEvent>) {
new_host_event(event.title, 'E'); new_host_event(event.title, 'E');
if (event.device.valid()) {
new_device_event(event.title, 'E', event.device);
}
} else if constexpr (std::is_same_v<TEvent, AutoEvictEvent>) { } else if constexpr (std::is_same_v<TEvent, AutoEvictEvent>) {
new_host_event("AutoEvict", 'B'); new_host_event("AutoEvict", 'B');
} else if constexpr (std::is_same_v<TEvent, AutoEvictFinishEvent>) { } else if constexpr (std::is_same_v<TEvent, AutoEvictFinishEvent>) {
...@@ -378,12 +384,21 @@ struct ChromeTimelineEventVisitor: EventVisitor<ChromeTimelineEventVisitor> { ...@@ -378,12 +384,21 @@ struct ChromeTimelineEventVisitor: EventVisitor<ChromeTimelineEventVisitor> {
} }
void name_threads(Profiler::thread_dict_t thread_dict) { void name_threads(Profiler::thread_dict_t thread_dict) {
for (auto&& [tid, tname]: thread_dict) { for (auto&& host: host_threads()) {
if (thread_dict.count(host)) {
trace_events.new_event()
.name("thread_name")
.pid('M')
.tid(to_tid(host))
.arg("name", thread_dict.at(host));
}
}
for (auto&& device: devices()) {
trace_events.new_event() trace_events.new_event()
.name("thread_name") .name("thread_name")
.pid('M') .pid('M')
.tid(to_tid(tid)) .tid(to_tid(device))
.arg("name", tname); .arg("name", device.to_string_logical());
} }
} }
}; };
......
...@@ -179,6 +179,7 @@ DEF_DUR_EVENT(AutoEvict, {}); ...@@ -179,6 +179,7 @@ DEF_DUR_EVENT(AutoEvict, {});
DEF_DUR_EVENT(Custom, { DEF_DUR_EVENT(Custom, {
std::string title; std::string title;
std::string content; std::string content;
CompNode device;
}); });
DEF_EVENT(RecordDevice, { DEF_EVENT(RecordDevice, {
......
...@@ -218,6 +218,22 @@ protected: ...@@ -218,6 +218,22 @@ protected:
return m_device_tid_table.at(device); return m_device_tid_table.at(device);
} }
SmallVector<std::thread::id> host_threads() {
SmallVector<std::thread::id> host_threads;
for (auto&& [host, _]: m_host_tid_table) {
host_threads.push_back(host);
}
return host_threads;
}
SmallVector<CompNode> devices() {
SmallVector<CompNode> devices;
for (auto&& [device, _]: m_device_tid_table) {
devices.push_back(device);
}
return devices;
}
void inc_counter(const char* key, int64_t delta) { void inc_counter(const char* key, int64_t delta) {
if (!m_counter_table.count(key)) { if (!m_counter_table.count(key)) {
m_counter_table[key] = 0; m_counter_table[key] = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册