Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
GraphExecutionTracer.cpp
Go to the documentation of this file.
1/**
2 * @file GraphExecutionTracer.cpp
3 * @brief Implementation of graph execution tracing.
4 * @author Olympe Engine
5 * @date 2026-03-24
6 */
7
9#include "../system/system_utils.h"
10#include <sstream>
11#include <iomanip>
12
13namespace Olympe {
14
16 : m_stepCount(0), m_executionComplete(false), m_executionSuccess(false)
17{
18}
19
23
25{
26 m_events.clear();
27 m_errorNodes.clear();
28 m_stepCount = 0;
29 m_executionComplete = false;
30 m_executionSuccess = false;
31}
32
33void GraphExecutionTracer::RecordNodeEntered(int32_t nodeId, const std::string& nodeName, const std::string& nodeType)
34{
37 event.nodeId = nodeId;
38 event.nodeName = nodeName;
39 event.nodeType = nodeType;
40 event.stepNumber = m_stepCount++;
41 event.message = "Entering node";
43}
44
46{
49 event.nodeId = nodeId;
50 event.stepNumber = m_stepCount++;
51 if (nextNodeId >= 0)
52 {
53 event.message = "Exiting node, next: " + std::to_string(nextNodeId);
54 }
55 else
56 {
57 event.message = "Exiting node";
58 }
60}
61
63 bool result, const std::string& message)
64{
67 event.nodeId = nodeId;
68 event.conditionExpression = expression;
69 event.conditionResult = result;
70 event.stepNumber = m_stepCount++;
71 event.message = "Condition '" + expression + "' = " + (result ? "TRUE" : "FALSE");
72 if (!message.empty())
73 {
74 event.message += " (" + message + ")";
75 }
77}
78
80{
83 event.nodeId = nodeId;
84 event.stepNumber = m_stepCount++;
85 event.message = "Branch taken: " + branchName + " -> Node " + std::to_string(nextNodeId);
87}
88
89void GraphExecutionTracer::RecordError(int32_t nodeId, const std::string& nodeName,
90 const std::string& errorMessage, const std::string& severity)
91{
94 event.nodeId = nodeId;
95 event.nodeName = nodeName;
96 event.stepNumber = m_stepCount++;
97 event.message = "[" + severity + "] " + errorMessage;
99
100 if (nodeId >= 0 && std::find(m_errorNodes.begin(), m_errorNodes.end(), nodeId) == m_errorNodes.end())
101 {
102 m_errorNodes.push_back(nodeId);
103 }
104}
105
107{
110 event.nodeId = nodeId;
111 event.stepNumber = m_stepCount++;
112 event.message = "Execution blocked: " + reason;
114
115 if (nodeId >= 0 && std::find(m_errorNodes.begin(), m_errorNodes.end(), nodeId) == m_errorNodes.end())
116 {
117 m_errorNodes.push_back(nodeId);
118 }
119}
120
121void GraphExecutionTracer::RecordDataPinResolved(int32_t nodeId, const std::string& pinName, const std::string& value)
122{
125 event.nodeId = nodeId;
126 event.stepNumber = m_stepCount++;
127 event.message = "Data pin '" + pinName + "' = " + value;
129}
130
131void GraphExecutionTracer::RecordExecutionCompleted(bool success, const std::string& message)
132{
133 m_executionComplete = true;
134 m_executionSuccess = success;
135
138 event.nodeId = -1;
139 event.stepNumber = m_stepCount++;
140 event.message = message;
142}
143
145{
146 std::ostringstream oss;
147
148 oss << "=== EXECUTION TRACE ===\n";
149 oss << "Total Steps: " << m_stepCount << "\n";
150 oss << "Errors: " << m_errorNodes.size() << "\n";
151 oss << "Status: " << (m_executionComplete ? (m_executionSuccess ? "SUCCESS" : "FAILED") : "INCOMPLETE") << "\n";
152 oss << "\n--- Event Log ---\n";
153
154 for (size_t i = 0; i < m_events.size(); ++i)
155 {
156 const ExecutionEvent& event = m_events[i];
157 oss << std::setw(3) << (i + 1) << ". ";
158
159 switch (event.type)
160 {
162 oss << "[ENTER] ";
163 break;
165 oss << "[EXIT] ";
166 break;
168 oss << "[COND] ";
169 break;
171 oss << "[BRANCH] ";
172 break;
174 oss << "[ERROR] ";
175 break;
177 oss << "[BLOCKED] ";
178 break;
180 oss << "[DATA] ";
181 break;
183 oss << "[DONE] ";
184 break;
185 default:
186 oss << "[???] ";
187 break;
188 }
189
190 if (event.nodeId >= 0)
191 {
192 oss << "Node " << std::setw(3) << event.nodeId;
193 if (!event.nodeName.empty())
194 oss << " (" << event.nodeName << ")";
195 oss << ": ";
196 }
197
198 oss << event.message << "\n";
199 }
200
201 return oss.str();
202}
203
205{
206 std::ostringstream oss;
207
208 oss << "Execution Summary:\n";
209 oss << " Steps executed: " << m_stepCount << "\n";
210 oss << " Status: " << (m_executionComplete ? (m_executionSuccess ? "✓ SUCCESS" : "✗ FAILED") : "⊘ INCOMPLETE") << "\n";
211 oss << " Errors found: " << m_errorNodes.size() << "\n";
212
213 if (!m_errorNodes.empty())
214 {
215 oss << " Error nodes: ";
216 for (size_t i = 0; i < m_errorNodes.size(); ++i)
217 {
218 if (i > 0) oss << ", ";
219 oss << m_errorNodes[i];
220 }
221 oss << "\n";
222 }
223
224 // Count event types
225 int enteredCount = 0, conditionCount = 0, errorCount = 0;
226 for (const auto& event : m_events)
227 {
231 }
232
233 oss << " Nodes visited: " << enteredCount << "\n";
234 oss << " Conditions evaluated: " << conditionCount << "\n";
235 oss << " Errors logged: " << errorCount << "\n";
236
237 return oss.str();
238}
239
241{
242 m_events.push_back(event);
243}
244
245} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Graph execution tracing for simulation and validation.
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.
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.
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)
void RecordDataPinResolved(int32_t nodeId, const std::string &pinName, const std::string &value)
Records data pin resolution.
std::vector< ExecutionEvent > m_events
std::string GetExecutionSummary() const
Returns a summary of the execution (steps, errors, etc.).
< Provides AssetID and INVALID_ASSET_ID
@ ExecutionBlocked
Execution was blocked (dead-end path, etc.)
@ BranchTaken
A branch condition was true.
@ 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.