| 80 | namespace { |
| 81 | |
| 82 | void render_node(const std::unordered_map<u32, std::vector<const Process*>>& children, |
| 83 | const Process* root, std::string prefix, bool last, |
| 84 | std::string& out, int depth) |
| 85 | { |
| 86 | if (depth > 64) return; // sanity guard against ppid cycles |
| 87 | // Tree connector for this node. |
| 88 | out += prefix; |
| 89 | out += last ? "\\-- " : "+-- "; |
| 90 | out += fmt::format("{} {}\n", root->pid, root->comm); |
| 91 | |
| 92 | auto it = children.find(root->pid); |
| 93 | if (it == children.end()) return; |
| 94 | const auto& kids = it->second; |
| 95 | for (std::size_t i = 0; i < kids.size(); ++i) { |
| 96 | std::string next_prefix = prefix + (last ? " " : "| "); |
| 97 | render_node(children, kids[i], std::move(next_prefix), |
| 98 | i + 1 == kids.size(), out, depth + 1); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | } // anonymous |
| 103 |
no test coverage detected