Add more command line options and perf-main duration
Jeffrey Pfau jeffrey@endrift.com
Sun, 20 Apr 2014 22:15:17 -0700
3 files changed,
25 insertions(+),
6 deletions(-)
M
src/platform/commandline.c
→
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 @@ opts->fd = -1;
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 @@ "g"
#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 @@ }
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;
M
src/platform/commandline.h
→
src/platform/commandline.h
@@ -22,6 +22,11 @@ " -3 3x viewport\n" \
" -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;@@ -33,6 +38,8 @@
int width; int height; int fullscreen; + + int perfDuration; enum DebuggerType debuggerType; int debugAtStart;
M
src/platform/perf-main.c
→
src/platform/perf-main.c
@@ -18,8 +18,8 @@ struct GBAVideoSoftwareRenderer renderer;
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 @@ renderer.outputBufferStride = 256;
struct GBAThread context = { .renderer = &renderer.d, - .frameskip = 0, .sync.videoFrameWait = 0, .sync.audioWait = 0 };@@ -40,7 +39,7 @@ GBAMapOptionsToContext(&opts, &context);
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 @@
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 @@ lastFrames = 0;
} } GBASyncWaitFrameEnd(&context->sync); + if (*frames == duration * 60) { + _GBAPerfShutdown(0); + } } + printf("\033[2K\r"); } static void _GBAPerfShutdown(int signal) {