feat: Add benchmark logging system for performance analysis (closes #104)
Add Python API for capturing performance data to JSON files: - mcrfpy.start_benchmark() - start capturing frame data - mcrfpy.end_benchmark() - stop and return filename - mcrfpy.log_benchmark(msg) - add log message to current frame The benchmark system captures per-frame data including: - Frame timing (frame_time_ms, fps, timestamp) - Detailed timing breakdown (grid_render, entity_render, python, animation, fov) - Draw call and element counts - User log messages attached to frames Output JSON format supports analysis tools and includes: - Benchmark metadata (PID, timestamps, duration, total frames) - Full frame-by-frame metrics array Also refactors ProfilingMetrics from nested GameEngine struct to top-level struct for easier forward declaration. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
219a559c35
commit
a7fef2aeb6
7 changed files with 551 additions and 59 deletions
37
src/BenchmarkLogger.cpp
Normal file
37
src/BenchmarkLogger.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include "BenchmarkLogger.h"
|
||||
#include "GameEngine.h"
|
||||
|
||||
// Global benchmark logger instance
|
||||
BenchmarkLogger g_benchmarkLogger;
|
||||
|
||||
void BenchmarkLogger::recordFrame(const ProfilingMetrics& metrics) {
|
||||
if (!running) return;
|
||||
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
double timestamp_ms = std::chrono::duration<double, std::milli>(now - start_time).count();
|
||||
|
||||
BenchmarkFrame frame;
|
||||
frame.frame_number = ++frame_counter;
|
||||
frame.timestamp_ms = timestamp_ms;
|
||||
frame.frame_time_ms = metrics.frameTime;
|
||||
frame.fps = metrics.fps;
|
||||
|
||||
frame.grid_render_ms = metrics.gridRenderTime;
|
||||
frame.entity_render_ms = metrics.entityRenderTime;
|
||||
frame.python_time_ms = metrics.pythonScriptTime;
|
||||
frame.animation_time_ms = metrics.animationTime;
|
||||
frame.fov_overlay_ms = metrics.fovOverlayTime;
|
||||
|
||||
frame.draw_calls = metrics.drawCalls;
|
||||
frame.ui_elements = metrics.uiElements;
|
||||
frame.visible_elements = metrics.visibleElements;
|
||||
frame.grid_cells_rendered = metrics.gridCellsRendered;
|
||||
frame.entities_rendered = metrics.entitiesRendered;
|
||||
frame.total_entities = metrics.totalEntities;
|
||||
|
||||
// Move pending logs to this frame
|
||||
frame.logs = std::move(pending_logs);
|
||||
pending_logs.clear();
|
||||
|
||||
frames.push_back(std::move(frame));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue