diff --git a/indra/llcommon/llprofiler.cpp b/indra/llcommon/llprofiler.cpp new file mode 100644 index 0000000000..be22212e50 --- /dev/null +++ b/indra/llcommon/llprofiler.cpp @@ -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}; +} \ No newline at end of file diff --git a/indra/llcommon/llprofiler.h b/indra/llcommon/llprofiler.h index e82837fcbf..a278c70fe4 100644 --- a/indra/llcommon/llprofiler.h +++ b/indra/llcommon/llprofiler.h @@ -36,6 +36,12 @@ #define LL_PROFILER_CONFIGURATION LL_PROFILER_CONFIG_FAST_TIMER #endif +// active switch for deferred profiling +namespace LLProfiler +{ + extern bool active; +} +// #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 - // 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 ) + // 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 ) + // + + // + // #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 ) // Enable deferred collection through filters // - #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 // Additional FS Tracy macros - #define LL_PROFILE_ZONE_COLOR(color) ZoneNamedC( ___tracy_scoped_zone, color, true ) // Additional Tracy macro + #define LL_PROFILE_ZONE_COLOR(color) ZoneNamedC( ___tracy_scoped_zone, color, LLProfiler::active ) // 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 @@ // 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__); + // + // + // #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 ) // Enable deferred collection through filters // - #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 // 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 diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index dfcfa349d8..c03f4e526f 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -24657,10 +24657,10 @@ Change of this parameter will affect the layout of buttons in notification toast Value 0 - FSTelemetryEnableWhenConnected + DeferProfilingUntilConnected Comment - Enable telemetry as soon as a server connects + Enable profiling data collection only after server connects. Lowers memory overhead and allows profiling from a specific point in time Persist 1 Type @@ -24668,10 +24668,10 @@ Change of this parameter will affect the layout of buttons in notification toast Value 1 - FSTelemetryActive + ProfilingActive Comment - Enable profiling as soon as a server connects. Off by default and non-persistent. Use with FSTelemetryEnableWhenConnected to initiate on startup + notes whether profiling is currently active. Used by the dev menu item Persist 0 Type diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index d82c2b9098..cc6eb97056 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -1635,24 +1635,35 @@ bool LLAppViewer::doFrame() LLEventPump& mainloop(LLEventPumps::instance().obtain("mainloop")); LLSD newFrame; -// telemetry enabling. +// 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 profiling_enabled_when_connected(gSavedSettings, "FSTelemetryEnableWhenConnected"); + static LLCachedControl 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" ) // remove misplaced zone marker (see FTM_MESSAGES) // MaxFPS Viewer-Chui merge error // Check if we need to restore rendering masks. if (restore_rendering_masks) @@ -3223,6 +3234,16 @@ bool LLAppViewer::initConfiguration() } } + // Start profiling immediately unless deferred. +#ifdef TRACE_ENABLE + if(!gSavedSettings.getBOOL("DeferProfilingUntilConnected")) + { + gSavedSettings.setBOOL( "ProfilingActive", true ); + LLProfiling::active = true; + } +#endif + // + LLFastTimerView::sAnalyzePerformance = gSavedSettings.getBOOL("AnalyzePerformance"); gAgentPilot.setReplaySession(gSavedSettings.getBOOL("ReplaySession")); diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp index a39cdf709e..b0aefe49ea 100644 --- a/indra/newview/llviewermenu.cpp +++ b/indra/newview/llviewermenu.cpp @@ -9565,15 +9565,15 @@ class LLAdvancedToggleDoubleClickTeleport: public view_listener_t }; // 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 // 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"); diff --git a/indra/newview/skins/default/xui/en/menu_viewer.xml b/indra/newview/skins/default/xui/en/menu_viewer.xml index 0c26664b04..1dbe561604 100644 --- a/indra/newview/skins/default/xui/en/menu_viewer.xml +++ b/indra/newview/skins/default/xui/en/menu_viewer.xml @@ -3813,20 +3813,20 @@ name="Profiling"> + parameter="ProfilingActive" /> + function="Develop.ToggleProfiling" + parameter="ProfilingActive" /> + parameter="DeferProfilingUntilConnected" /> + parameter="DeferProfilingUntilConnected" />