| 172 | } |
| 173 | |
| 174 | void Timeline::AllocateTimeNodes(GraphNode* gnode) { |
| 175 | if (gnode->Trackable(step_)) { |
| 176 | TrackNode(gnode); |
| 177 | const TFGraphNode* node = gnode->node; |
| 178 | for (const auto& kernel_execs : node->op_execs(step_)) { |
| 179 | const string& device = kernel_execs.first; |
| 180 | |
| 181 | if (process_.find(device) == process_.end()) { |
| 182 | int64 pid = AllocatePID(); |
| 183 | process_[device].reset(new Process(device, pid)); |
| 184 | chrome_formatter_.EmitPID(GetTimeDevName(device), pid); |
| 185 | } |
| 186 | Process* p = process_[device].get(); |
| 187 | |
| 188 | for (const auto& exec : kernel_execs.second) { |
| 189 | int64 start_micros = exec.first; |
| 190 | int64 exec_micros = exec.second; |
| 191 | // TODO(xpan): There might be start time duplication here. |
| 192 | if (tnodes_[device].find(start_micros) == tnodes_[device].end()) { |
| 193 | // TODO(xpan): Give each kernel call a unique_name. |
| 194 | tnodes_[device][start_micros].reset( |
| 195 | new TimeNode(p, gnode, start_micros, exec_micros)); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | for (GraphNode* n : gnode->show_children) { |
| 201 | AllocateTimeNodes(n); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | void Timeline::GenerateGraphTimeline(const std::vector<GraphNode*>& gnodes) { |
| 206 | for (GraphNode* gnode : gnodes) { |