From baf8e6fe80a7e891b0922cdb3cee1ecdd8f3d9b6 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 22 Feb 2020 14:16:04 +0100 Subject: [PATCH] No support for sampling on 32-bit windows. Note that 32-bit applications running on 64-bit windows will perform sampling. --- client/TracySysTrace.cpp | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/client/TracySysTrace.cpp b/client/TracySysTrace.cpp index 70ba412f..8725798e 100644 --- a/client/TracySysTrace.cpp +++ b/client/TracySysTrace.cpp @@ -160,6 +160,14 @@ bool SysTraceStart() { s_pid = GetCurrentProcessId(); +#if defined _WIN64 + constexpr bool isOs64Bit = true; +#else + BOOL _iswow64; + IsWow64Process( GetCurrentProcess(), &_iswow64 ); + const bool isOs64Bit = _iswow64; +#endif + TOKEN_PRIVILEGES priv = {}; priv.PrivilegeCount = 1; priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; @@ -173,15 +181,20 @@ bool SysTraceStart() const auto status = GetLastError(); if( status != ERROR_SUCCESS ) return false; - TRACE_PROFILE_INTERVAL interval = {}; - interval.Interval = 10000; - const auto intervalStatus = TraceSetInformation( 0, TraceSampledProfileIntervalInfo, &interval, sizeof( interval ) ); - if( intervalStatus != ERROR_SUCCESS ) return false; + if( isOs64Bit ) + { + TRACE_PROFILE_INTERVAL interval = {}; + interval.Interval = 10000; + const auto intervalStatus = TraceSetInformation( 0, TraceSampledProfileIntervalInfo, &interval, sizeof( interval ) ); + if( intervalStatus != ERROR_SUCCESS ) return false; + } const auto psz = sizeof( EVENT_TRACE_PROPERTIES ) + sizeof( KERNEL_LOGGER_NAME ); s_prop = (EVENT_TRACE_PROPERTIES*)tracy_malloc( psz ); memset( s_prop, 0, sizeof( EVENT_TRACE_PROPERTIES ) ); - s_prop->EnableFlags = EVENT_TRACE_FLAG_CSWITCH | EVENT_TRACE_FLAG_DISPATCHER | EVENT_TRACE_FLAG_THREAD | EVENT_TRACE_FLAG_PROFILE; + ULONG flags = EVENT_TRACE_FLAG_CSWITCH | EVENT_TRACE_FLAG_DISPATCHER | EVENT_TRACE_FLAG_THREAD; + if( isOs64Bit ) flags |= EVENT_TRACE_FLAG_PROFILE; + s_prop->EnableFlags = flags; s_prop->LogFileMode = EVENT_TRACE_REAL_TIME_MODE; s_prop->Wnode.BufferSize = psz; s_prop->Wnode.Flags = WNODE_FLAG_TRACED_GUID; @@ -210,14 +223,17 @@ bool SysTraceStart() return false; } - CLASSIC_EVENT_ID stackId; - stackId.EventGuid = PerfInfoGuid; - stackId.Type = 46; - const auto stackStatus = TraceSetInformation( s_traceHandle, TraceStackTracingInfo, &stackId, sizeof( stackId ) ); - if( stackStatus != ERROR_SUCCESS ) + if( isOs64Bit ) { - tracy_free( s_prop ); - return false; + CLASSIC_EVENT_ID stackId; + stackId.EventGuid = PerfInfoGuid; + stackId.Type = 46; + const auto stackStatus = TraceSetInformation( s_traceHandle, TraceStackTracingInfo, &stackId, sizeof( stackId ) ); + if( stackStatus != ERROR_SUCCESS ) + { + tracy_free( s_prop ); + return false; + } } #ifdef UNICODE