diff --git a/imperative/src/impl/interpreter/interpreter_impl.cpp b/imperative/src/impl/interpreter/interpreter_impl.cpp index 48b23f9cc8c942d6d4ec4a9e2586fb61aadfe053..ce3080694f90fff683c682d3e7ad2dba68b926c7 100644 --- a/imperative/src/impl/interpreter/interpreter_impl.cpp +++ b/imperative/src/impl/interpreter/interpreter_impl.cpp @@ -78,6 +78,20 @@ void imperative_log_profile(const char* 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() { diff --git a/imperative/src/impl/profiler/chrome_timeline.cpp b/imperative/src/impl/profiler/chrome_timeline.cpp index 69e6cc210712af920595b9116d32161d640d84c5..738975294c19163863a46215d4e507be318c06aa 100644 --- a/imperative/src/impl/profiler/chrome_timeline.cpp +++ b/imperative/src/impl/profiler/chrome_timeline.cpp @@ -350,8 +350,14 @@ struct ChromeTimelineEventVisitor: EventVisitor { new_host_event("StopProfile", 'E'); } else if constexpr (std::is_same_v) { 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) { 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) { new_host_event("AutoEvict", 'B'); } else if constexpr (std::is_same_v) { @@ -378,12 +384,21 @@ struct ChromeTimelineEventVisitor: EventVisitor { } 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() .name("thread_name") .pid('M') - .tid(to_tid(tid)) - .arg("name", tname); + .tid(to_tid(device)) + .arg("name", device.to_string_logical()); } } }; diff --git a/imperative/src/impl/profiler/events.h b/imperative/src/impl/profiler/events.h index 62d55b04b28db4d7f2b606f225650643ac33b76d..9db53e60756ab6eadb4df98f14eee15fca44c3cb 100644 --- a/imperative/src/impl/profiler/events.h +++ b/imperative/src/impl/profiler/events.h @@ -179,6 +179,7 @@ DEF_DUR_EVENT(AutoEvict, {}); DEF_DUR_EVENT(Custom, { std::string title; std::string content; + CompNode device; }); DEF_EVENT(RecordDevice, { diff --git a/imperative/src/impl/profiler/states.h b/imperative/src/impl/profiler/states.h index 7aade873309b9ae65d60222819e697d2940b8a25..061f22b515456164de9cfc34dd5bf9d9c0720497 100644 --- a/imperative/src/impl/profiler/states.h +++ b/imperative/src/impl/profiler/states.h @@ -218,6 +218,22 @@ protected: return m_device_tid_table.at(device); } + SmallVector host_threads() { + SmallVector host_threads; + for (auto&& [host, _]: m_host_tid_table) { + host_threads.push_back(host); + } + return host_threads; + } + + SmallVector devices() { + SmallVector devices; + for (auto&& [device, _]: m_device_tid_table) { + devices.push_back(device); + } + return devices; + } + void inc_counter(const char* key, int64_t delta) { if (!m_counter_table.count(key)) { m_counter_table[key] = 0;