Add more command line options and perf-main duration

This commit is contained in:
Jeffrey Pfau 2014-04-20 22:15:17 -07:00
parent 810c35c318
commit 53389684db
3 changed files with 25 additions and 6 deletions

View File

@ -15,6 +15,7 @@ static const char* _defaultFilename = "test.rom";
static const struct option _options[] = { static const struct option _options[] = {
{ "bios", 1, 0, 'b' }, { "bios", 1, 0, 'b' },
{ "frameskip", 1, 0, 's' },
#ifdef USE_CLI_DEBUGGER #ifdef USE_CLI_DEBUGGER
{ "debug", 1, 0, 'd' }, { "debug", 1, 0, 'd' },
#endif #endif
@ -30,12 +31,11 @@ int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, c
opts->biosFd = -1; opts->biosFd = -1;
opts->width = 240; opts->width = 240;
opts->height = 160; opts->height = 160;
opts->fullscreen = 0;
int multiplier = 1; int multiplier = 1;
int ch; int ch;
char options[64] = char options[64] =
"b:" "b:s:"
#ifdef USE_CLI_DEBUGGER #ifdef USE_CLI_DEBUGGER
"d" "d"
#endif #endif
@ -44,6 +44,7 @@ int parseCommandArgs(struct StartupOptions* opts, int argc, char* const* argv, c
#endif #endif
; ;
if (extraOptions) { if (extraOptions) {
// TODO: modularize options to subparsers
strncat(options, extraOptions, sizeof(options) - strlen(options) - 1); strncat(options, extraOptions, sizeof(options) - strlen(options) - 1);
} }
while ((ch = getopt_long(argc, argv, options, _options, 0)) != -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; opts->debuggerType = DEBUGGER_GDB;
break; break;
#endif #endif
case 's':
opts->frameskip = atoi(optarg);
break;
case 'S':
opts->perfDuration = atoi(optarg);
break;
case '2': case '2':
if (multiplier != 1) { if (multiplier != 1) {
return 0; return 0;

View File

@ -22,6 +22,11 @@ enum DebuggerType {
" -4 4x viewport\n" \ " -4 4x viewport\n" \
" -f Sart full-screen" " -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 { struct StartupOptions {
int fd; int fd;
const char* fname; const char* fname;
@ -34,6 +39,8 @@ struct StartupOptions {
int height; int height;
int fullscreen; int fullscreen;
int perfDuration;
enum DebuggerType debuggerType; enum DebuggerType debuggerType;
int debugAtStart; int debugAtStart;
}; };

View File

@ -18,8 +18,8 @@ int main(int argc, char** argv) {
GBAVideoSoftwareRendererCreate(&renderer); GBAVideoSoftwareRendererCreate(&renderer);
struct StartupOptions opts; struct StartupOptions opts;
if (!parseCommandArgs(&opts, argc, argv, 0)) { if (!parseCommandArgs(&opts, argc, argv, PERF_OPTIONS)) {
usage(argv[0], 0); usage(argv[0], PERF_USAGE);
return 1; return 1;
} }
@ -28,7 +28,6 @@ int main(int argc, char** argv) {
struct GBAThread context = { struct GBAThread context = {
.renderer = &renderer.d, .renderer = &renderer.d,
.frameskip = 0,
.sync.videoFrameWait = 0, .sync.videoFrameWait = 0,
.sync.audioWait = 0 .sync.audioWait = 0
}; };
@ -40,7 +39,7 @@ int main(int argc, char** argv) {
GBAThreadStart(&context); GBAThreadStart(&context);
int frames = 0; int frames = opts.perfDuration;
time_t start = time(0); time_t start = time(0);
_GBAPerfRunloop(&context, &frames); _GBAPerfRunloop(&context, &frames);
time_t end = time(0); time_t end = time(0);
@ -63,6 +62,8 @@ int main(int argc, char** argv) {
static void _GBAPerfRunloop(struct GBAThread* context, int* frames) { static void _GBAPerfRunloop(struct GBAThread* context, int* frames) {
struct timeval lastEcho; struct timeval lastEcho;
gettimeofday(&lastEcho, 0); gettimeofday(&lastEcho, 0);
int duration = *frames;
*frames = 0;
int lastFrames = 0; int lastFrames = 0;
while (context->state < THREAD_EXITING) { while (context->state < THREAD_EXITING) {
if (GBASyncWaitFrameStart(&context->sync, 0)) { if (GBASyncWaitFrameStart(&context->sync, 0)) {
@ -82,7 +83,11 @@ static void _GBAPerfRunloop(struct GBAThread* context, int* frames) {
} }
} }
GBASyncWaitFrameEnd(&context->sync); GBASyncWaitFrameEnd(&context->sync);
if (*frames == duration * 60) {
_GBAPerfShutdown(0);
}
} }
printf("\033[2K\r");
} }
static void _GBAPerfShutdown(int signal) { static void _GBAPerfShutdown(int signal) {