Skip to content

Commit

Permalink
Fix bad performance of script command tracing (#751)
Browse files Browse the repository at this point in the history
* Fix bad performance of script command tracing

* Update source/game_sa/Scripts/TheScripts.h

Co-authored-by: yukani <yukani@zohomail.eu>

---------

Co-authored-by: yukani <yukani@zohomail.eu>
  • Loading branch information
Pirulax and yukani authored Sep 18, 2024
1 parent 2dddbed commit 49238f1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
Options and Actions
--]]

newoption {
trigger = "script-tracing",
description = "Enable script command trace logging (Slow!)"
}
newoption {
trigger = "outdir",
value = "path",
Expand Down
8 changes: 7 additions & 1 deletion source/game_sa/Scripts/RunningScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,13 @@ OpcodeResult CRunningScript::ProcessOneCommand() {
};
} op = { CTheScripts::Read2BytesFromScript(m_IP) };

SPDLOG_LOGGER_TRACE(logger, "[{}][IP: {:#x} + {:#x}]: {} [{:#x}]", m_szName, LOG_PTR(m_pBaseIP), LOG_PTR(m_IP - m_pBaseIP), notsa::script::GetScriptCommandName((eScriptCommands)op.command), (size_t)op.command);
#ifdef NOTSA_SCRIPT_TRACING
// snprintf is faster (in debug at least) - Gotta stick to it for now
char msg[4096];
sprintf_s(msg, "[%s][IP: 0x%X + 0x%X]: %s [0x%X]", m_szName, LOG_PTR(m_pBaseIP), LOG_PTR(m_IP - m_pBaseIP), notsa::script::GetScriptCommandName((eScriptCommands)op.command).data(), (size_t)op.command);
SPDLOG_LOGGER_TRACE(logger, msg);
//SPDLOG_LOGGER_TRACE(logger, "[{}][IP: {:#x} + {:#x}]: {} [{:#x}]", m_szName, LOG_PTR(m_pBaseIP), LOG_PTR(m_IP - m_pBaseIP), notsa::script::GetScriptCommandName((eScriptCommands)op.command), (size_t)op.command);
#endif

m_bNotFlag = op.notFlag;

Expand Down
4 changes: 4 additions & 0 deletions source/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ project "gta_sa_modern"
"../libs/tracy/public",
"../libs/json/include"
}

filter "options:script-tracing"
defines { "NOTSA_SCRIPT_TRACING" }
filter {}

defines {
"NOMINMAX",
Expand Down

0 comments on commit 49238f1

Please sign in to comment.