Make Profiler2 configurable in visual mode. Non visual doesn't load the config so it's not possible. Also update the profiler2 page to be able to change the port

Differential Revision: https://code.wildfiregames.com/D2444
This was SVN commit r24340.
This commit is contained in:
Stan 2020-12-07 08:11:23 +00:00
parent d92a2118b0
commit 421fbfd278
5 changed files with 37 additions and 9 deletions

View File

@ -135,6 +135,11 @@ skycolor = "0 0 0"
session = 60 ; Throttle FPS in running games (prevents 100% CPU workload). session = 60 ; Throttle FPS in running games (prevents 100% CPU workload).
menu = 60 ; Throttle FPS in menus only. menu = 60 ; Throttle FPS in menus only.
[profiler2]
server = "127.0.0.1"
server.port = "8000" ; Use a free port on your machine.
server.threads = "6" ; Enough for the browser's parallel connection limit
[hotkey] [hotkey]
; Each one of the specified keys will trigger the action on the left ; Each one of the specified keys will trigger the action on the left
; for multiple-key combinations, separate keys with '+'. ; for multiple-key combinations, separate keys with '+'.

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2019 Wildfire Games. /* Copyright (C) 2020 Wildfire Games.
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
@ -27,6 +27,7 @@
#include "lib/allocators/shared_ptr.h" #include "lib/allocators/shared_ptr.h"
#include "lib/os_path.h" #include "lib/os_path.h"
#include "ps/CLogger.h" #include "ps/CLogger.h"
#include "ps/ConfigDB.h"
#include "ps/CStr.h" #include "ps/CStr.h"
#include "ps/Profiler2GPU.h" #include "ps/Profiler2GPU.h"
#include "ps/Pyrogenesis.h" #include "ps/Pyrogenesis.h"
@ -178,10 +179,21 @@ void CProfiler2::EnableHTTP()
if (m_MgContext) if (m_MgContext)
return; return;
CStr listeningPort = "8000";
CStr listeningServer = "127.0.0.1";
CStr numThreads = "6";
if (CConfigDB::IsInitialised())
{
CFG_GET_VAL("profiler2.server.port", listeningPort);
CFG_GET_VAL("profiler2.server", listeningServer);
CFG_GET_VAL("profiler2.server.threads", numThreads);
}
std::string listening_ports = fmt::format("{0}:{1}", listeningServer, listeningPort);
const char* options[] = { const char* options[] = {
"listening_ports", "127.0.0.1:8000", // bind to localhost for security "listening_ports", listening_ports.c_str(),
"num_threads", "6", // enough for the browser's parallel connection limit "num_threads", numThreads.c_str(),
NULL nullptr
}; };
m_MgContext = mg_start(MgCallback, this, options); m_MgContext = mg_start(MgCallback, this, options);
ENSURE(m_MgContext); ENSURE(m_MgContext);
@ -922,6 +934,8 @@ const char* CProfiler2::ConstructJSONResponse(std::ostream& stream, const std::s
void CProfiler2::SaveToFile() void CProfiler2::SaveToFile()
{ {
OsPath path = psLogDir()/"profile2.jsonp"; OsPath path = psLogDir()/"profile2.jsonp";
debug_printf("Writing profile data to %s \n", path.string8().c_str());
LOGMESSAGERENDER("Writing profile data to %s \n", path.string8().c_str());
std::ofstream stream(OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc); std::ofstream stream(OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc);
ENSURE(stream.good()); ENSURE(stream.good());

View File

@ -91,7 +91,7 @@ function refresh_from_jsonp(callback, content)
function refresh_live(callback, file) function refresh_live(callback, file)
{ {
$.ajax({ $.ajax({
url: 'http://127.0.0.1:8000/overview', url: `http://127.0.0.1:${$("#gameport").val()}/overview`,
dataType: 'json', dataType: 'json',
success: function (data) { success: function (data) {
var threads = []; var threads = [];
@ -115,7 +115,7 @@ function refresh_live(callback, file)
function refresh_thread(callback, thread, callback_data) function refresh_thread(callback, thread, callback_data)
{ {
$.ajax({ $.ajax({
url: 'http://127.0.0.1:8000/query', url: `http://127.0.0.1:${$("#gameport").val()}/query`,
dataType: 'json', dataType: 'json',
data: { 'thread': thread.name }, data: { 'thread': thread.name },
success: function (data) { success: function (data) {

View File

@ -1,5 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en">
<head> <head>
<meta charset="utf-8"/>
<title>0 A.D. profiler UI</title> <title>0 A.D. profiler UI</title>
<script src="jquery-1.6.4.js"></script> <script src="jquery-1.6.4.js"></script>
<script src="utilities.js"></script> <script src="utilities.js"></script>
@ -45,6 +47,8 @@ header nav p.active { cursor:pointer; background:#eee; box-shadow: 0px 0px 2px 0
</head> </head>
<body> <body>
<button onclick="save_as_file()">Save Live Report to file</button> <button onclick="save_as_file()">Save Live Report to file</button>
<label for="gameport">Port:</label>
<input id="gameport" type="text" value="8000" onchange="updatePort()">
<header> <header>
<h1>Open reports</h1> <h1>Open reports</h1>

View File

@ -34,7 +34,7 @@ var g_loading_timeout = null;
function save_as_file() function save_as_file()
{ {
$.ajax({ $.ajax({
url: 'http://127.0.0.1:8000/download', url: `http://127.0.0.1:${$("#gameport").val()}/download`,
success: function () { success: function () {
}, },
error: function (jqXHR, textStatus, errorThrown) { error: function (jqXHR, textStatus, errorThrown) {
@ -501,3 +501,8 @@ window.onload = function()
// add new reports // add new reports
document.getElementById('report_load_input').addEventListener('change', load_report_from_file, false); document.getElementById('report_load_input').addEventListener('change', load_report_from_file, false);
} }
function updatePort() {
document.location.reload();
}