| 43 | } |
| 44 | |
| 45 | void TFGraph::Build() { |
| 46 | if (root_) return; |
| 47 | |
| 48 | std::set<string> nonroots; |
| 49 | // Filter out the root nodes (node not input of any other node). |
| 50 | for (auto it = nodes_map_.begin(); it != nodes_map_.end(); it++) { |
| 51 | GraphNode* node = it->second.get(); |
| 52 | const std::map<int, string>& inputs = node->node->inputs(); |
| 53 | for (auto inputs_it = inputs.cbegin(); inputs_it != inputs.cend(); |
| 54 | inputs_it++) { |
| 55 | nonroots.insert(inputs_it->second); |
| 56 | auto child_it = nodes_map_.find(inputs_it->second); |
| 57 | if (child_it != nodes_map_.end()) { |
| 58 | node->children.push_back(child_it->second.get()); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | std::vector<GraphNode*> roots; |
| 63 | for (auto it = nodes_map_.begin(); it != nodes_map_.end(); it++) { |
| 64 | if (nonroots.find(it->first) == nonroots.end()) { |
| 65 | roots.push_back(it->second.get()); |
| 66 | } |
| 67 | } |
| 68 | root_ = CreateParentNode(kTFProfRoot); |
| 69 | root_->children.insert(root_->children.end(), roots.begin(), roots.end()); |
| 70 | } |
| 71 | |
| 72 | const ShowNode* TFGraph::ShowInternal(const Options& opts, Timeline* timeline) { |
| 73 | root_->ResetTotalStats(); |