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_GRAPH to be enabled.

Parameters:
char *buffer

Character array to write Mermaid syntax to.

size_t buffer_size

Size of the buffer (recommend 1024+ bytes).

size_t *bytes_written = nullptr

Optional pointer to store number of bytes written.

Returns:

Status::Ok on success, error code on failure.

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.live

graph TD
  S0[My Signal]
  C1[Doubled]
  C2[Quadrupled]
  E3[My Effect]
  S0 --> C1
  S0 --> C2
  C1 --> E3
  C2 --> E3

Note

  • Requires RXESP32_ENABLE_DEPENDENCY_GRAPH to 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:
Stream &stream = Serial

Reference to Stream object (Serial, File, etc.).

size_t *bytes_written = nullptr

Optional pointer to store number of bytes written.

Returns:

Status::Ok if 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_METRICS to be enabled.

Parameters:
ReactiveNode &node

Reference to any reactive node (Signal, Computed, Effect).

Stream &stream = Serial

Reference to Stream object.

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);

Returns:

NodeStats struct with counts and estimated memory.

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
// ================================

Parameters:
Stream &stream = Serial

Output stream.

struct NodeStats

Statistics about reactive nodes in the system.

Provides counts of active Signal / Computed / Effect instances. Useful for debugging, memory profiling, and leak detection.

Since

v0.1.0

Public Members

uint16_t signal_count = 0

Number of active Signal instances.

uint16_t computed_count = 0

Number of active Computed instances.

uint16_t effect_count = 0

Number of active Effect instances.

uint16_t total_nodes = 0

Total number of reactive nodes.

size_t total_memory_used_b = 0

Estimated total memory used in bytes.

See Also

  • Core - Core Overview