From 4e8d02849994d24d6f7acd55ec68a22e506545b2 Mon Sep 17 00:00:00 2001 From: Beherith Date: Fri, 11 Aug 2023 14:35:24 +0200 Subject: [PATCH 01/11] Allow for Tracy Plots from Lua, new UnsyncedCtrl callouts: LuaTracyPlotConfig, LuaTracyPlot LuaTracyPlotConfig(number plotIndex , string plotType, bool step, bool fill, number color) LuaTracyPlot(number plotIndex, number plotValue) Plot indices go from 1-9, I could not figure out how to pass a name to the plot. Any help there is welcome! --- rts/Lua/LuaUnsyncedCtrl.cpp | 58 +++++++++++++++++++++++++++++++++++++ rts/Lua/LuaUnsyncedCtrl.h | 3 ++ 2 files changed, 61 insertions(+) diff --git a/rts/Lua/LuaUnsyncedCtrl.cpp b/rts/Lua/LuaUnsyncedCtrl.cpp index 7d66aed8e2..21b648ac1c 100644 --- a/rts/Lua/LuaUnsyncedCtrl.cpp +++ b/rts/Lua/LuaUnsyncedCtrl.cpp @@ -325,6 +325,9 @@ bool LuaUnsyncedCtrl::PushEntries(lua_State* L) REGISTER_LUA_CFUNC(Yield); + REGISTER_LUA_CFUNC(LuaTracyPlotConfig); + REGISTER_LUA_CFUNC(LuaTracyPlot); + return true; } @@ -4864,3 +4867,58 @@ int LuaUnsyncedCtrl::Yield(lua_State* L) lua_pushboolean(L, true); //hint Lua should keep calling Yield return 1; } + +const char * tracyLuaPlot1 = "LuaPlot1"; +const char * tracyLuaPlot2 = "LuaPlot2"; +const char * tracyLuaPlot3 = "LuaPlot3"; +const char * tracyLuaPlot4 = "LuaPlot4"; +const char * tracyLuaPlot5 = "LuaPlot5"; +const char * tracyLuaPlot6 = "LuaPlot6"; +const char * tracyLuaPlot7 = "LuaPlot7"; +const char * tracyLuaPlot8 = "LuaPlot8"; +const char * tracyLuaPlot9 = "LuaPlot9"; + +int LuaUnsyncedCtrl::LuaTracyPlotConfig(lua_State* L) +{ + const int plotIndex = std::clamp(luaL_checkint(L, 1), 1, 9); + const char* plotFormatTypeString = luaL_optstring(L, 2, ""); + tracy::PlotFormatType plotFormatType = tracy::PlotFormatType::Number; + + if (plotFormatTypeString[0] != 0 ){ + if (plotFormatTypeString[0] == 'P') plotFormatType = tracy::PlotFormatType::Percentage; // for Perce + if (plotFormatTypeString[0] == 'M') plotFormatType = tracy::PlotFormatType::Memory; // for Perce + } + const bool step = luaL_optboolean(L, 3, true); // stepwise default + const bool fill = luaL_optboolean(L, 4, false); // no fill default + const uint32_t color = luaL_optint(L, 5, 0xffffff); // white default + switch(plotIndex){ + case 1: TracyPlotConfig(tracyLuaPlot1, plotFormatType, step, fill, color); break; + case 2: TracyPlotConfig(tracyLuaPlot2, plotFormatType, step, fill, color); break; + case 3: TracyPlotConfig(tracyLuaPlot3, plotFormatType, step, fill, color); break; + case 4: TracyPlotConfig(tracyLuaPlot4, plotFormatType, step, fill, color); break; + case 5: TracyPlotConfig(tracyLuaPlot5, plotFormatType, step, fill, color); break; + case 6: TracyPlotConfig(tracyLuaPlot6, plotFormatType, step, fill, color); break; + case 7: TracyPlotConfig(tracyLuaPlot7, plotFormatType, step, fill, color); break; + case 8: TracyPlotConfig(tracyLuaPlot8, plotFormatType, step, fill, color); break; + case 9: TracyPlotConfig(tracyLuaPlot9, plotFormatType, step, fill, color); break; + } + return 0; +} + +int LuaUnsyncedCtrl::LuaTracyPlot(lua_State* L) +{ + const int plotIndex = std::clamp(luaL_checkint(L, 1), 1, 9) ; + const float plotValue = luaL_checkfloat(L, 2); + switch(plotIndex){ + case 1: TracyPlot(tracyLuaPlot1, plotValue); break; + case 2: TracyPlot(tracyLuaPlot2, plotValue); break; + case 3: TracyPlot(tracyLuaPlot3, plotValue); break; + case 4: TracyPlot(tracyLuaPlot4, plotValue); break; + case 5: TracyPlot(tracyLuaPlot5, plotValue); break; + case 6: TracyPlot(tracyLuaPlot6, plotValue); break; + case 7: TracyPlot(tracyLuaPlot7, plotValue); break; + case 8: TracyPlot(tracyLuaPlot8, plotValue); break; + case 9: TracyPlot(tracyLuaPlot9, plotValue); break; + } + return 0; +} \ No newline at end of file diff --git a/rts/Lua/LuaUnsyncedCtrl.h b/rts/Lua/LuaUnsyncedCtrl.h index 0b99e7b29b..2325472454 100644 --- a/rts/Lua/LuaUnsyncedCtrl.h +++ b/rts/Lua/LuaUnsyncedCtrl.h @@ -203,6 +203,9 @@ class LuaUnsyncedCtrl { static int SetWindowMaximized(lua_State* L); static int Yield(lua_State* L); + + static int LuaTracyPlotConfig(lua_State* L); + static int LuaTracyPlot(lua_State* L); }; #endif /* LUA_UNSYNCED_CTRL_H */ From f68a46f68325f3842acab831d2f7c6768689d5c4 Mon Sep 17 00:00:00 2001 From: Beherith Date: Fri, 11 Aug 2023 14:53:02 +0200 Subject: [PATCH 02/11] Add function ldocs to LuaTracyPlotConfig and LuaTracyPlot --- rts/Lua/LuaUnsyncedCtrl.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/rts/Lua/LuaUnsyncedCtrl.cpp b/rts/Lua/LuaUnsyncedCtrl.cpp index 21b648ac1c..a6bb96432b 100644 --- a/rts/Lua/LuaUnsyncedCtrl.cpp +++ b/rts/Lua/LuaUnsyncedCtrl.cpp @@ -4878,6 +4878,16 @@ const char * tracyLuaPlot7 = "LuaPlot7"; const char * tracyLuaPlot8 = "LuaPlot8"; const char * tracyLuaPlot9 = "LuaPlot9"; +/*** + * + * @function Spring.LuaTracyPlotConfig + * @number plotIndex which LuaPlot[1-9] should be initialized + * @string[opt] plotFormatType "Number"|"Percentage"|"Memory", default "Number" + * @bool[opt] step stepwise chart, default stepwise + * @bool[opt] fill color fill, default no fill + * @number[opt] color unit32 number as RGB color, default white + * @treturn nil + */ int LuaUnsyncedCtrl::LuaTracyPlotConfig(lua_State* L) { const int plotIndex = std::clamp(luaL_checkint(L, 1), 1, 9); @@ -4905,6 +4915,13 @@ int LuaUnsyncedCtrl::LuaTracyPlotConfig(lua_State* L) return 0; } +/*** + * + * @function Spring.LuaTracyPlot + * @number plotIndex which LuaPlot[1-9] should be updated + * @number plotvalue the number to show on the Tracy plot + * @treturn nil + */ int LuaUnsyncedCtrl::LuaTracyPlot(lua_State* L) { const int plotIndex = std::clamp(luaL_checkint(L, 1), 1, 9) ; From 53d8152eac9c0c9757c94e3f3ae1b1a88e79bdf1 Mon Sep 17 00:00:00 2001 From: Beherith Date: Fri, 11 Aug 2023 15:32:39 +0200 Subject: [PATCH 03/11] Further Clarify LuaTracyPlotConfig ldoc strings --- rts/Lua/LuaUnsyncedCtrl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rts/Lua/LuaUnsyncedCtrl.cpp b/rts/Lua/LuaUnsyncedCtrl.cpp index a6bb96432b..e95f5e6063 100644 --- a/rts/Lua/LuaUnsyncedCtrl.cpp +++ b/rts/Lua/LuaUnsyncedCtrl.cpp @@ -4878,7 +4878,7 @@ const char * tracyLuaPlot7 = "LuaPlot7"; const char * tracyLuaPlot8 = "LuaPlot8"; const char * tracyLuaPlot9 = "LuaPlot9"; -/*** +/*** Initialize a plot in Tracy for use in debugging, up to 9 plots [1-9] may be used * * @function Spring.LuaTracyPlotConfig * @number plotIndex which LuaPlot[1-9] should be initialized @@ -4915,7 +4915,7 @@ int LuaUnsyncedCtrl::LuaTracyPlotConfig(lua_State* L) return 0; } -/*** +/*** Update a Tracy Plot with a value * * @function Spring.LuaTracyPlot * @number plotIndex which LuaPlot[1-9] should be updated From 1a693b01dc6fcd37f55f1b17dadb4c0573829aeb Mon Sep 17 00:00:00 2001 From: Beherith Date: Fri, 11 Aug 2023 16:31:55 +0200 Subject: [PATCH 04/11] TracyPlotConfig and TracyPlot now take plotName strings as first arguments thanks @sprunk --- rts/Lua/LuaUnsyncedCtrl.cpp | 78 ++++++++++++++----------------------- 1 file changed, 29 insertions(+), 49 deletions(-) diff --git a/rts/Lua/LuaUnsyncedCtrl.cpp b/rts/Lua/LuaUnsyncedCtrl.cpp index e95f5e6063..8e09967603 100644 --- a/rts/Lua/LuaUnsyncedCtrl.cpp +++ b/rts/Lua/LuaUnsyncedCtrl.cpp @@ -4868,74 +4868,54 @@ int LuaUnsyncedCtrl::Yield(lua_State* L) return 1; } -const char * tracyLuaPlot1 = "LuaPlot1"; -const char * tracyLuaPlot2 = "LuaPlot2"; -const char * tracyLuaPlot3 = "LuaPlot3"; -const char * tracyLuaPlot4 = "LuaPlot4"; -const char * tracyLuaPlot5 = "LuaPlot5"; -const char * tracyLuaPlot6 = "LuaPlot6"; -const char * tracyLuaPlot7 = "LuaPlot7"; -const char * tracyLuaPlot8 = "LuaPlot8"; -const char * tracyLuaPlot9 = "LuaPlot9"; +std::set tracyLuaPlots; /*** Initialize a plot in Tracy for use in debugging, up to 9 plots [1-9] may be used * * @function Spring.LuaTracyPlotConfig - * @number plotIndex which LuaPlot[1-9] should be initialized + * @string plotName which should be initialized * @string[opt] plotFormatType "Number"|"Percentage"|"Memory", default "Number" * @bool[opt] step stepwise chart, default stepwise * @bool[opt] fill color fill, default no fill - * @number[opt] color unit32 number as RGB color, default white + * @number[opt] color unit32 number as BGR color, default white * @treturn nil */ + int LuaUnsyncedCtrl::LuaTracyPlotConfig(lua_State* L) { - const int plotIndex = std::clamp(luaL_checkint(L, 1), 1, 9); - const char* plotFormatTypeString = luaL_optstring(L, 2, ""); - tracy::PlotFormatType plotFormatType = tracy::PlotFormatType::Number; + const auto plotName = luaL_checkstring(L, 1); + const auto plotFormatTypeString = luaL_optstring(L, 2, ""); + const auto step = luaL_optboolean(L, 3, true); // stepwise default + const auto fill = luaL_optboolean(L, 4, false); // no fill default + const uint32_t color = luaL_optint(L, 5, 0xFFFFFF); // white default - if (plotFormatTypeString[0] != 0 ){ - if (plotFormatTypeString[0] == 'P') plotFormatType = tracy::PlotFormatType::Percentage; // for Perce - if (plotFormatTypeString[0] == 'M') plotFormatType = tracy::PlotFormatType::Memory; // for Perce - } - const bool step = luaL_optboolean(L, 3, true); // stepwise default - const bool fill = luaL_optboolean(L, 4, false); // no fill default - const uint32_t color = luaL_optint(L, 5, 0xffffff); // white default - switch(plotIndex){ - case 1: TracyPlotConfig(tracyLuaPlot1, plotFormatType, step, fill, color); break; - case 2: TracyPlotConfig(tracyLuaPlot2, plotFormatType, step, fill, color); break; - case 3: TracyPlotConfig(tracyLuaPlot3, plotFormatType, step, fill, color); break; - case 4: TracyPlotConfig(tracyLuaPlot4, plotFormatType, step, fill, color); break; - case 5: TracyPlotConfig(tracyLuaPlot5, plotFormatType, step, fill, color); break; - case 6: TracyPlotConfig(tracyLuaPlot6, plotFormatType, step, fill, color); break; - case 7: TracyPlotConfig(tracyLuaPlot7, plotFormatType, step, fill, color); break; - case 8: TracyPlotConfig(tracyLuaPlot8, plotFormatType, step, fill, color); break; - case 9: TracyPlotConfig(tracyLuaPlot9, plotFormatType, step, fill, color); break; - } - return 0; + tracy::PlotFormatType plotFormatType; + switch (plotFormatTypeString[0]) { + case 'p': case 'P': plotFormatType = tracy::PlotFormatType::Percentage; break; + case 'm': case 'M': plotFormatType = tracy::PlotFormatType::Memory; break; + default: plotFormatType = tracy::PlotFormatType::Number; break; + } + + const auto [iterator, inserted] = tracyLuaPlots.emplace(plotName); + TracyPlotConfig(iterator->c_str(), plotFormatType, step, fill, color); + return 0; } + /*** Update a Tracy Plot with a value * * @function Spring.LuaTracyPlot - * @number plotIndex which LuaPlot[1-9] should be updated + * @string plotName which LuaPlot should be updated (must have been initialized as per above!) * @number plotvalue the number to show on the Tracy plot * @treturn nil */ int LuaUnsyncedCtrl::LuaTracyPlot(lua_State* L) { - const int plotIndex = std::clamp(luaL_checkint(L, 1), 1, 9) ; - const float plotValue = luaL_checkfloat(L, 2); - switch(plotIndex){ - case 1: TracyPlot(tracyLuaPlot1, plotValue); break; - case 2: TracyPlot(tracyLuaPlot2, plotValue); break; - case 3: TracyPlot(tracyLuaPlot3, plotValue); break; - case 4: TracyPlot(tracyLuaPlot4, plotValue); break; - case 5: TracyPlot(tracyLuaPlot5, plotValue); break; - case 6: TracyPlot(tracyLuaPlot6, plotValue); break; - case 7: TracyPlot(tracyLuaPlot7, plotValue); break; - case 8: TracyPlot(tracyLuaPlot8, plotValue); break; - case 9: TracyPlot(tracyLuaPlot9, plotValue); break; - } - return 0; -} \ No newline at end of file + const auto plotName = luaL_checkstring(L, 1); + const auto plotValue = luaL_checkfloat(L, 2); + + const auto [iterator, inserted] = tracyLuaPlots.emplace(plotName); + TracyPlot(iterator->c_str(), plotValue); + return 0; +} + From f46f7d1f38118019eff13140adea718775353f9b Mon Sep 17 00:00:00 2001 From: sprunk Date: Fri, 11 Aug 2023 16:35:18 +0200 Subject: [PATCH 05/11] Add a comment. --- rts/Lua/LuaUnsyncedCtrl.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rts/Lua/LuaUnsyncedCtrl.cpp b/rts/Lua/LuaUnsyncedCtrl.cpp index 8e09967603..c5f3c41c67 100644 --- a/rts/Lua/LuaUnsyncedCtrl.cpp +++ b/rts/Lua/LuaUnsyncedCtrl.cpp @@ -4868,6 +4868,8 @@ int LuaUnsyncedCtrl::Yield(lua_State* L) return 1; } +/* NB: strings here are never cleaned up, but the use case assumes + * that they live a long time and there's just a handful of them */ std::set tracyLuaPlots; /*** Initialize a plot in Tracy for use in debugging, up to 9 plots [1-9] may be used From 05b3b550dc1679e4d764484eb6d80b12808e5f5b Mon Sep 17 00:00:00 2001 From: Beherith Date: Tue, 16 Jan 2024 22:22:14 +0100 Subject: [PATCH 06/11] Clarify docs for LuaTracyPlots --- rts/Lua/LuaUnsyncedCtrl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rts/Lua/LuaUnsyncedCtrl.cpp b/rts/Lua/LuaUnsyncedCtrl.cpp index c5f3c41c67..902e941359 100644 --- a/rts/Lua/LuaUnsyncedCtrl.cpp +++ b/rts/Lua/LuaUnsyncedCtrl.cpp @@ -4872,13 +4872,13 @@ int LuaUnsyncedCtrl::Yield(lua_State* L) * that they live a long time and there's just a handful of them */ std::set tracyLuaPlots; -/*** Initialize a plot in Tracy for use in debugging, up to 9 plots [1-9] may be used +/*** Initialize a plot in Tracy for use in debugging or profiling * * @function Spring.LuaTracyPlotConfig * @string plotName which should be initialized * @string[opt] plotFormatType "Number"|"Percentage"|"Memory", default "Number" - * @bool[opt] step stepwise chart, default stepwise - * @bool[opt] fill color fill, default no fill + * @bool[opt] step stepwise chart, default true is stepwise + * @bool[opt] fill color fill, default false is no fill * @number[opt] color unit32 number as BGR color, default white * @treturn nil */ @@ -4907,7 +4907,7 @@ int LuaUnsyncedCtrl::LuaTracyPlotConfig(lua_State* L) /*** Update a Tracy Plot with a value * * @function Spring.LuaTracyPlot - * @string plotName which LuaPlot should be updated (must have been initialized as per above!) + * @string plotName which LuaPlot should be updated (must have been initialized via LuaTracyPlotConfig) * @number plotvalue the number to show on the Tracy plot * @treturn nil */ From 437f13d1ac92f7ff35346283ea4b962b4a288b57 Mon Sep 17 00:00:00 2001 From: Beherith Date: Tue, 16 Jan 2024 22:36:50 +0100 Subject: [PATCH 07/11] Expose LuaTracyPlot to LuaMenu and LuaIntro contexts --- rts/Lua/LuaIntro.cpp | 3 +++ rts/Lua/LuaMenu.cpp | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/rts/Lua/LuaIntro.cpp b/rts/Lua/LuaIntro.cpp index af649ca7c6..d4a76d1b67 100644 --- a/rts/Lua/LuaIntro.cpp +++ b/rts/Lua/LuaIntro.cpp @@ -212,6 +212,9 @@ bool CLuaIntro::LoadUnsyncedCtrlFunctions(lua_State* L) REGISTER_SCOPED_LUA_CFUNC(LuaUnsyncedCtrl, SetLogSectionFilterLevel); + REGISTER_SCOPED_LUA_CFUNC(LuaUnsyncedCtrl, LuaTracyPlotConfig); + REGISTER_SCOPED_LUA_CFUNC(LuaUnsyncedCtrl, LuaTracyPlot); + return true; } diff --git a/rts/Lua/LuaMenu.cpp b/rts/Lua/LuaMenu.cpp index 5a0b5650de..1b7711109d 100644 --- a/rts/Lua/LuaMenu.cpp +++ b/rts/Lua/LuaMenu.cpp @@ -252,6 +252,10 @@ bool CLuaMenu::LoadUnsyncedCtrlFunctions(lua_State* L) REGISTER_SCOPED_LUA_CFUNC(LuaUnsyncedCtrl, SDLSetTextInputRect); REGISTER_SCOPED_LUA_CFUNC(LuaUnsyncedCtrl, SDLStartTextInput); REGISTER_SCOPED_LUA_CFUNC(LuaUnsyncedCtrl, SDLStopTextInput); + + REGISTER_SCOPED_LUA_CFUNC(LuaUnsyncedCtrl, LuaTracyPlotConfig); + REGISTER_SCOPED_LUA_CFUNC(LuaUnsyncedCtrl, LuaTracyPlot); + return true; } From 81450229a1f129c18ee73f3b2a62eb6a19975e89 Mon Sep 17 00:00:00 2001 From: Beherith Date: Wed, 17 Jan 2024 13:48:17 +0100 Subject: [PATCH 08/11] Fix whitespace, clarify docstrings --- rts/Lua/LuaUnsyncedCtrl.cpp | 46 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/rts/Lua/LuaUnsyncedCtrl.cpp b/rts/Lua/LuaUnsyncedCtrl.cpp index 902e941359..57fd506676 100644 --- a/rts/Lua/LuaUnsyncedCtrl.cpp +++ b/rts/Lua/LuaUnsyncedCtrl.cpp @@ -4872,10 +4872,10 @@ int LuaUnsyncedCtrl::Yield(lua_State* L) * that they live a long time and there's just a handful of them */ std::set tracyLuaPlots; -/*** Initialize a plot in Tracy for use in debugging or profiling +/*** Configure custom appearence for a Tracy plot for use in debugging or profiling * * @function Spring.LuaTracyPlotConfig - * @string plotName which should be initialized + * @string plotName which should be customized * @string[opt] plotFormatType "Number"|"Percentage"|"Memory", default "Number" * @bool[opt] step stepwise chart, default true is stepwise * @bool[opt] fill color fill, default false is no fill @@ -4885,39 +4885,39 @@ std::set tracyLuaPlots; int LuaUnsyncedCtrl::LuaTracyPlotConfig(lua_State* L) { - const auto plotName = luaL_checkstring(L, 1); - const auto plotFormatTypeString = luaL_optstring(L, 2, ""); - const auto step = luaL_optboolean(L, 3, true); // stepwise default - const auto fill = luaL_optboolean(L, 4, false); // no fill default - const uint32_t color = luaL_optint(L, 5, 0xFFFFFF); // white default - - tracy::PlotFormatType plotFormatType; - switch (plotFormatTypeString[0]) { - case 'p': case 'P': plotFormatType = tracy::PlotFormatType::Percentage; break; - case 'm': case 'M': plotFormatType = tracy::PlotFormatType::Memory; break; - default: plotFormatType = tracy::PlotFormatType::Number; break; - } + const auto plotName = luaL_checkstring(L, 1); + const auto plotFormatTypeString = luaL_optstring(L, 2, ""); + const auto step = luaL_optboolean(L, 3, true); // stepwise default + const auto fill = luaL_optboolean(L, 4, false); // no fill default + const uint32_t color = luaL_optint(L, 5, 0xFFFFFF); // white default + + tracy::PlotFormatType plotFormatType; + switch (plotFormatTypeString[0]) { + case 'p': case 'P': plotFormatType = tracy::PlotFormatType::Percentage; break; + case 'm': case 'M': plotFormatType = tracy::PlotFormatType::Memory; break; + default: plotFormatType = tracy::PlotFormatType::Number; break; + } - const auto [iterator, inserted] = tracyLuaPlots.emplace(plotName); - TracyPlotConfig(iterator->c_str(), plotFormatType, step, fill, color); - return 0; + const auto [iterator, inserted] = tracyLuaPlots.emplace(plotName); + TracyPlotConfig(iterator->c_str(), plotFormatType, step, fill, color); + return 0; } /*** Update a Tracy Plot with a value * * @function Spring.LuaTracyPlot - * @string plotName which LuaPlot should be updated (must have been initialized via LuaTracyPlotConfig) + * @string plotName which LuaPlot should be updated * @number plotvalue the number to show on the Tracy plot * @treturn nil */ int LuaUnsyncedCtrl::LuaTracyPlot(lua_State* L) { - const auto plotName = luaL_checkstring(L, 1); - const auto plotValue = luaL_checkfloat(L, 2); + const auto plotName = luaL_checkstring(L, 1); + const auto plotValue = luaL_checkfloat(L, 2); - const auto [iterator, inserted] = tracyLuaPlots.emplace(plotName); - TracyPlot(iterator->c_str(), plotValue); - return 0; + const auto [iterator, inserted] = tracyLuaPlots.emplace(plotName); + TracyPlot(iterator->c_str(), plotValue); + return 0; } From a2817f202a47a20a5e7727fa8f302806610c140e Mon Sep 17 00:00:00 2001 From: sprunk Date: Fri, 26 Jan 2024 16:16:11 +0100 Subject: [PATCH 09/11] Microoptimize tracy plot API --- rts/Lua/LuaUnsyncedCtrl.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/rts/Lua/LuaUnsyncedCtrl.cpp b/rts/Lua/LuaUnsyncedCtrl.cpp index 57fd506676..42dcd93cf3 100644 --- a/rts/Lua/LuaUnsyncedCtrl.cpp +++ b/rts/Lua/LuaUnsyncedCtrl.cpp @@ -4870,7 +4870,7 @@ int LuaUnsyncedCtrl::Yield(lua_State* L) /* NB: strings here are never cleaned up, but the use case assumes * that they live a long time and there's just a handful of them */ -std::set tracyLuaPlots; +std::set > tracyLuaPlots; /*** Configure custom appearence for a Tracy plot for use in debugging or profiling * @@ -4898,8 +4898,11 @@ int LuaUnsyncedCtrl::LuaTracyPlotConfig(lua_State* L) default: plotFormatType = tracy::PlotFormatType::Number; break; } - const auto [iterator, inserted] = tracyLuaPlots.emplace(plotName); - TracyPlotConfig(iterator->c_str(), plotFormatType, step, fill, color); + auto plot = tracyLuaPlots.find(plotName); + if (plot == tracyLuaPlots.end()) + plot = tracyLuaPlots.emplace(plotName).first; + + TracyPlotConfig(plot->c_str(), plotFormatType, step, fill, color); return 0; } @@ -4916,8 +4919,11 @@ int LuaUnsyncedCtrl::LuaTracyPlot(lua_State* L) const auto plotName = luaL_checkstring(L, 1); const auto plotValue = luaL_checkfloat(L, 2); - const auto [iterator, inserted] = tracyLuaPlots.emplace(plotName); - TracyPlot(iterator->c_str(), plotValue); + auto plot = tracyLuaPlots.find(plotName); + if (plot == tracyLuaPlots.end()) + plot = tracyLuaPlots.emplace(plotName).first; + + TracyPlot(plot->c_str(), plotValue); return 0; } From cb4614d599de9257515d59632a7177dc33380437 Mon Sep 17 00:00:00 2001 From: sprunk Date: Fri, 26 Jan 2024 23:42:55 +0100 Subject: [PATCH 10/11] Fix compilation. --- rts/Lua/LuaUnsyncedCtrl.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rts/Lua/LuaUnsyncedCtrl.cpp b/rts/Lua/LuaUnsyncedCtrl.cpp index 42dcd93cf3..b8e57c2bc2 100644 --- a/rts/Lua/LuaUnsyncedCtrl.cpp +++ b/rts/Lua/LuaUnsyncedCtrl.cpp @@ -111,6 +111,8 @@ #undef CreateDirectory #undef Yield +#include +#include /****************************************************************************** * Callouts to set state From 6d5b2469f69e3c9bf03526b0c84d492b8c206e76 Mon Sep 17 00:00:00 2001 From: sprunk Date: Sat, 27 Jan 2024 01:22:44 +0100 Subject: [PATCH 11/11] Commentate the tracy plot storage --- rts/Lua/LuaUnsyncedCtrl.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rts/Lua/LuaUnsyncedCtrl.cpp b/rts/Lua/LuaUnsyncedCtrl.cpp index b8e57c2bc2..ff60a37209 100644 --- a/rts/Lua/LuaUnsyncedCtrl.cpp +++ b/rts/Lua/LuaUnsyncedCtrl.cpp @@ -4870,8 +4870,12 @@ int LuaUnsyncedCtrl::Yield(lua_State* L) return 1; } -/* NB: strings here are never cleaned up, but the use case assumes - * that they live a long time and there's just a handful of them */ +/* Tracy seems to want unique, unchanging strings to be passed to + * its API, so we need to immanentize the ephemeral Lua strings + * and store them. + * + * NB: strings here are never cleaned up, but the use case assumes + * that they live a long time and there's just a handful of them. */ std::set > tracyLuaPlots; /*** Configure custom appearence for a Tracy plot for use in debugging or profiling