Repository navigation
Modernize the dbgprint module and make it portable. - #523
daliborfox wants to merge 19 commits into
Conversation
|
Development builds of 79842e6:
The links work without a GitHub account. Artifacts expire after 90 days, and this comment follows the latest successful build. |
|
Hey! Overall looks solid, but found a few things:
And we're now onto 0.3.0 so that needs updating :P |
…() calls to testcases.
|
Thank you for the inputs! I agree with you on all points, and I've cleaned up the PR. I've done some measurements on the Windows console output, comparing Here's the testcase: consoletest.cpp I've commented out the file write and debugger write statements, and only kept the console write statements, and these are the results I got on Windows Terminal a) with Same test with the Windows console host, with And just for completeness sake, I also ran it on Linux, on the same computer in the Alacritty terminal (I dual-boot):
I think the reason why What surprised me about the results is that I had expected And unfortunately, the performance test is marginal on the 32-bit debug build: It was a lot worse at first (40us on my system, managed to get it down to 5us), I've spent quite some time optimizing it on the previous weekend (the biggest bottleneck was timestamp generation). However, the debug build version of STL stuff is quite a bit slower than the release build. Would it make sense to have a separate threshold for the debug build, e.g. 15us instead of 10? |
|
I've spent some time further cleaning up and optimizing the PR, and I've been able to resolve the performance problem reported by the testsuite. By getting rid of the I've also compared the performance to the original version of the module, and there, the latency is Comparing the 32-bit release builds, the original version has an uncontended mean latency result of |








This pull request updates the dbgprint module so that it makes use of C++20 standard library facilities instead of Windows ones where possible, and allows the module to work on non-Windows systems, having been tested on Linux and Mac:
On Mac, the operating system version for the log banner is retrieved from the
SystemVersion.plistfile, on other systems the/etc/os-releaseor/usr/lib/os-releasefile is queried. The output ofuname -ais provided as a fallback in case those files don't exist.Reading the .plist file does require an additional dependency of
libxml2on Mac, though it's a part of the macOS SDK, so the user doesn't need to install any additional dependencies themselves when building OpenTS with this module (build system support not yet available).The default location for the logging directory is as follows:
<dir-with-game-exe>\Debug\~/Library/Logs/OpenTS/$XDG_STATE_HOME/OpenTS/, with a fallback of$HOME/.local/state/OpenTS/./OpenTS-Logs/A new feature is the ability to specify the desired location of the log file. If the
-USERDIR=<path>command-line option is specified, the logs will be located in the following directory:<USERDIR>/Debug/In order to gracefully use objects that dynamically allocate memory, the module holds its state in a lazy initialization singleton. This singleton contains an
m_DebugDestroyedflag that causes all of the module's functions to gracefully fail if they try to make use of the shared state after it's already had its destructor called by the C++ runtime.The same applies to the thread-local buffers used for holding the
vsnprintf()formatting data.As a consequence, there is a high likelihood that messages logged from the global destructors of other modules in the project will not end up being processed.
Another important thing to keep in mind is that the
Debug_Init()function call is now mandatory, as it's used to process the command-line options for whether or not to enable the console, and where to store the logs. It is permissible to callDebugString()beforeDebug_Init()is invoked, e.g. from global constructors, but the messages will only be displayed and/or written to the log file / sent to the debugger afterDebug_Init()had been invoked.Please let me know if you disagree if some of the things I've done, or see room for improvement! I've tried my best to polish things up, but it's always possible that I've missed something.