TraceLog header created by create_standalone.py is not standalone

The TraceLog module source code includes a Python script called create_standalone.py. This script creates a single header which, seemingly, should be usable out of the UE build tree for integration of third party libraries with tracing. I wanted to use this in a custom build of the IREE runtime library (part of the experimental NNERuntimeIREE plugin) to redirect the tracing of the library to Unreal Insights, using a custom “tracing provider” (I am not actually if it is possible to get an externally-built DLL to use the common UE tracing client, for now I was just trying to map IREE trace calls to TRACE_LOG events).

However, I have found that the header has still many dependencies to UE facilities (varying depending on whether TRACE_IMPLEMENT is 0 or 1): AutoRTFM API, ON_SCOPE_EXIT, FPlatformString, several G* global variables, lz4.h … Some of these are relatively easy to address (e.g. ON_SCOPE_EXIT is a single header and I think AutoRTFM can be limited to just the headers of the module if its functionality is disabled), but copying source files from UE to the build tree is tedious and brittle.

Is create_standalone.py meant to be used in a different way? Or is it outdated and does not account for changes in TraceLog that bring new dependencies?

Hello Javier,

You’re correct on all counts here. It’s a way to use Trace and a subset of the instrumentation primitives that Insights supports. Zen uses it for example. The script had however got a little stale but has now been updated on UE5/Main as of 51294058. The lz4.h include is required, LZ4 is a dependency which is available from Github or can be copied from elsewhere in UE’s tree.

Usage is fairly straightforward;

1) “python x:\ue\Engine\Source\Runtime\TraceLog\create_standalone.py d:\outdir” - this creates an amalgamated trace.h file in “outdir”.

2) In a .cpp file, “include <trace.h>” with the TRACE_IMPLEMENT=1 macro defined.

3) The API for CPU scopes and tracing to sockets/files is in the “epilogue” section of trace.h

Zen can be used a reference for use and integration too; https://github.com/EpicGames/zen/

-Martin.