Utils¶
-
namespace Utils¶
Utility functions for debugging and monitoring reactive nodes.
Provides tools for visualizing dependency graphs, printing node metrics, and collecting statistics about the reactive system.
- Since
v0.1.0
Functions¶
-
inline Status printGraphMermaid(char *buffer, size_t buffer_size, size_t *bytes_written = nullptr)¶
Generate Mermaid diagram syntax for dependency graph visualization.
Generates Mermaid flowchart syntax showing all reactive nodes and their dependencies. Output can be pasted into https://mermaid.live or GitHub for visual graph rendering.
- Since
v0.1.0
char mermaid[1024]; size_t bytes = 0; if (Utils::printGraphMermaid(mermaid, sizeof(mermaid), &bytes)) { Serial.printf("Bytes written: %zu\n", bytes); Serial.println(mermaid); // Copy output to https://mermaid.live for visualization }Note
Requires
RXESP32_ENABLE_DEPENDENCY_GRAPHto be enabled.
-
inline Status printGraphMermaidToStream(Stream &stream = Serial, size_t *bytes_written = nullptr)¶
Print Mermaid diagram syntax to a Stream.
Writes the Mermaid dependency graph directly to any Arduino Stream (Serial, File, etc.) without needing a buffer. Output can be pasted into https://mermaid.live or GitHub for visual graph rendering.
- Since
v0.1.0
Signal<int> signal(0, {.name = "My Signal"}); Computed<int> doubled([]() { return number.get() * 2; }, {.name = "Doubled"}); Computed<int> quadrupled([]() { return number.get() * 2; }, {.name = "Quadrupled"}); Effect<> effect( []() { doubled.get(); quadrupled.get(); return nullptr; }, {.name = "My Effect"}); Utils::printGraphMermaidToStream(); // Copy Serial output to https://mermaid.livegraph TD S0[My Signal] C1[Doubled] C2[Quadrupled] E3[My Effect] S0 --> C1 S0 --> C2 C1 --> E3 C2 --> E3Note
Requires
RXESP32_ENABLE_DEPENDENCY_GRAPHto be enabled.Internally uses a fixed-size buffer defined by
RXESP32_DEPENDENCY_GRAPH_STREAM_BUFFER_SIZE_B. Ensure this is large enough for your graph.
- Parameters:¶
- Returns:¶
Status::Okif successful, error code otherwise.
-
inline void printNodeMetrics(ReactiveNode &node, Stream &stream = Serial)¶
Print node metrics to Serial or any Stream.
Displays execution count, timing statistics, and notification count for a specific reactive node. Useful for performance analysis and debugging.
- Since
v0.1.0
Computed<int> expensive([]() { return slowCalculation(); }, {.name = "Expensive"}); // ... after some executions ... Utils::printNodeMetrics(expensive); // Output: // ======= Node Metrics ======= // - Node: Expensive // - Executions: 61 // - Total time: 1580 us // - Average: 124 us // - Min: 110 us // - Max: 162 us // - Notifications: 10 // ===========================Note
Requires
RXESP32_ENABLE_NODE_METRICSto be enabled.
-
NodeStats getNodeStats()¶
Get statistics about all reactive nodes.
Returns counts of all Signal / Computed / Effect instances currently alive in the system. Useful for debugging, memory profiling, and detecting leaks.
- Since
v0.1.0
auto stats = Utils::getNodeStats(); Serial.printf("Signals: %u\n", stats.signal_count); Serial.printf("Computed: %u\n", stats.computed_count); Serial.printf("Effects: %u\n", stats.effect_count); Serial.printf("Total: %u nodes\n", stats.total_nodes); Serial.printf("Memory: %zu bytes\n", stats.total_memory_used_b);
-
void printNodeStats(Stream &stream = Serial)¶
Print node statistics to Serial or any Stream.
Displays counts of all node types and estimated memory usage.
- Since
v0.1.0
Utils::printNodeStats(); // Output: // === Reactive Nodes Statistics === // - Signals: 5 // - Computed: 3 // - Effects: 2 // - Total Nodes: 10 // - Memory Used: 900 bytes // ================================
See Also¶
Core - Core Overview