diff options
| author | Stefan Boberg <[email protected]> | 2026-04-20 11:03:13 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-04-20 11:03:13 +0200 |
| commit | 8b842f161ee114ec9e10da1aa8efe2306836805a (patch) | |
| tree | 53c20f4760491c5ddb1659ba7a6066cffab8e1cf /src/zencore/trace.cpp | |
| parent | zencore: implement SearchPathForExecutable on POSIX (#981) (diff) | |
| download | archived-zen-8b842f161ee114ec9e10da1aa8efe2306836805a.tar.xz archived-zen-8b842f161ee114ec9e10da1aa8efe2306836805a.zip | |
added support for trace regions (#984)
- Introduces a UE-trace Region primitive in `zencore/trace.{h,cpp}` for marking named, potentially long-running intervals of work that Unreal Insights render as banners in the timeline, separately from CPU scopes.
- New API:
- `uint64_t TraceBeginRegion(RegionName, Category={})` / `void TraceEndRegion(RegionId)` for manual begin/end pairs.
- `ScopedTraceRegion` RAII helper plus `ZEN_TRACE_REGION(name)` / `ZEN_TRACE_REGION_CAT(name, category)` macros for scope-based use.
- Emits the `Misc.RegionBeginWithId` / `Misc.RegionEndWithId` trace events (paired by a `GetHifreqTimerValue()`-derived id).
- Full no-op fallback under `#if !ZEN_WITH_TRACE` so callers compile in all configurations.
- Annotates `GcScheduler::CollectGarbage` with `ZEN_TRACE_REGION_CAT("GcScheduler::CollectGarbage", "gc")` as a first caller — makes GC passes visible as banners in Insights without relying on the existing `ZEN_TRACE_CPU` scope alone (which doesn't render as a region).
Diffstat (limited to 'src/zencore/trace.cpp')
| -rw-r--r-- | src/zencore/trace.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/zencore/trace.cpp b/src/zencore/trace.cpp index d7084bbd1..6e2eea1c7 100644 --- a/src/zencore/trace.cpp +++ b/src/zencore/trace.cpp @@ -8,6 +8,7 @@ # include <zencore/string.h> # include <zencore/thread.h> # include <zencore/logging.h> +# include <zencore/timer.h> # define TRACE_IMPLEMENT 1 # undef _WINSOCK_DEPRECATED_NO_WARNINGS @@ -25,6 +26,21 @@ # include <zencore/memory/fmalloc.h> # include <zencore/memory/memorytrace.h> +namespace { + +TRACE_EVENT_BEGIN(Misc, RegionBeginWithId, NoSync) +TRACE_EVENT_FIELD(uint64, CycleAndId) +TRACE_EVENT_FIELD(uint8[], RegionName) +TRACE_EVENT_FIELD(uint8[], Category) +TRACE_EVENT_END() + +TRACE_EVENT_BEGIN(Misc, RegionEndWithId, NoSync) +TRACE_EVENT_FIELD(uint64, Cycle) +TRACE_EVENT_FIELD(uint64, RegionId) +TRACE_EVENT_END() + +} // namespace + namespace zen { void @@ -164,6 +180,34 @@ TraceStop() return false; } +uint64_t +TraceBeginRegion(std::string_view RegionName, std::string_view Category) +{ + uint64_t RegionId = GetHifreqTimerValue(); + TRACE_LOG(Misc, RegionBeginWithId, true) << RegionBeginWithId.CycleAndId(RegionId) + << RegionBeginWithId.RegionName(reinterpret_cast<const uint8*>(RegionName.data()), + int32_t(RegionName.size())) + << RegionBeginWithId.Category(reinterpret_cast<const uint8*>(Category.data()), + int32_t(Category.size())); + return RegionId; +} + +void +TraceEndRegion(uint64_t RegionId) +{ + TRACE_LOG(Misc, RegionEndWithId, true) << RegionEndWithId.Cycle(GetHifreqTimerValue()) << RegionEndWithId.RegionId(RegionId); +} + +ScopedTraceRegion::ScopedTraceRegion(std::string_view RegionName, std::string_view Category) +: m_RegionId(TraceBeginRegion(RegionName, Category)) +{ +} + +ScopedTraceRegion::~ScopedTraceRegion() +{ + TraceEndRegion(m_RegionId); +} + bool GetTraceOptionsFromCommandline(TraceOptions& OutOptions) { |