diff options
| author | Stefan Boberg <[email protected]> | 2024-11-25 09:56:23 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-11-25 09:56:23 +0100 |
| commit | 8b8de92e51db4cc4c1727712c736dcba5f79d369 (patch) | |
| tree | 1f58edaaad389837a7652daebab246125762240e /src/zenserver | |
| parent | 5.5.13 (diff) | |
| download | zen-8b8de92e51db4cc4c1727712c736dcba5f79d369.tar.xz zen-8b8de92e51db4cc4c1727712c736dcba5f79d369.zip | |
Insights-compatible memory tracking (#214)
This change introduces support for tracing of memory allocation activity. The code is ported from UE5, and Unreal Insights can be used to analyze the output. This is currently only fully supported on Windows, but will be extended to Mac/Linux in the near future.
To activate full memory tracking, pass `--trace=memory` on the commandline alongside `--tracehost=<ip>` or `-tracefile=<path>`. For more control over how much detail is traced you can instead pass some combination of `callstack`, `memtag`, `memalloc` instead. In practice, `--trace=memory` is an alias for `--trace=callstack,memtag,memalloc`). For convenience we also support `--trace=memory_light` which omits call stacks.
This change also introduces multiple memory allocators, which may be selected via command-line option `--malloc=<allocator>`:
* `mimalloc` - mimalloc (default, same as before)
* `rpmalloc` - rpmalloc is another high performance allocator for multithreaded applications which may be a better option than mimalloc (to be evaluated). Due to toolchain limitations this is currently only supported on Windows.
* `stomp` - an allocator intended to be used during development/debugging to help track down memory issues such as use-after-free or out-of-bounds access. Currently only supported on Windows.
* `ansi` - fallback to default system allocator
Diffstat (limited to 'src/zenserver')
| -rw-r--r-- | src/zenserver/config.cpp | 10 | ||||
| -rw-r--r-- | src/zenserver/config.h | 6 | ||||
| -rw-r--r-- | src/zenserver/diag/logging.cpp | 5 | ||||
| -rw-r--r-- | src/zenserver/main.cpp | 24 |
4 files changed, 33 insertions, 12 deletions
diff --git a/src/zenserver/config.cpp b/src/zenserver/config.cpp index bedab7049..0108e8b9f 100644 --- a/src/zenserver/config.cpp +++ b/src/zenserver/config.cpp @@ -593,6 +593,9 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) options.add_options()("detach", "Indicate whether zenserver should detach from parent process group", cxxopts::value<bool>(ServerOptions.Detach)->default_value("true")); + options.add_options()("malloc", + "Configure memory allocator subsystem", + cxxopts::value(ServerOptions.MemoryOptions)->default_value("mimalloc")); // clang-format off options.add_options("logging") @@ -713,6 +716,13 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) #if ZEN_WITH_TRACE options.add_option("ue-trace", "", + "trace", + "Specify which trace channels should be enabled", + cxxopts::value<std::string>(ServerOptions.TraceChannels)->default_value(""), + ""); + + options.add_option("ue-trace", + "", "tracehost", "Hostname to send the trace to", cxxopts::value<std::string>(ServerOptions.TraceHost)->default_value(""), diff --git a/src/zenserver/config.h b/src/zenserver/config.h index 5c56695f3..c7781aada 100644 --- a/src/zenserver/config.h +++ b/src/zenserver/config.h @@ -176,9 +176,11 @@ struct ZenServerOptions std::string Loggers[zen::logging::level::LogLevelCount]; std::string ScrubOptions; #if ZEN_WITH_TRACE - std::string TraceHost; // Host name or IP address to send trace data to - std::string TraceFile; // Path of a file to write a trace + std::string TraceChannels; // Trace channels to enable + std::string TraceHost; // Host name or IP address to send trace data to + std::string TraceFile; // Path of a file to write a trace #endif + std::string MemoryOptions; // Memory allocation options std::string CommandLine; }; diff --git a/src/zenserver/diag/logging.cpp b/src/zenserver/diag/logging.cpp index 595be70cb..0d96cd8d6 100644 --- a/src/zenserver/diag/logging.cpp +++ b/src/zenserver/diag/logging.cpp @@ -6,6 +6,7 @@ #include <zencore/filesystem.h> #include <zencore/fmtutils.h> +#include <zencore/memory/llm.h> #include <zencore/session.h> #include <zencore/string.h> #include <zenutil/logging.h> @@ -20,6 +21,8 @@ namespace zen { void InitializeServerLogging(const ZenServerOptions& InOptions) { + UE_MEMSCOPE(ELLMTag::Logging); + const LoggingOptions LogOptions = {.IsDebug = InOptions.IsDebug, .IsVerbose = false, .IsTest = InOptions.IsTest, @@ -79,6 +82,8 @@ InitializeServerLogging(const ZenServerOptions& InOptions) void ShutdownServerLogging() { + UE_MEMSCOPE(ELLMTag::Logging); + zen::ShutdownLogging(); } diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp index 2fb01ebf1..4444241cc 100644 --- a/src/zenserver/main.cpp +++ b/src/zenserver/main.cpp @@ -17,16 +17,15 @@ #include <zencore/trace.h> #include <zenhttp/httpserver.h> +#include <zencore/memory/fmalloc.h> +#include <zencore/memory/memory.h> +#include <zencore/memory/memorytrace.h> +#include <zencore/memory/newdelete.h> + #include "config.h" #include "diag/logging.h" #include "sentryintegration.h" -#if ZEN_USE_MIMALLOC -ZEN_THIRD_PARTY_INCLUDES_START -# include <mimalloc-new-delete.h> -ZEN_THIRD_PARTY_INCLUDES_END -#endif - #if ZEN_PLATFORM_WINDOWS # include <zencore/windows.h> # include "windows/service.h" @@ -354,9 +353,6 @@ test_main(int argc, char** argv) int main(int argc, char* argv[]) { -#if ZEN_USE_MIMALLOC - mi_version(); -#endif using namespace zen; if (argc >= 2) @@ -433,9 +429,17 @@ main(int argc, char* argv[]) { TraceInit("zenserver"); } - atexit(TraceShutdown); #endif // ZEN_WITH_TRACE +#if ZEN_WITH_MEMTRACK + FMalloc* TraceMalloc = MemoryTrace_Create(GMalloc); + if (TraceMalloc != GMalloc) + { + GMalloc = TraceMalloc; + MemoryTrace_Initialize(); + } +#endif + #if ZEN_PLATFORM_WINDOWS if (ServerOptions.InstallService) { |