diff --git a/src/platform/commandline.c b/src/platform/commandline.c index 89789e5fe..852648444 100644 --- a/src/platform/commandline.c +++ b/src/platform/commandline.c @@ -15,6 +15,7 @@ static const char* _defaultFilename = "test.rom"; static const struct option _options[] = { { "bios", 1, 0, 'b' }, + { "frameskip", 1, 0, 's' }, #ifdef USE_CLI_DEBUGGER { "debug", 1, 0, 'd' }, #endif @@ -30,12 +31,11 @@ int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, c opts->biosFd = -1; opts->width = 240; opts->height = 160; - opts->fullscreen = 0; int multiplier = 1; int ch; char options[64] = - "b:" + "b:s:" #ifdef USE_CLI_DEBUGGER "d" #endif @@ -44,6 +44,7 @@ int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, c #endif ; if (extraOptions) { + // TODO: modularize options to subparsers strncat(options, extraOptions, sizeof(options) - strlen(options) - 1); } while ((ch = getopt_long(argc, argv, options, _options, 0)) != -1) { @@ -70,6 +71,12 @@ int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, c opts->debuggerType = DEBUGGER_GDB; break; #endif + case 's': + opts->frameskip = atoi(optarg); + break; + case 'S': + opts->perfDuration = atoi(optarg); + break; case '2': if (multiplier != 1) { return 0; diff --git a/src/platform/commandline.h b/src/platform/commandline.h index d91adbf0a..01d53336a 100644 --- a/src/platform/commandline.h +++ b/src/platform/commandline.h @@ -22,6 +22,11 @@ enum DebuggerType { " -4 4x viewport\n" \ " -f Sart full-screen" +#define PERF_OPTIONS "S:" +#define PERF_USAGE \ + "\nBenchmark options:\n" \ + " -S SEC Run for SEC in-game seconds before exiting" + struct StartupOptions { int fd; const char* fname; @@ -34,6 +39,8 @@ struct StartupOptions { int height; int fullscreen; + int perfDuration; + enum DebuggerType debuggerType; int debugAtStart; }; diff --git a/src/platform/perf-main.c b/src/platform/perf-main.c index 521e276e6..770077abf 100644 --- a/src/platform/perf-main.c +++ b/src/platform/perf-main.c @@ -18,8 +18,8 @@ int main(int argc, char** argv) { GBAVideoSoftwareRendererCreate(&renderer); struct StartupOptions opts; - if (!parseCommandArgs(&opts, argc, argv, 0)) { - usage(argv[0], 0); + if (!parseCommandArgs(&opts, argc, argv, PERF_OPTIONS)) { + usage(argv[0], PERF_USAGE); return 1; } @@ -28,7 +28,6 @@ int main(int argc, char** argv) { struct GBAThread context = { .renderer = &renderer.d, - .frameskip = 0, .sync.videoFrameWait = 0, .sync.audioWait = 0 }; @@ -40,7 +39,7 @@ int main(int argc, char** argv) { GBAThreadStart(&context); - int frames = 0; + int frames = opts.perfDuration; time_t start = time(0); _GBAPerfRunloop(&context, &frames); time_t end = time(0); @@ -63,6 +62,8 @@ int main(int argc, char** argv) { static void _GBAPerfRunloop(struct GBAThread* context, int* frames) { struct timeval lastEcho; gettimeofday(&lastEcho, 0); + int duration = *frames; + *frames = 0; int lastFrames = 0; while (context->state < THREAD_EXITING) { if (GBASyncWaitFrameStart(&context->sync, 0)) { @@ -82,7 +83,11 @@ static void _GBAPerfRunloop(struct GBAThread* context, int* frames) { } } GBASyncWaitFrameEnd(&context->sync); + if (*frames == duration * 60) { + _GBAPerfShutdown(0); + } } + printf("\033[2K\r"); } static void _GBAPerfShutdown(int signal) {