Vita: Add supporting framework for mgba-perf
Vicki Pfau vi@endrift.com
Tue, 18 Aug 2020 21:26:35 -0700
4 files changed,
105 insertions(+),
4 deletions(-)
M
src/platform/psp2/CMakeLists.txt
→
src/platform/psp2/CMakeLists.txt
@@ -28,6 +28,7 @@ -lScePhotoExport_stub
-lScePower_stub -lSceSysmodule_stub -lSceTouch_stub) +set(OS_LIB ${OS_LIB} PARENT_SCOPE) set(OBJCOPY_CMD ${OBJCOPY} -I binary -O elf32-littlearm -B arm) list(APPEND GUI_SRC ${CMAKE_CURRENT_SOURCE_DIR}/gui-font.c)@@ -60,6 +61,30 @@ FILE ${CMAKE_CURRENT_SOURCE_DIR}/pic0.png sce_sys/pic0.png
FILE ${CMAKE_CURRENT_SOURCE_DIR}/bg.png sce_sys/livearea/contents/bg.png FILE ${CMAKE_CURRENT_SOURCE_DIR}/startup.png sce_sys/livearea/contents/startup.png FILE ${CMAKE_CURRENT_BINARY_DIR}/template.xml sce_sys/livearea/contents/template.xml) + +if(BUILD_PERF) + add_executable(perf-main.elf perf.c) + set_target_properties(perf-main.elf PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}") + target_link_libraries(perf-main.elf ${OS_LIB}) + + vita_create_self(perf.bin ../${BINARY_NAME}-perf) + vita_create_self(perf-main.self perf-main.elf) + + vita_create_vpk(${BINARY_NAME}-perf.vpk MGBA00002 perf-main.self + NAME "${PROJECT_NAME} Perf Tester" + FILE ${CMAKE_CURRENT_BINARY_DIR}/perf.bin perf.bin + FILE ${CMAKE_CURRENT_SOURCE_DIR}/icon0.png sce_sys/icon0.png + FILE ${CMAKE_CURRENT_SOURCE_DIR}/pic0.png sce_sys/pic0.png + FILE ${CMAKE_CURRENT_SOURCE_DIR}/bg.png sce_sys/livearea/contents/bg.png + FILE ${CMAKE_CURRENT_SOURCE_DIR}/startup.png sce_sys/livearea/contents/startup.png + FILE ${CMAKE_CURRENT_BINARY_DIR}/template.xml sce_sys/livearea/contents/template.xml) + + install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/perf.bin + ${CMAKE_CURRENT_SOURCE_DIR}/perf-start.sh + ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}-perf.vpk + DESTINATION . COMPONENT ${BINARY_NAME}-perf) +endif() install(TARGETS ${BINARY_NAME}.elf DESTINATION . COMPONENT ${BINARY_NAME}-dbg) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}.vpk DESTINATION . COMPONENT ${BINARY_NAME}-psp2)
A
src/platform/psp2/perf-start.sh
@@ -0,0 +1,16 @@
+#!/bin/sh +IP=$1 +shift + +# Kill any previous session +echo | nc $IP 7215 +echo | nc $IP 7216 + +curl -sT perf.bin ftp://$IP:1337/ux0:app/MGBA00002/ +echo launch MGBA00002 | nc $IP 1338 > /dev/null + +sleep 2 + +(for ARG in $@; do + echo $ARG +done; echo) | nc $IP 7215
A
src/platform/psp2/perf.c
@@ -0,0 +1,57 @@
+/* Copyright (c) 2013-2020 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <mgba-util/socket.h> + +#include <psp2/appmgr.h> +#include <psp2/kernel/processmgr.h> +#include <psp2/kernel/threadmgr.h> + +#define MAX_ARGS 19 + + +void connectServer(char* args[]) { + Socket server = SocketOpenTCP(7215, NULL); + if (SOCKET_FAILED(server)) { + return; + } + if (SOCKET_FAILED(SocketListen(server, 0))) { + SocketClose(server); + return; + } + Socket conn = SocketAccept(server, NULL); + if (SOCKET_FAILED(conn)) { + SocketClose(server); + return; + } + + int i = 0; + ssize_t len; + char arg[1024]; + while (i < MAX_ARGS && (len = SocketRecv(conn, arg, sizeof(arg) - 1)) > 0) { + arg[len] = '\0'; + char* tok; + for (tok = strtok(arg, "\n"); tok && i < MAX_ARGS; ++i) { + args[i] = strdup(tok); + tok = strtok(NULL, "\n"); + } + if (arg[len - 1] == '\n') { + return; + } + } + + SocketClose(conn); + SocketClose(server); +} + +int main() { + char* args[MAX_ARGS + 1] = { 0 }; + SocketSubsystemInit(); + connectServer(args); + SocketSubsystemDeinit(); + sceAppMgrLoadExec("app0:/perf.bin", args, NULL); + sceKernelExitProcess(0); + return 0; +}
M
tools/perf.py
→
tools/perf.py
@@ -72,18 +72,20 @@
class PerfServer(object): ITERATIONS_PER_INSTANCE = 50 - def __init__(self, address, command=None): + def __init__(self, address, root='/', command=None): s = address.rsplit(':', 1) if len(s) == 1: self.address = (s[0], 7216) else: self.address = (s[0], s[1]) + self.command = None if command: self.command = shlex.split(command) self.iterations = self.ITERATIONS_PER_INSTANCE self.socket = None self.results = [] self.reader = None + self.root = root def _start(self, test): if self.command:@@ -108,7 +110,7 @@
def run(self, test): if not self.socket: self._start(test) - self.socket.send(os.path.join("/perfroms", test.rom).encode("utf-8")) + self.socket.send(os.path.join(self.root, test.rom).encode("utf-8")) self.results.append(next(self.reader)) self.iterations -= 1 if self.iterations == 0:@@ -178,6 +180,7 @@ parser.add_argument('-T', '--threaded-renderer', action='store_const', const=True, help='threaded video rendering')
parser.add_argument('-s', '--server', metavar='ADDRESS', help='run on server') parser.add_argument('-S', '--server-command', metavar='COMMAND', help='command to launch server') parser.add_argument('-o', '--out', metavar='FILE', help='output file path') + parser.add_argument('-r', '--root', metavar='PATH', type=str, default='/perfroms', help='root path for server mode') parser.add_argument('directory', help='directory containing ROM files') args = parser.parse_args()@@ -189,9 +192,9 @@ renderer = 'threaded-software'
s = Suite(args.directory, wall=args.wall_time, game=args.game_frames, renderer=renderer) if args.server: if args.server_command: - server = PerfServer(args.server, args.server_command) + server = PerfServer(args.server, args.root, args.server_command) else: - server = PerfServer(args.server) + server = PerfServer(args.server, args.root) s.set_server(server) s.collect_tests() results = s.run()