Add per-second perf updating

This commit is contained in:
Jeffrey Pfau 2013-11-04 21:07:41 -08:00
parent 3b74b61862
commit 3005c6c9fb
2 changed files with 19 additions and 1 deletions

View File

@ -4,6 +4,7 @@ set(BINARY_NAME gbac CACHE INTERNAL "Name of output binaries")
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Wextra -Wno-error=type-limits --std=gnu99") set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Wextra -Wno-error=type-limits --std=gnu99")
set(CMAKE_C_FLAGS_RELEASE "-O3 -Wall -Wextra --std=gnu99") set(CMAKE_C_FLAGS_RELEASE "-O3 -Wall -Wextra --std=gnu99")
set(USE_DEBUGGER ON CACHE BOOL "Whether or not to enable the ARM debugger") set(USE_DEBUGGER ON CACHE BOOL "Whether or not to enable the ARM debugger")
set(EXTRA_LIB "")
file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c) file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c)
file(GLOB GBA_SRC ${CMAKE_SOURCE_DIR}/src/gba/*.c) file(GLOB GBA_SRC ${CMAKE_SOURCE_DIR}/src/gba/*.c)
file(GLOB UTIL_SRC ${CMAKE_SOURCE_DIR}/src/util/*.c) file(GLOB UTIL_SRC ${CMAKE_SOURCE_DIR}/src/util/*.c)
@ -42,7 +43,8 @@ endif()
if(BUILD_PERF) if(BUILD_PERF)
set(MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/perf-main.c) set(MAIN_SRC ${CMAKE_SOURCE_DIR}/src/platform/perf-main.c)
set(EXTRA_LIB ${EXTRA_LIB} rt)
endif() endif()
add_executable(${BINARY_NAME} ${ARM_SRC} ${GBA_SRC} ${DEBUGGER_SRC} ${RENDERER_SRC} ${UTIL_SRC} ${PLATFORM_SRC} ${MAIN_SRC}) add_executable(${BINARY_NAME} ${ARM_SRC} ${GBA_SRC} ${DEBUGGER_SRC} ${RENDERER_SRC} ${UTIL_SRC} ${PLATFORM_SRC} ${MAIN_SRC})
target_link_libraries(${BINARY_NAME} m pthread ${DEBUGGER_LIB} ${SDL_LIBRARY} ${OPENGL_LIBRARY}) target_link_libraries(${BINARY_NAME} m pthread ${DEBUGGER_LIB} ${SDL_LIBRARY} ${OPENGL_LIBRARY} ${EXTRA_LIB})

View File

@ -62,9 +62,25 @@ int main(int argc, char** argv) {
} }
static void _GBAPerfRunloop(struct GBAThread* context, int* frames) { static void _GBAPerfRunloop(struct GBAThread* context, int* frames) {
struct timespec lastEcho;
clock_gettime(CLOCK_REALTIME, &lastEcho);
int lastFrames = 0;
while (context->state < THREAD_EXITING) { while (context->state < THREAD_EXITING) {
if (GBASyncWaitFrameStart(&context->sync, 0)) { if (GBASyncWaitFrameStart(&context->sync, 0)) {
++*frames; ++*frames;
++lastFrames;
struct timespec currentTime;
long timeDiff;
clock_gettime(CLOCK_REALTIME, &currentTime);
timeDiff = currentTime.tv_sec - lastEcho.tv_sec;
timeDiff *= 1000;
timeDiff += (currentTime.tv_nsec - lastEcho.tv_nsec) / 1000000;
if (timeDiff >= 1000) {
printf("\033[2K\rCurrent FPS: %g (%gx)", lastFrames / (timeDiff / 1000.0f), lastFrames / (float) (60 * (timeDiff / 1000.0f)));
fflush(stdout);
lastEcho = currentTime;
lastFrames = 0;
}
} }
GBASyncWaitFrameEnd(&context->sync); GBASyncWaitFrameEnd(&context->sync);
} }