tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_TestUtilities.cpp
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
12#include "../../3rd_party/choc/text/choc_StringUtilities.h"
13
14#if __has_include (<cxxabi.h>)
15#include <cxxabi.h>
16#endif
17
18namespace tracktion { inline namespace graph { namespace test_utilities
19{
20 inline std::string demangle (std::string name)
21 {
22 #if __has_include (<cxxabi.h>)
23 int status;
24
25 if (char* demangled = abi::__cxa_demangle (name.c_str(), nullptr, nullptr, &status); status == 0)
26 {
27 std::string demangledString (demangled);
28 free (demangled);
29 return demangledString;
30 }
31 #endif
32
33 return name;
34 }
35
37 {
38 struct NodeInfo
39 {
40 std::string label;
41 size_t memorySizeBytes = 0;
42 int numOutputs = -1;
43 bool containsInternalNodes = false;
44 int latencyNumSamples = 0;
45 };
46
47 struct Visitor
48 {
49 static std::pair<std::string, std::string> getNodeName (Node& n)
50 {
51 return { std::to_string (reinterpret_cast<uintptr_t> (&n)),
52 demangle (typeid (n).name()) };
53 }
54
55 static void visitInputs (Node& n, std::vector<std::string>& edges, std::map<std::string, NodeInfo>& map)
56 {
57 const auto [destNodeID, destNodeString] = getNodeName (n);
58 auto& destNodeInfo = map[destNodeID];
59 destNodeInfo.label = destNodeString;
60 destNodeInfo.memorySizeBytes = n.getAllocatedBytes();
61 destNodeInfo.containsInternalNodes = ! n.getInternalNodes().empty();
62 destNodeInfo.numOutputs = n.numOutputNodes;
63 destNodeInfo.latencyNumSamples = n.getNodeProperties().latencyNumSamples;
64
65 for (auto input : n.getDirectInputNodes())
66 {
67 const auto [sourceNodeID, sourceNodeString] = getNodeName (*input);
68 auto& sourceNodeInfo = map[sourceNodeID];
69 sourceNodeInfo.label = sourceNodeString;
70
71 const auto edge = sourceNodeID + "->" + destNodeID;
72
73 if (std::find (edges.begin(), edges.end(), edge) == edges.end())
74 edges.push_back (edge);
75
76 visitInputs (*input, edges, map);
77 }
78 }
79 };
80
83 Visitor::visitInputs (node, edges, idNameMap);
84
85 // Build graph
86 std::string output;
87 output += "digraph {\n";
88
89 for (auto [id, info] : idNameMap)
90 {
91 std::string label = choc::text::replace (info.label,
92 "tracktion::engine", "te",
93 "tracktion::graph", "tg");
94
95 std::string colourString, shapeString;
96
97 if (info.memorySizeBytes > 0)
98 {
99 label += "*";
100 colourString += "color=red ";
101 }
102
103 label += " (" + std::to_string (info.numOutputs) + ")";
104
105 if (info.latencyNumSamples > 0)
106 label += choc::text::replace ("\n{}", "{}", std::to_string (info.latencyNumSamples));
107
108 if (info.containsInternalNodes)
109 shapeString += "shape=box";
110
111 output += id + "[label=\"" + label + "\" " + colourString + shapeString + "]\n";
112 }
113
114 for (auto edge : edges)
115 output += edge += "\n";
116
117 output += "\n}";
118
119 return output;
120 }
121}}}
T begin(T... args)
Main graph Node processor class.
virtual std::vector< Node * > getDirectInputNodes()
Should return all the inputs directly feeding in to this node.
virtual std::vector< Node * > getInternalNodes()
Can return Nodes that are internal to this Node but don't make up the main graph constructed from get...
virtual NodeProperties getNodeProperties()=0
Should return the properties of the node.
T end(T... args)
T find(T... args)
T push_back(T... args)
typedef uintptr_t
T to_string(T... args)
std::string createGraphDescription(Node &node)
Returns the graph structure in a dot textual description.