| 124 | } |
| 125 | |
| 126 | int StatisticsEngine::Init(const platform::NodeTrees& trees) { |
| 127 | if (inited_) { |
| 128 | LOG(WARNING) << "Duplicate initialization for StatisticsEngine"; |
| 129 | return -1; |
| 130 | } |
| 131 | if (phi::GetCurrentThreadName() != "MainThread") { |
| 132 | LOG(WARNING) << "StatisticsEngin must run on the main thread"; |
| 133 | return -1; |
| 134 | } |
| 135 | inited_ = true; |
| 136 | InitStdEvents(); |
| 137 | InitInnerthreadPriorityForStdEvents(); |
| 138 | InitInterthreadPriorityForStdEvents(); |
| 139 | // determine executor type |
| 140 | uint64_t main_tid = phi::GetCurrentThreadId().sys_tid; |
| 141 | for (const auto& kv : trees.GetNodeTrees()) { |
| 142 | if (kv.first != main_tid) { |
| 143 | continue; |
| 144 | } |
| 145 | std::queue<const platform::HostTraceEventNode*> q; |
| 146 | q.push(kv.second); |
| 147 | while (!q.empty()) { |
| 148 | auto cur_node = q.front(); |
| 149 | q.pop(); |
| 150 | const auto& name = cur_node->Name(); |
| 151 | if (name.find("Executor::") == 0) { |
| 152 | VLOG(10) << "type: Executor"; |
| 153 | executor_type_ = ExecutorType::EXECUTOR; |
| 154 | return InitFiltersForExecutor(); |
| 155 | } else if (name.find("StandaloneExecutor::") == 0) { |
| 156 | VLOG(10) << "type: InterpreterCore"; |
| 157 | executor_type_ = ExecutorType::INTERPRETER_CORE; |
| 158 | return InitFiltersForInterpreterCore(); |
| 159 | } |
| 160 | for (const auto& child : cur_node->GetChildren()) { |
| 161 | q.push(child); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | LOG(WARNING) << "Unsupported Executor"; |
| 166 | return -1; |
| 167 | } |
| 168 | |
| 169 | void StatisticsEngine::InitStdEvents() { |
| 170 | name2idx_["Total"] = names_.size(); |
nothing calls this directly
no test coverage detected