| 342 | } |
| 343 | |
| 344 | bool SysTraceStart( int64_t& samplingPeriod ) |
| 345 | { |
| 346 | if( !_GetThreadDescription ) _GetThreadDescription = (t_GetThreadDescription)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "GetThreadDescription" ); |
| 347 | |
| 348 | s_pid = GetCurrentProcessId(); |
| 349 | |
| 350 | #if defined _WIN64 |
| 351 | constexpr bool isOs64Bit = true; |
| 352 | #else |
| 353 | BOOL _iswow64; |
| 354 | IsWow64Process( GetCurrentProcess(), &_iswow64 ); |
| 355 | const bool isOs64Bit = _iswow64; |
| 356 | #endif |
| 357 | |
| 358 | TOKEN_PRIVILEGES priv = {}; |
| 359 | priv.PrivilegeCount = 1; |
| 360 | priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; |
| 361 | if( LookupPrivilegeValue( nullptr, SE_SYSTEM_PROFILE_NAME, &priv.Privileges[0].Luid ) == 0 ) return false; |
| 362 | |
| 363 | HANDLE pt; |
| 364 | if( OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &pt ) == 0 ) return false; |
| 365 | const auto adjust = AdjustTokenPrivileges( pt, FALSE, &priv, 0, nullptr, nullptr ); |
| 366 | CloseHandle( pt ); |
| 367 | if( adjust == 0 ) return false; |
| 368 | const auto status = GetLastError(); |
| 369 | if( status != ERROR_SUCCESS ) return false; |
| 370 | |
| 371 | if( isOs64Bit ) |
| 372 | { |
| 373 | TRACE_PROFILE_INTERVAL interval = {}; |
| 374 | interval.Interval = GetSamplingInterval(); |
| 375 | const auto intervalStatus = TraceSetInformation( 0, TraceSampledProfileIntervalInfo, &interval, sizeof( interval ) ); |
| 376 | if( intervalStatus != ERROR_SUCCESS ) return false; |
| 377 | samplingPeriod = GetSamplingPeriod(); |
| 378 | } |
| 379 | |
| 380 | const auto psz = sizeof( EVENT_TRACE_PROPERTIES ) + sizeof( KERNEL_LOGGER_NAME ); |
| 381 | s_prop = (EVENT_TRACE_PROPERTIES*)tracy_malloc( psz ); |
| 382 | memset( s_prop, 0, sizeof( EVENT_TRACE_PROPERTIES ) ); |
| 383 | ULONG flags = 0; |
| 384 | #ifndef TRACY_NO_CONTEXT_SWITCH |
| 385 | flags = EVENT_TRACE_FLAG_CSWITCH | EVENT_TRACE_FLAG_DISPATCHER | EVENT_TRACE_FLAG_THREAD; |
| 386 | #endif |
| 387 | #ifndef TRACY_NO_SAMPLING |
| 388 | if( isOs64Bit ) flags |= EVENT_TRACE_FLAG_PROFILE; |
| 389 | #endif |
| 390 | s_prop->EnableFlags = flags; |
| 391 | s_prop->LogFileMode = EVENT_TRACE_REAL_TIME_MODE; |
| 392 | s_prop->Wnode.BufferSize = psz; |
| 393 | s_prop->Wnode.Flags = WNODE_FLAG_TRACED_GUID; |
| 394 | #ifdef TRACY_TIMER_QPC |
| 395 | s_prop->Wnode.ClientContext = 1; |
| 396 | #else |
| 397 | s_prop->Wnode.ClientContext = 3; |
| 398 | #endif |
| 399 | s_prop->Wnode.Guid = SystemTraceControlGuid; |
| 400 | s_prop->BufferSize = 1024; |
| 401 | s_prop->MinimumBuffers = std::thread::hardware_concurrency() * 4; |
no test coverage detected