From 44a0008d4e8f80fce9697bbde09193e837bc0072 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Mon, 17 Oct 2011 00:16:43 +0100 Subject: [PATCH] Debug performance/time graph --- includes/defines.h | 11 +++++++++- src/graphics.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 51 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 113 insertions(+), 2 deletions(-) diff --git a/includes/defines.h b/includes/defines.h index 667ad69d1..62e0c481b 100644 --- a/includes/defines.h +++ b/includes/defines.h @@ -138,6 +138,8 @@ typedef unsigned int pixel; #define DEBUG_PARTS 0x0001 #define DEBUG_PARTCOUNT 0x0002 #define DEBUG_DRAWTOOL 0x0004 +#define DEBUG_PERFORMANCE_CALC 0x0008 +#define DEBUG_PERFORMANCE_FRAME 0x0010 typedef unsigned char uint8; @@ -161,11 +163,18 @@ extern int kiosk_enable; extern int aheat_enable; extern int decorations_enable; extern int hud_enable; -extern int debug_flags; extern int pretty_powder; int limitFPS; int water_equal_test; +extern int debug_flags; +#define DEBUG_PERF_FRAMECOUNT 256 +extern int debug_perf_istart; +extern int debug_perf_iend; +extern long debug_perf_frametime[DEBUG_PERF_FRAMECOUNT]; +extern long debug_perf_partitime[DEBUG_PERF_FRAMECOUNT]; +extern long debug_perf_time; + extern int active_menu; extern int sys_pause; diff --git a/src/graphics.c b/src/graphics.c index 5d7354dd4..60572dc48 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -2718,6 +2718,59 @@ int sdl_open(void) int draw_debug_info(pixel* vid, int lm, int lx, int ly, int cx, int cy, int line_x, int line_y) { char infobuf[256]; + if(debug_flags & DEBUG_PERFORMANCE_FRAME || debug_flags & DEBUG_PERFORMANCE_CALC) + { + int t1, t2, x = 0, i = debug_perf_istart; + float partiavg = 0, frameavg = 0; + while(i != debug_perf_iend) + { + partiavg += abs(debug_perf_partitime[i]/100000); + frameavg += abs(debug_perf_frametime[i]/100000); + if(debug_flags & DEBUG_PERFORMANCE_CALC) + t1 = abs(debug_perf_partitime[i]/100000); + else + t1 = 0; + + if(debug_flags & DEBUG_PERFORMANCE_FRAME) + t2 = abs(debug_perf_frametime[i]/100000); + else + t2 = 0; + + if(t1 > YRES) + t1 = YRES; + if(t1+t2 > YRES) + t2 = YRES-t1; + + if(t1>0) + draw_line(vid, x, YRES, x, YRES-t1, 0, 255, 120, XRES+BARSIZE); + if(t2>0) + draw_line(vid, x, YRES-t1, x, YRES-(t1+t2), 255, 120, 0, XRES+BARSIZE); + + i++; + x++; + i %= DEBUG_PERF_FRAMECOUNT; + } + + if(debug_flags & DEBUG_PERFORMANCE_CALC) + t1 = abs(partiavg / x); + else + t1 = 0; + + if(debug_flags & DEBUG_PERFORMANCE_FRAME) + t2 = abs(frameavg / x); + else + t2 = 0; + + if(t1 > YRES) + t1 = YRES; + if(t1+t2 > YRES) + t2 = YRES-t1; + + if(t1>0) + fillrect(vid, x, YRES-t1-1, 5, t1+2, 0, 255, 0, 255); + if(t2>0) + fillrect(vid, x, (YRES-t1)-t2-1, 5, t2+1, 255, 0, 0, 255); + } if(debug_flags & DEBUG_DRAWTOOL) { if(lm == 1) //Line tool diff --git a/src/main.c b/src/main.c index 09dfffd0e..2615e4fd2 100644 --- a/src/main.c +++ b/src/main.c @@ -187,8 +187,13 @@ int frameidx = 0; //int CGOL = 0; //int GSPEED = 1;//causes my .exe to crash.. int sound_enable = 0; -int debug_flags = 0; +int debug_flags = 0; +int debug_perf_istart = 1; +int debug_perf_iend = 0; +long debug_perf_frametime[DEBUG_PERF_FRAMECOUNT]; +long debug_perf_partitime[DEBUG_PERF_FRAMECOUNT]; +long debug_perf_time = 0; sign signs[MAXSIGNS]; @@ -1813,8 +1818,52 @@ int main(int argc, char *argv[]) if(ngrav_enable && drawgrav_enable) draw_grav(vid_buf); draw_walls(part_vbuf); + + if(debug_flags & (DEBUG_PERFORMANCE_CALC|DEBUG_PERFORMANCE_FRAME)) + { + #ifdef WIN32 + #elif defined(MACOSX) + #else + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + debug_perf_time = ts.tv_nsec; + #endif + } + update_particles(part_vbuf); //update everything + + if(debug_flags & (DEBUG_PERFORMANCE_CALC|DEBUG_PERFORMANCE_FRAME)) + { + #ifdef WIN32 + #elif defined(MACOSX) + #else + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + + debug_perf_partitime[debug_perf_iend] = ts.tv_nsec - debug_perf_time; + + debug_perf_time = ts.tv_nsec; + #endif + } + render_parts(part_vbuf); //draw particles + + if(debug_flags & (DEBUG_PERFORMANCE_CALC|DEBUG_PERFORMANCE_FRAME)) + { + #ifdef WIN32 + #elif defined(MACOSX) + #else + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + + debug_perf_frametime[debug_perf_iend] = ts.tv_nsec - debug_perf_time; + #endif + debug_perf_iend++; + debug_perf_iend %= DEBUG_PERF_FRAMECOUNT; + debug_perf_istart++; + debug_perf_istart %= DEBUG_PERF_FRAMECOUNT; + } + if(sl == WL_GRAV+100 || sr == WL_GRAV+100) draw_grav_zones(part_vbuf);