mirror of https://github.com/inolen/redream.git
add frame time debug graph
This commit is contained in:
parent
de0dad6096
commit
955a2ae89c
|
@ -53,7 +53,6 @@ struct emu {
|
||||||
struct host *host;
|
struct host *host;
|
||||||
struct dreamcast *dc;
|
struct dreamcast *dc;
|
||||||
|
|
||||||
int debug_menu;
|
|
||||||
volatile int running;
|
volatile int running;
|
||||||
volatile int video_width;
|
volatile int video_width;
|
||||||
volatile int video_height;
|
volatile int video_height;
|
||||||
|
@ -101,6 +100,13 @@ struct emu {
|
||||||
emulation thread when modified. instead, they are added to this modified
|
emulation thread when modified. instead, they are added to this modified
|
||||||
list which will be processed the next time the threads are synchronized */
|
list which will be processed the next time the threads are synchronized */
|
||||||
struct list modified_textures;
|
struct list modified_textures;
|
||||||
|
|
||||||
|
/* debug stats */
|
||||||
|
int debug_menu;
|
||||||
|
int frame_stats;
|
||||||
|
int frame_seq;
|
||||||
|
float frame_times[360];
|
||||||
|
int64_t last_paint;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -457,10 +463,12 @@ static void emu_paint(struct emu *emu) {
|
||||||
if (emu->debug_menu) {
|
if (emu->debug_menu) {
|
||||||
if (igBeginMainMenuBar()) {
|
if (igBeginMainMenuBar()) {
|
||||||
if (igBeginMenu("DEBUG", 1)) {
|
if (igBeginMenu("DEBUG", 1)) {
|
||||||
int tracing = emu->trace_writer ? 1 : 0;
|
if (igMenuItem("frame stats", NULL, emu->frame_stats, 1)) {
|
||||||
const char *tracing_label = tracing ? "stop trace" : "start trace";
|
emu->frame_stats = !emu->frame_stats;
|
||||||
|
}
|
||||||
|
|
||||||
if (igMenuItem(tracing_label, NULL, tracing, 1)) {
|
if ((!emu->trace_writer && igMenuItem("start trace", NULL, 0, 1)) ||
|
||||||
|
(emu->trace_writer && igMenuItem("stop trace", NULL, 1, 1))) {
|
||||||
emu_toggle_tracing(emu);
|
emu_toggle_tracing(emu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -503,6 +511,35 @@ static void emu_paint(struct emu *emu) {
|
||||||
|
|
||||||
igEndMainMenuBar();
|
igEndMainMenuBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (emu->frame_stats) {
|
||||||
|
if (igBegin("frame stats", NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||||
|
/* frame times */
|
||||||
|
{
|
||||||
|
struct ImVec2 graph_size = {300.0f, 50.0f};
|
||||||
|
int num_frame_times = array_size(emu->frame_times);
|
||||||
|
|
||||||
|
float min_time = FLT_MAX;
|
||||||
|
float max_time = -FLT_MAX;
|
||||||
|
float avg_time = 0.0f;
|
||||||
|
for (int i = 0; i < num_frame_times; i++) {
|
||||||
|
float time = emu->frame_times[i];
|
||||||
|
min_time = MIN(min_time, time);
|
||||||
|
max_time = MAX(max_time, time);
|
||||||
|
avg_time += time;
|
||||||
|
}
|
||||||
|
avg_time /= num_frame_times;
|
||||||
|
|
||||||
|
igValueFloat("min time", min_time, "%.2f");
|
||||||
|
igValueFloat("max time", max_time, "%.2f");
|
||||||
|
igValueFloat("avg time", avg_time, "%.2f");
|
||||||
|
igPlotLines("", emu->frame_times, num_frame_times, emu->frame_seq,
|
||||||
|
NULL, 0.0f, 60.0f, graph_size, sizeof(float));
|
||||||
|
}
|
||||||
|
|
||||||
|
igEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -709,9 +746,19 @@ void emu_run_frame(struct emu *emu) {
|
||||||
dc_tick(emu->dc, MACHINE_STEP);
|
dc_tick(emu->dc, MACHINE_STEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
prof_update(time_nanoseconds());
|
int64_t now = time_nanoseconds();
|
||||||
|
|
||||||
|
prof_update(now);
|
||||||
emu_paint(emu);
|
emu_paint(emu);
|
||||||
|
|
||||||
|
if (emu->last_paint) {
|
||||||
|
float frame_time_ms = (float)(now - emu->last_paint) / 1000000.0f;
|
||||||
|
int num_frame_times = array_size(emu->frame_times);
|
||||||
|
emu->frame_times[emu->frame_seq] = frame_time_ms;
|
||||||
|
emu->frame_seq = (emu->frame_seq + 1) % num_frame_times;
|
||||||
|
}
|
||||||
|
|
||||||
|
emu->last_paint = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
int emu_load_game(struct emu *emu, const char *path) {
|
int emu_load_game(struct emu *emu, const char *path) {
|
||||||
|
|
Loading…
Reference in New Issue