aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/trace.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2026-04-23 18:16:57 +0200
committerStefan Boberg <[email protected]>2026-04-23 18:16:57 +0200
commit0232b991cd7d8e3a2114ea30e4591dd3e7b65c36 (patch)
tree94730e7594fd09ae1fa820391ce311f6daf13905 /src/zencore/trace.cpp
parentFix forward declaration order for s_GotSigWinch and SigWinchHandler (diff)
parenttrace: declare Region event name fields as AnsiString (#1012) (diff)
downloadarchived-zen-sb/zen-help.tar.xz
archived-zen-sb/zen-help.zip
Merge branch 'main' into sb/zen-helpsb/zen-help
- Combine HelpCommand (this branch) with HistoryCommand (main) in zen CLI dispatcher - Keep filter-aware TuiPickOne rewrite; adopt main's ASCII arrow glyphs in doc comment
Diffstat (limited to 'src/zencore/trace.cpp')
-rw-r--r--src/zencore/trace.cpp53
1 files changed, 51 insertions, 2 deletions
diff --git a/src/zencore/trace.cpp b/src/zencore/trace.cpp
index 7c195e69f..d6a0b2e92 100644
--- a/src/zencore/trace.cpp
+++ b/src/zencore/trace.cpp
@@ -6,7 +6,9 @@
# include <zencore/zencore.h>
# include <zencore/commandline.h>
# 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
@@ -24,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(UE::Trace::AnsiString, RegionName)
+TRACE_EVENT_FIELD(UE::Trace::AnsiString, 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
@@ -38,7 +55,7 @@ TraceConfigure(const TraceOptions& Options)
auto ProcessTraceArg = [&](const std::string_view& Arg) {
if (Arg == "default"sv)
{
- ProcessChannelList("cpu,log"sv);
+ ProcessChannelList("cpu,zenlog"sv);
}
else if (Arg == "memory"sv)
{
@@ -53,6 +70,12 @@ TraceConfigure(const TraceOptions& Options)
// memtag actually traces to the memalloc channel
ProcessChannelList("memalloc"sv);
}
+ else if (Arg == "log"sv)
+ {
+ // Upstream UE trace reserves "log" for printf-style Logging.* events, which zen
+ // does not emit. Redirect to the zenlog channel so --trace=log does what users expect.
+ ProcessChannelList("zenlog"sv);
+ }
else
{
// Presume that the argument is a trace channel name
@@ -121,7 +144,7 @@ TraceInit(std::string_view ProgramName)
const char* CommandLineString = "";
# endif
- trace::ThreadRegister("main", /* system id */ 0, /* sort id */ 0);
+ trace::ThreadRegister("main", /* system id */ GetCurrentThreadId(), /* sort id */ -1);
trace::DescribeSession(ProgramName,
# if ZEN_BUILD_DEBUG
trace::Build::Debug,
@@ -163,6 +186,32 @@ 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(RegionName.data(), int32_t(RegionName.size()))
+ << RegionBeginWithId.Category(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)
{