Skip to content

Commit

Permalink
Enhance the periodic logging to help understand memory usage (#6310)
Browse files Browse the repository at this point in the history
Removes the sim-based game time logger. Introduces a ui-based game time logger. This allows us to make the logging more relevant by including the session time and the heap usage.
  • Loading branch information
Garanas authored Jul 1, 2024
1 parent d0c16fe commit 727125e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 15 deletions.
5 changes: 5 additions & 0 deletions changelog/snippets/other.6310.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- (#6310) Enhance the periodic logging of the session time.

The logging now differentiates between the session time and the game time. It also prints information about the allocated memory on the heap. This is useful for debugging memory issues.

As an example: `DEBUG: Session time: 00:35:01 Game time: 00:09:33 Heap: 288.0M / 253.2M`
14 changes: 0 additions & 14 deletions lua/simInit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,6 @@ function BeginSession()
-- add on game over callbacks
ForkThread(GameOverListenerThread)

-- log game time
ForkThread(GameTimeLogger)

-- keep track of units off map
OnStartOffMapPreventionThread()

Expand Down Expand Up @@ -545,17 +542,6 @@ function BeginSessionEffects()
end
end

function GameTimeLogger()
while true do
GTS = GetGameTimeSeconds()
hours = math.floor(GTS / 3600);
minutes = math.floor((GTS - (hours * 3600)) / 60);
seconds = GTS - (hours * 3600) - (minutes * 60);
SPEW(string.format('Current gametime: %02d:%02d:%02d', hours, minutes, seconds))
WaitSeconds(30)
end
end

-- forks a thread that performs off-map prevention
function OnStartOffMapPreventionThread()
OffMappingPreventThread = ForkThread(import("/lua/scenarioframework.lua").AntiOffMapMainThread)
Expand Down
69 changes: 69 additions & 0 deletions lua/system/logger.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
--******************************************************************************************************
--** Copyright (c) 2024 Willem 'Jip' Wijnia
--**
--** Permission is hereby granted, free of charge, to any person obtaining a copy
--** of this software and associated documentation files (the "Software"), to deal
--** in the Software without restriction, including without limitation the rights
--** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
--** copies of the Software, and to permit persons to whom the Software is
--** furnished to do so, subject to the following conditions:
--**
--** The above copyright notice and this permission notice shall be included in all
--** copies or substantial portions of the Software.
--**
--** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
--** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
--** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
--** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
--** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
--** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
--** SOFTWARE.
--******************************************************************************************************

--- This module is responsible for periodically logging various information
--- about the current session that can be useful for debugging purposes.

--- Retrieves various engine statistics.
---@return integer # Heap committed
---@return integer # Heap total
local function GetEngineStatistics()

local heapCommitted = 0
local heapTotal = 0

if __EngineStats and __EngineStats.Children then
for _, a in pairs(__EngineStats.Children) do
if a.Name == 'Heap' then
for _, b in pairs(a.Children) do
if b.Name == 'Committed' then
heapCommitted = b.Value
end

if b.Name == 'Total' then
heapTotal = b.Value
end
end
end
end
end

return heapCommitted, heapTotal
end

function LoggingThread()
while true do
local sessionTime = CurrentTime()
local gameTime = GameTime()
local heapCommitted, heapTotal = GetEngineStatistics()

SPEW(
string.format("Session time: %s", FormatTime(sessionTime)),
string.format("Game time: %s", FormatTime(gameTime)),
string.format("Heap: %s / %s", heapTotal, heapCommitted)
)

WaitSeconds(10)
end
end

ForkThread(LoggingThread)
1 change: 1 addition & 0 deletions lua/ui/game/gamemain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ function CreateUI(isReplay)

-- start long-running threads

import("/lua/system/logger.lua")
import("/lua/system/performance.lua")
import("/lua/ui/game/cursor/depth.lua")
import("/lua/ui/game/cursor/hover.lua")
Expand Down
1 change: 0 additions & 1 deletion lua/userInit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ if replayID then
LOG("REPLAY ID: " .. replayID)
end


do

-- Moderation functionality
Expand Down

0 comments on commit 727125e

Please sign in to comment.