| 103 | } |
| 104 | |
| 105 | const ShowMultiNode* TFOp::ShowInternal(const Options& opts, |
| 106 | Timeline* timeline) { |
| 107 | root_->ResetTotalStats(); |
| 108 | if (opts.output_type == kOutput[3]) { |
| 109 | fprintf(stderr, "Only 'code' view supports pprof output now.\n"); |
| 110 | return root_.get(); |
| 111 | } |
| 112 | if (opts.output_type == kOutput[1] || opts.output_type == kOutput[2]) { |
| 113 | root_->formatted_str = FormatNode(root_.get(), root_.get(), opts); |
| 114 | } |
| 115 | if (timeline) { |
| 116 | fprintf(stderr, |
| 117 | "op view doesn't support timeline yet. " |
| 118 | "Consider graph/scope/code view.\n"); |
| 119 | return root_.get(); |
| 120 | } |
| 121 | if (cnodes_map_.empty()) { |
| 122 | return root_.get(); |
| 123 | } |
| 124 | |
| 125 | std::vector<OpNode*> nodes; |
| 126 | for (auto& n : cnodes_map_) { |
| 127 | n.second->account = ReAccount(n.second.get(), opts); |
| 128 | n.second->ResetTotalStats(); |
| 129 | n.second->AddSelfToTotalStats(); |
| 130 | nodes.push_back(n.second.get()); |
| 131 | } |
| 132 | nodes = SortNodes(nodes, opts); |
| 133 | // pre keeps track of previous visited node. |
| 134 | OpNode* pre = nullptr; |
| 135 | std::vector<OpNode*> account_nodes; |
| 136 | for (auto it = nodes.rbegin(); it != nodes.rend(); ++it) { |
| 137 | if ((*it)->account) { |
| 138 | if (pre) (*it)->AggregateTotalStats(pre); |
| 139 | account_nodes.push_back(*it); |
| 140 | pre = *it; |
| 141 | } |
| 142 | } |
| 143 | std::reverse(std::begin(account_nodes), std::end(account_nodes)); |
| 144 | if (pre) { |
| 145 | root_->AggregateTotalStats(pre); |
| 146 | } |
| 147 | |
| 148 | // Perform the display and optionally redo accounting. |
| 149 | int64 depth = 0; |
| 150 | std::vector<OpNode*> show_nodes; |
| 151 | int64 start = SearchRoot(account_nodes, opts.start_name_regexes); |
| 152 | for (int64 i = start; i < account_nodes.size(); ++i, ++depth) { |
| 153 | OpNode* n = account_nodes[i]; |
| 154 | if (ShouldTrim(n, opts.trim_name_regexes) || depth > opts.max_depth) { |
| 155 | break; |
| 156 | } |
| 157 | n->show = ShouldShow(n, opts, depth); |
| 158 | if (n->show) show_nodes.push_back(n); |
| 159 | } |
| 160 | |
| 161 | pre = nullptr; |
| 162 | for (auto it = show_nodes.rbegin(); it != show_nodes.rend(); ++it) { |
nothing calls this directly
no test coverage detected