Skip to content

Commit 866b44c

Browse files
committed
[Debug] Add add a method to dump dotty style graph.
Add add a method to dump the metadata caches as a dotty graph.
1 parent f22239b commit 866b44c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

include/swift/Runtime/Concurrent.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ template <class KeyTy, class ValueTy> struct ConcurrentMapNode {
128128
delete Right.load(std::memory_order_acquire);
129129
}
130130

131+
#ifndef NDEBUG
132+
void dump() {
133+
auto L = Left.load(std::memory_order_acquire);
134+
auto R = Right.load(std::memory_order_acquire);
135+
printf("\"%p\" [ label = \" {<f0> %08lx | {<f1> | <f2>}}\""
136+
"style=\"rounded\" shape = \"record\"];\n", this, Key);
137+
138+
if (L) {
139+
L->dump();
140+
printf("\"%p\":f1 -> \"%p\":f0;\n", this, L);
141+
}
142+
if (R) {
143+
R->dump();
144+
printf("\"%p\":f2 -> \"%p\":f0;\n", this, R);
145+
}
146+
}
147+
#endif
148+
131149
ConcurrentMapNode(const ConcurrentMapNode &) = delete;
132150
ConcurrentMapNode &operator=(const ConcurrentMapNode &) = delete;
133151

@@ -161,6 +179,20 @@ template <class KeyTy, class ValueTy> class ConcurrentMap {
161179
/// searches the same value in a loop.
162180
std::atomic<NodeTy *> LastSearch;
163181

182+
#ifndef NDEBUG
183+
void dump() {
184+
auto R = Root.load(std::memory_order_acquire);
185+
printf("digraph g {\n"
186+
"graph [ rankdir = \"TB\"];\n"
187+
"node [ fontsize = \"16\" ];\n"
188+
"edge [ ];\n");
189+
if (R) {
190+
R->dump();
191+
}
192+
printf("\n}\n");
193+
}
194+
#endif
195+
164196
/// Search for a value by key \p Key.
165197
/// \returns a pointer to the value or null if the value is not in the map.
166198
ValueTy *findValueByKey(KeyTy Key) {

0 commit comments

Comments
 (0)