Reinstate filter based deferred profiling

Allow for collection to be deferred until a profiler is connected.
master
Beq 2021-10-12 10:48:12 +01:00
parent cf80612b7d
commit b8ceff16bb
6 changed files with 105 additions and 35 deletions

View File

@ -0,0 +1,31 @@
/**
* @file llprofiler.cpp
* @brief llprofiler Telemetry abstraction
*
* $LicenseInfo:firstyear=2021&license=fsviewerlgpl$
* Phoenix Firestorm Viewer Source Code
* Copyright (C) 2021, The Phoenix Firestorm Project, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* The Phoenix Firestorm Project, Inc., 1831 Oakwood Drive, Fairmont, Minnesota 56031-3225 USA
* http://www.firestormviewer.org
* $/LicenseInfo$
*/
#include "llprofiler.h"
namespace LLProfiler
{
bool active{false};
}

View File

@ -36,6 +36,12 @@
#define LL_PROFILER_CONFIGURATION LL_PROFILER_CONFIG_FAST_TIMER
#endif
// <FS:Beq> active switch for deferred profiling
namespace LLProfiler
{
extern bool active;
}
// </FS:Beq>
#if defined(LL_PROFILER_CONFIGURATION) && (LL_PROFILER_CONFIGURATION > LL_PROFILER_CONFIG_NONE)
#if LL_PROFILER_CONFIGURATION == LL_PROFILER_CONFIG_TRACY || LL_PROFILER_CONFIGURATION == LL_PROFILER_CONFIG_TRACY_FAST_TIMER
#define TRACY_ENABLE 1
@ -57,13 +63,19 @@
#define LL_PROFILER_SET_THREAD_NAME( name ) tracy::SetThreadName( name )
#define LL_PROFILER_THREAD_BEGIN(name) FrameMarkStart( name ) // C string
#define LL_PROFILER_THREAD_END(name) FrameMarkEnd( name ) // C string
// <FS:Beq> revert change that obscures custom FTM zones.
// #define LL_RECORD_BLOCK_TIME(name) ZoneScoped // Want descriptive names; was: ZoneNamedN( ___tracy_scoped_zone, #name, true );
#define LL_RECORD_BLOCK_TIME(name) ZoneNamedN( ___tracy_scoped_zone, #name, true )
// <FS:Beq> revert change that obscures custom FTM zones. We may want to may FTM Zones unique in future.
// #define LL_RECORD_BLOCK_TIME(name) ZoneScoped // Want descriptive names; was: ZoneNamedN( ___tracy_scoped_zone, #name, LLProfiler::active );
#define LL_RECORD_BLOCK_TIME(name) ZoneNamedN( ___tracy_scoped_zone, #name, LLProfiler::active )
// </FS:Beq>
// <FS:Beq>
// #define LL_PROFILE_ZONE_NAMED(name) ZoneNamedN( ___tracy_scoped_zone, name, true )
// #define LL_PROFILE_ZONE_NAMED_COLOR(name,color) ZoneNamedNC( ___tracy_scopped_zone, name, color, true ) // RGB
// #define LL_PROFILE_ZONE_SCOPED ZoneScoped
#define LL_PROFILE_ZONE_NAMED(name) ZoneNamedN( ___tracy_scoped_zone, name, LLProfiler::active )
#define LL_PROFILE_ZONE_NAMED_COLOR(name,color) ZoneNamedNC( ___tracy_scopped_zone, name, color, LLProfiler::active ) // RGB
#define LL_PROFILE_ZONE_SCOPED ZoneNamed( ___tracy_scoped_zone, LLProfiler::active ) // <FS:Beq/> Enable deferred collection through filters
// </FS:Beq>
#define LL_PROFILE_ZONE_NAMED(name) ZoneNamedN( ___tracy_scoped_zone, name, true )
#define LL_PROFILE_ZONE_NAMED_COLOR(name,color) ZoneNamedNC( ___tracy_scopped_zone, name, color, true ) // RGB
#define LL_PROFILE_ZONE_SCOPED ZoneScoped
#define LL_PROFILE_ZONE_NUM( val ) ZoneValue( val )
#define LL_PROFILE_ZONE_TEXT( text, size ) ZoneText( text, size )
@ -73,7 +85,7 @@
#define LL_PROFILE_ZONE_WARN(name) LL_PROFILE_ZONE_NAMED_COLOR( name, 0x0FFFF00 ) // RGB red
// <FS:Beq> Additional FS Tracy macros
#define LL_PROFILE_ZONE_COLOR(color) ZoneNamedC( ___tracy_scoped_zone, color, true ) // <FS:Beq> Additional Tracy macro
#define LL_PROFILE_ZONE_COLOR(color) ZoneNamedC( ___tracy_scoped_zone, color, LLProfiler::active ) // <FS:Beq/> Additional Tracy macro
#define LL_PROFILE_PLOT( name, value ) TracyPlot( name, value)
#define LL_PROFILE_PLOT_SQ( name, prev, value ) TracyPlot(name,prev);TracyPlot( name, value)
#define LL_PROFILE_IS_CONNECTED TracyIsConnected
@ -114,11 +126,16 @@
// <FS:Beq> revert change that obscures custom FTM zones.
// #define LL_RECORD_BLOCK_TIME(name) ZoneScoped const LLTrace::BlockTimer& LL_GLUE_TOKENS(block_time_recorder, __LINE__)(LLTrace::timeThisBlock(name)); (void)LL_GLUE_TOKENS(block_time_recorder, __LINE__);
#define LL_RECORD_BLOCK_TIME(name) ZoneNamedN( ___tracy_scoped_zone, #name, true ); const LLTrace::BlockTimer& LL_GLUE_TOKENS(block_time_recorder, __LINE__)(LLTrace::timeThisBlock(name)); (void)LL_GLUE_TOKENS(block_time_recorder, __LINE__);
#define LL_RECORD_BLOCK_TIME(name) ZoneNamedN( ___tracy_scoped_zone, #name, LLProfiler::active ); const LLTrace::BlockTimer& LL_GLUE_TOKENS(block_time_recorder, __LINE__)(LLTrace::timeThisBlock(name)); (void)LL_GLUE_TOKENS(block_time_recorder, __LINE__);
// </FS:Beq>
// <FS:Beq>
// #define LL_PROFILE_ZONE_NAMED(name) ZoneNamedN( ___tracy_scoped_zone, name, true )
// #define LL_PROFILE_ZONE_NAMED_COLOR(name,color) ZoneNamedNC( ___tracy_scopped_zone, name, color, true ) // RGB
// #define LL_PROFILE_ZONE_SCOPED ZoneScoped
#define LL_PROFILE_ZONE_NAMED(name) ZoneNamedN( ___tracy_scoped_zone, name, LLProfiler::active );
#define LL_PROFILE_ZONE_NAMED_COLOR(name,color) ZoneNamedNC( ___tracy_scopped_zone, name, color, LLProfiler::active ) // RGB
#define LL_PROFILE_ZONE_SCOPED ZoneNamed( ___tracy_scoped_zone, LLProfiler::active ) // <FS:Beq/> Enable deferred collection through filters
// </FS:Beq>
#define LL_PROFILE_ZONE_NAMED(name) ZoneNamedN( ___tracy_scoped_zone, name, true );
#define LL_PROFILE_ZONE_NAMED_COLOR(name,color) ZoneNamedNC( ___tracy_scopped_zone, name, color, true ) // RGB
#define LL_PROFILE_ZONE_SCOPED ZoneScoped
#define LL_PROFILE_ZONE_NUM( val ) ZoneValue( val )
#define LL_PROFILE_ZONE_TEXT( text, size ) ZoneText( text, size )
@ -127,7 +144,7 @@
#define LL_PROFILE_ZONE_INFO(name) LL_PROFILE_ZONE_NAMED_COLOR( name, 0X00FFFF ) // RGB cyan
#define LL_PROFILE_ZONE_WARN(name) LL_PROFILE_ZONE_NAMED_COLOR( name, 0x0FFFF00 ) // RGB red
// <FS:Beq> Additional FS Tracy macros
#define LL_PROFILE_ZONE_COLOR(color) ZoneNamedC( ___tracy_scoped_zone, color, true )
#define LL_PROFILE_ZONE_COLOR(color) ZoneNamedC( ___tracy_scoped_zone, color, LLProfiler::active )
#define LL_PROFILE_PLOT( name, value ) TracyPlot( name, value)
#define LL_PROFILE_PLOT_SQ( name, prev, value ) TracyPlot( name, prev );TracyPlot( name, value )
#define LL_PROFILE_IS_CONNECTED TracyIsConnected

View File

@ -24657,10 +24657,10 @@ Change of this parameter will affect the layout of buttons in notification toast
<key>Value</key>
<integer>0</integer>
</map>
<key>FSTelemetryEnableWhenConnected</key>
<key>DeferProfilingUntilConnected</key>
<map>
<key>Comment</key>
<string>Enable telemetry as soon as a server connects</string>
<string>Enable profiling data collection only after server connects. Lowers memory overhead and allows profiling from a specific point in time</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
@ -24668,10 +24668,10 @@ Change of this parameter will affect the layout of buttons in notification toast
<key>Value</key>
<integer>1</integer>
</map>
<key>FSTelemetryActive</key>
<key>ProfilingActive</key>
<map>
<key>Comment</key>
<string>Enable profiling as soon as a server connects. Off by default and non-persistent. Use with FSTelemetryEnableWhenConnected to initiate on startup</string>
<string>notes whether profiling is currently active. Used by the dev menu item</string>
<key>Persist</key>
<integer>0</integer>
<key>Type</key>

View File

@ -1635,24 +1635,35 @@ bool LLAppViewer::doFrame()
LLEventPump& mainloop(LLEventPumps::instance().obtain("mainloop"));
LLSD newFrame;
// <FS:Beq> telemetry enabling.
// <FS:Beq> profiling enablement.
// This ifdef is optional but better to avoid even low overhead code in main loop where not needed.
#ifdef FS_HAS_TELEMETRY_SUPPORT
#ifdef TRACY_ENABLE
static bool one_time{false};
static LLCachedControl<bool> profiling_enabled_when_connected(gSavedSettings, "FSTelemetryEnableWhenConnected");
static LLCachedControl<bool> defer_profiling(gSavedSettings, "DeferProfilingUntilConnected");
if( !one_time && (gFrameCount % 10 == 0) )
{
if(!FSTelemetry::active && profiling_enabled_when_connected && FSTelemetryIsConnected)
// LL_INFOS() << "Profiler active: " << (LLProfiler::active?"True":"False") << LL_ENDL;
// LL_INFOS() << "deferred_profiling: " << (defer_profiling?"True":"False") << LL_ENDL;
// LL_INFOS() << "connected: " << (LL_PROFILE_IS_CONNECTED?"True":"False") << LL_ENDL;
if( ( !LLProfiler::active ) && ( defer_profiling && LL_PROFILE_IS_CONNECTED ) )
{
FSTelemetry::active = true;
gSavedSettings.setBOOL("FSTelemetryActive", TRUE); // keep the setting in sync.
LLProfiler::active = true;
gSavedSettings.setBOOL( "ProfilingActive", LLProfiler::active );
one_time=true; // prevent reset race if we disable manually.
LL_INFOS() << "Profiler or collector connected" << LL_ENDL;
}
else if(!profiling_enabled_when_connected)
if( !defer_profiling )
{
// no point in checking if we are not waiting.
// TODO(Beq): At the moment we have only two options
// 1) start capturing immediately
// 2) start capturing only when a profiler is connected
// Ideally we could have another flag to control profiling at start
// this would then allow a fully manual enablement.
one_time = true;
LL_INFOS() << "Manual profiling control selected" << LL_ENDL;
}
}
#endif
@ -1678,7 +1689,7 @@ bool LLAppViewer::doFrame()
LL_CLEAR_CALLSTACKS();
{
LL_PROFILE_ZONE_NAMED( "df processMiscNativeEvents" )
// LL_PROFILE_ZONE_NAMED( "df processMiscNativeEvents" ) // <FS:Beq/> remove misplaced zone marker (see FTM_MESSAGES)
// <FS:Ansariel> MaxFPS Viewer-Chui merge error
// Check if we need to restore rendering masks.
if (restore_rendering_masks)
@ -3223,6 +3234,16 @@ bool LLAppViewer::initConfiguration()
}
}
// <FS:Beq> Start profiling immediately unless deferred.
#ifdef TRACE_ENABLE
if(!gSavedSettings.getBOOL("DeferProfilingUntilConnected"))
{
gSavedSettings.setBOOL( "ProfilingActive", true );
LLProfiling::active = true;
}
#endif
// </FS:Beq>
LLFastTimerView::sAnalyzePerformance = gSavedSettings.getBOOL("AnalyzePerformance");
gAgentPilot.setReplaySession(gSavedSettings.getBOOL("ReplaySession"));

View File

@ -9565,15 +9565,15 @@ class LLAdvancedToggleDoubleClickTeleport: public view_listener_t
};
// <FS:Beq> Add telemetry controls to the viewer menus
class FSTelemetryToggleActive : public view_listener_t
class LLProfilerToggleActive : public view_listener_t
{
protected:
bool handleEvent(const LLSD& userdata)
{
BOOL checked = gSavedSettings.getBOOL( "FSTelemetryActive" );
gSavedSettings.setBOOL( "FSTelemetryActive", !checked );
FSTelemetry::active = !checked;
BOOL checked = gSavedSettings.getBOOL( "ProfilingActive" );
gSavedSettings.setBOOL( "ProfilingActive", !checked );
LLProfiler::active = !checked;
return true;
}
};
@ -11953,9 +11953,10 @@ void initialize_menus()
//Develop (clear cache immediately)
commit.add("Develop.ClearCache", boost::bind(&handle_cache_clear_immediately) );
#ifdef TRACY_ENABLE
// <FS:Beq/> Add telemetry controls to the viewer Develop menu (Toggle profiling)
view_listener_t::addMenu(new FSTelemetryToggleActive(), "Develop.ToggleTelemetry");
view_listener_t::addMenu(new LLProfilerToggleActive(), "Develop.ToggleProfiling");
#endif
// Admin >Object
view_listener_t::addMenu(new LLAdminForceTakeCopy(), "Admin.ForceTakeCopy");
view_listener_t::addMenu(new LLAdminHandleObjectOwnerSelf(), "Admin.HandleObjectOwnerSelf");

View File

@ -3813,20 +3813,20 @@
name="Profiling">
<menu_item_check.on_check
function="CheckControl"
parameter="FSTelemetryActive" />
parameter="ProfilingActive" />
<menu_item_check.on_click
function="Develop.ToggleTelemetry"
parameter="FSTelemetryActive" />
function="Develop.ToggleProfiling"
parameter="ProfilingActive" />
</menu_item_check>
<menu_item_check
label="Start when connected"
name="Start when telemetry client connects">
<menu_item_check.on_check
function="CheckControl"
parameter="FSTelemetryEnableWhenConnected" />
parameter="DeferProfilingUntilConnected" />
<menu_item_check.on_click
function="ToggleControl"
parameter="FSTelemetryEnableWhenConnected" />
parameter="DeferProfilingUntilConnected" />
</menu_item_check>
</menu>