| 66 | bool isVisibleNode(const ProfileTreeEntry& entry) { return entry.smoothedMs > 0.0001; } |
| 67 | |
| 68 | void drawTreeNode(const std::vector<ProfileTreeEntry>& entries, size_t index, double totalTrackedMs) { |
| 69 | if (index >= entries.size()) { |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | const ProfileTreeEntry& entry = entries[index]; |
| 74 | if (!isVisibleNode(entry)) { |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | const double percent = totalTrackedMs > 0.0 ? (entry.smoothedMs * 100.0 / totalTrackedMs) : 0.0; |
| 79 | |
| 80 | std::vector<size_t> visibleChildren; |
| 81 | visibleChildren.reserve(entry.childIndices.size()); |
| 82 | for (const size_t childIndex : entry.childIndices) { |
| 83 | if (childIndex < entries.size() && isVisibleNode(entries[childIndex])) { |
| 84 | visibleChildren.emplace_back(childIndex); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | std::sort(visibleChildren.begin(), visibleChildren.end(), |
| 89 | [&](size_t lhs, size_t rhs) { return entries[lhs].smoothedMs > entries[rhs].smoothedMs; }); |
| 90 | |
| 91 | const std::string shortName = shortenProfileName(entry.name); |
| 92 | const std::string visibleLabel = formatNodeLabel(shortName, entry.smoothedMs, percent); |
| 93 | const std::string nodeLabel = visibleLabel + "###tree_" + std::to_string(index); |
| 94 | |
| 95 | ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_OpenOnArrow; |
| 96 | if (entry.parentIndex == ProfileTreeEntry::kNoParent) { |
| 97 | flags |= ImGuiTreeNodeFlags_DefaultOpen; |
| 98 | } |
| 99 | if (visibleChildren.empty()) { |
| 100 | flags |= ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; |
| 101 | ImGui::TreeNodeEx(nodeLabel.data(), flags); |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | if (ImGui::TreeNodeEx(nodeLabel.data(), flags)) { |
| 106 | for (const size_t childIndex : visibleChildren) { |
| 107 | drawTreeNode(entries, childIndex, totalTrackedMs); |
| 108 | } |
| 109 | ImGui::TreePop(); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | void drawProfilerTreeView(float uiScale) { |
no test coverage detected