From 7ada7dd2a8da901126dbb1d8409a735e6b476491 Mon Sep 17 00:00:00 2001 From: Itms Date: Tue, 9 Sep 2014 18:17:08 +0000 Subject: [PATCH] Some tweaks to profiler2: * separate the HTTP profiling server from the on-screen profiler * allow shutting down the HTTP profiler * print messages when enabling/disabling HTTP and GPU profilers Patch by kingbasil, fixes #1862 This was SVN commit r15723. --- binaries/data/config/default.cfg | 5 ++--- source/main.cpp | 5 ++--- source/ps/GameSetup/GameSetup.cpp | 4 ++-- source/ps/Profiler2.cpp | 32 ++++++++++++++++++++++++++++++- source/ps/Profiler2.h | 12 +++++++++++- 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index 8cd45515ac..b853ff0873 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -328,11 +328,10 @@ hotkey.text.move.right = "Ctrl+RightArrow" ; Move cursor to start of word to ; > PROFILER hotkey.profile.toggle = "F11" ; Enable/disable real-time profiler hotkey.profile.save = "Shift+F11" ; Save current profiler data to logs/profile.txt -hotkey.profile2.enable = "F11" ; Enable HTTP/GPU modes for new profiler +hotkey.profile2.toggle = "Ctrl+F11" ; Enable/disable HTTP/GPU modes for new profiler -profiler2.http.autoenable = false ; Enable HTTP server output at startup (default off for security/performance) +profiler2.autoenable = false ; Enable HTTP server output at startup (default off for security/performance) profiler2.script.enable = false ; Enable Javascript profiling. Needs to be set before startup and can't be changed later. (default off for performance) -profiler2.gpu.autoenable = false ; Enable GPU timing at startup (default off for performance/compatibility) profiler2.gpu.arb.enable = true ; Allow GL_ARB_timer_query timing mode when available profiler2.gpu.ext.enable = true ; Allow GL_EXT_timer_query timing mode when available profiler2.gpu.intel.enable = true ; Allow GL_INTEL_performance_queries timing mode when available diff --git a/source/main.cpp b/source/main.cpp index a999125b7c..b037dfd805 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -161,10 +161,9 @@ static InReaction MainInputHandler(const SDL_Event_* ev) #endif return IN_HANDLED; } - else if (hotkey == "profile2.enable") + else if (hotkey == "profile2.toggle") { - g_Profiler2.EnableGPU(); - g_Profiler2.EnableHTTP(); + g_Profiler2.Toggle(); return IN_HANDLED; } break; diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 9152bb4003..f1ff24a0ff 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -955,7 +955,7 @@ bool Init(const CmdLineArgs& args, int flags) // Optionally start profiler HTTP output automatically // (By default it's only enabled by a hotkey, for security/performance) bool profilerHTTPEnable = false; - CFG_GET_VAL("profiler2.http.autoenable", Bool, profilerHTTPEnable); + CFG_GET_VAL("profiler2.autoenable", Bool, profilerHTTPEnable); if (profilerHTTPEnable) g_Profiler2.EnableHTTP(); @@ -992,7 +992,7 @@ void InitGraphics(const CmdLineArgs& args, int flags) // Optionally start profiler GPU timings automatically // (By default it's only enabled by a hotkey, for performance/compatibility) bool profilerGPUEnable = false; - CFG_GET_VAL("profiler2.gpu.autoenable", Bool, profilerGPUEnable); + CFG_GET_VAL("profiler2.autoenable", Bool, profilerGPUEnable); if (profilerGPUEnable) g_Profiler2.EnableGPU(); diff --git a/source/ps/Profiler2.cpp b/source/ps/Profiler2.cpp index 70eae0c1a2..ae49b0c8ff 100644 --- a/source/ps/Profiler2.cpp +++ b/source/ps/Profiler2.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 Wildfire Games +/* Copyright (c) 2014 Wildfire Games * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -157,6 +157,7 @@ void CProfiler2::InitialiseGPU() void CProfiler2::EnableHTTP() { ENSURE(m_Initialised); + LOGMESSAGERENDER(L"Starting profiler2 HTTP server"); // Ignore multiple enablings if (m_MgContext) @@ -175,14 +176,43 @@ void CProfiler2::EnableGPU() { ENSURE(m_Initialised); if (!m_GPU) + { + LOGMESSAGERENDER(L"Starting profiler2 GPU mode"); InitialiseGPU(); + } } void CProfiler2::ShutdownGPU() { + LOGMESSAGERENDER(L"Shutting down profiler2 GPU mode"); SAFE_DELETE(m_GPU); } +void CProfiler2::ShutDownHTTP() +{ + LOGMESSAGERENDER(L"Shutting down profiler2 HTTP server"); + if (m_MgContext) + { + mg_stop(m_MgContext); + m_MgContext = NULL; + } +} + +void CProfiler2::Toggle() +{ + // TODO: Maybe we can open the browser to the profiler page automatically + if (m_GPU && m_MgContext) + { + ShutdownGPU(); + ShutDownHTTP(); + } + else if (!m_GPU && !m_MgContext) + { + EnableGPU(); + EnableHTTP(); + } +} + void CProfiler2::Shutdown() { ENSURE(m_Initialised); diff --git a/source/ps/Profiler2.h b/source/ps/Profiler2.h index 64f197b732..a1228b379b 100644 --- a/source/ps/Profiler2.h +++ b/source/ps/Profiler2.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 Wildfire Games +/* Copyright (c) 2014 Wildfire Games * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -275,6 +275,16 @@ public: */ void ShutdownGPU(); + /** + * Call in main thread to shut down the profiler's HTTP server + */ + void ShutDownHTTP(); + + /** + * Call in main thread to enable/disable the profiler + */ + void Toggle(); + /** * Call in main thread to shut everything down. * All other profiled threads should have been terminated already.