Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
GraphExecutionTracer.h
Go to the documentation of this file.
1/**
2 * @file GraphExecutionTracer.h
3 * @brief Graph execution tracing for simulation and validation.
4 * @author Olympe Engine
5 * @date 2026-03-24
6 *
7 * @details
8 * GraphExecutionTracer records each step of graph execution during simulation,
9 * tracking node visits, condition evaluations, and execution flow for debugging
10 * and validation purposes.
11 *
12 * Phase 24.3 — Integration with execution simulation for blueprint validation.
13 * C++14 compliant.
14 */
15
16#pragma once
17
18#include <string>
19#include <vector>
20#include <cstdint>
21#include "../TaskSystem/TaskGraphTemplate.h"
22
23namespace Olympe {
24
25/**
26 * @enum ExecutionEventType
27 * @brief Types of events that can be recorded during graph execution trace.
28 */
30 NodeEntered, ///< Execution entered a node
31 NodeExited, ///< Execution exited a node
32 ConditionEvaluated, ///< A condition was evaluated
33 DataPinResolved, ///< A data pin was resolved
34 BranchTaken, ///< A branch condition was true
35 BranchNotTaken, ///< A branch condition was false
36 ErrorOccurred, ///< An error happened during execution
37 ExecutionBlocked, ///< Execution was blocked (dead-end path, etc.)
38 ExecutionCompleted ///< Graph execution completed
39};
40
41/**
42 * @struct ExecutionEvent
43 * @brief A single event recorded during graph execution trace.
44 */
48 std::string nodeName;
49 std::string nodeType; ///< TaskNodeType as string
50 std::string message; ///< Additional context/details
51 std::string conditionExpression; ///< For condition evaluation events
52 bool conditionResult; ///< Result of condition (if applicable)
53 float timestamp; ///< Time in execution (frame count, step count)
54 int32_t stepNumber; ///< Sequential step number
55 int32_t depth; ///< Call stack depth (for subgraphs)
56
60};
61
62/**
63 * @class GraphExecutionTracer
64 * @brief Records execution trace during graph simulation.
65 *
66 * @details
67 * Used by GraphExecutionSimulator to capture execution flow. Can be queried
68 * to understand why a graph failed or which path was taken.
69 */
71public:
72
75
76 /**
77 * @brief Clears all recorded events and resets state.
78 */
79 void Reset();
80
81 /**
82 * @brief Records that execution entered a node.
83 * @param nodeId ID of the node being entered.
84 * @param nodeName Display name of the node.
85 * @param nodeType Type of the node (from TaskNodeType).
86 */
87 void RecordNodeEntered(int32_t nodeId, const std::string& nodeName, const std::string& nodeType);
88
89 /**
90 * @brief Records that execution exited a node successfully.
91 * @param nodeId ID of the node being exited.
92 * @param nextNodeId ID of the next node in execution (NODE_INDEX_NONE if end).
93 */
95
96 /**
97 * @brief Records a condition evaluation result.
98 * @param nodeId ID of the node containing the condition.
99 * @param expression String representation of the condition.
100 * @param result Whether the condition evaluated to true.
101 * @param message Optional additional details.
102 */
103 void RecordConditionEvaluated(int32_t nodeId, const std::string& expression,
104 bool result, const std::string& message = "");
105
106 /**
107 * @brief Records that a branch was taken based on condition.
108 * @param nodeId ID of the branch node.
109 * @param branchName Name of the branch taken ("True", "False", case name, etc.).
110 * @param nextNodeId ID of the node being branched to.
111 */
112 void RecordBranchTaken(int32_t nodeId, const std::string& branchName, int32_t nextNodeId);
113
114 /**
115 * @brief Records an execution error.
116 * @param nodeId ID of the node where error occurred (NODE_INDEX_NONE for graph-level).
117 * @param nodeName Name of the node (if applicable).
118 * @param errorMessage Description of the error.
119 * @param severity "Error" or "Critical".
120 */
121 void RecordError(int32_t nodeId, const std::string& nodeName,
122 const std::string& errorMessage, const std::string& severity = "Error");
123
124 /**
125 * @brief Records that execution was blocked (dead-end, etc.).
126 * @param nodeId ID of the node causing the block.
127 * @param reason Why execution was blocked.
128 */
129 void RecordExecutionBlocked(int32_t nodeId, const std::string& reason);
130
131 /**
132 * @brief Records data pin resolution.
133 * @param nodeId ID of the node.
134 * @param pinName Name of the pin.
135 * @param value Resolved value as string.
136 */
137 void RecordDataPinResolved(int32_t nodeId, const std::string& pinName, const std::string& value);
138
139 /**
140 * @brief Records graph execution completion.
141 * @param success true if completed successfully, false if ended with error.
142 * @param message Summary message.
143 */
144 void RecordExecutionCompleted(bool success, const std::string& message);
145
146 /**
147 * @brief Returns all recorded events.
148 */
149 const std::vector<ExecutionEvent>& GetEvents() const { return m_events; }
150
151 /**
152 * @brief Returns the number of steps executed.
153 */
154 int32_t GetStepCount() const { return m_stepCount; }
155
156 /**
157 * @brief Returns true if any errors were recorded.
158 */
159 bool HasErrors() const { return !m_errorNodes.empty(); }
160
161 /**
162 * @brief Returns the set of node IDs that encountered errors.
163 */
164 const std::vector<int32_t>& GetErrorNodes() const { return m_errorNodes; }
165
166 /**
167 * @brief Returns a formatted trace log as a multi-line string.
168 */
169 std::string GetTraceLog() const;
170
171 /**
172 * @brief Returns a summary of the execution (steps, errors, etc.).
173 */
174 std::string GetExecutionSummary() const;
175
176private:
177
178 void AddEvent(const ExecutionEvent& event);
179
180 std::vector<ExecutionEvent> m_events;
181 std::vector<int32_t> m_errorNodes;
184 bool m_executionSuccess = false;
185};
186
187} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Records execution trace during graph simulation.
void RecordExecutionCompleted(bool success, const std::string &message)
Records graph execution completion.
void RecordBranchTaken(int32_t nodeId, const std::string &branchName, int32_t nextNodeId)
Records that a branch was taken based on condition.
void RecordNodeExited(int32_t nodeId, int32_t nextNodeId)
Records that execution exited a node successfully.
const std::vector< ExecutionEvent > & GetEvents() const
Returns all recorded events.
std::string GetTraceLog() const
Returns a formatted trace log as a multi-line string.
void Reset()
Clears all recorded events and resets state.
void RecordError(int32_t nodeId, const std::string &nodeName, const std::string &errorMessage, const std::string &severity="Error")
Records an execution error.
std::vector< int32_t > m_errorNodes
void RecordConditionEvaluated(int32_t nodeId, const std::string &expression, bool result, const std::string &message="")
Records a condition evaluation result.
const std::vector< int32_t > & GetErrorNodes() const
Returns the set of node IDs that encountered errors.
void RecordExecutionBlocked(int32_t nodeId, const std::string &reason)
Records that execution was blocked (dead-end, etc.).
void RecordNodeEntered(int32_t nodeId, const std::string &nodeName, const std::string &nodeType)
Records that execution entered a node.
void AddEvent(const ExecutionEvent &event)
bool HasErrors() const
Returns true if any errors were recorded.
void RecordDataPinResolved(int32_t nodeId, const std::string &pinName, const std::string &value)
Records data pin resolution.
int32_t GetStepCount() const
Returns the number of steps executed.
std::vector< ExecutionEvent > m_events
std::string GetExecutionSummary() const
Returns a summary of the execution (steps, errors, etc.).
< Provides AssetID and INVALID_ASSET_ID
ExecutionEventType
Types of events that can be recorded during graph execution trace.
@ ExecutionBlocked
Execution was blocked (dead-end path, etc.)
@ BranchTaken
A branch condition was true.
@ BranchNotTaken
A branch condition was false.
@ NodeEntered
Execution entered a node.
@ DataPinResolved
A data pin was resolved.
@ ConditionEvaluated
A condition was evaluated.
@ ErrorOccurred
An error happened during execution.
@ ExecutionCompleted
Graph execution completed.
@ NodeExited
Execution exited a node.
A single event recorded during graph execution trace.
std::string conditionExpression
For condition evaluation events.
std::string nodeType
TaskNodeType as string.
int32_t depth
Call stack depth (for subgraphs)
int32_t stepNumber
Sequential step number.
float timestamp
Time in execution (frame count, step count)
bool conditionResult
Result of condition (if applicable)
std::string message
Additional context/details.