EnableThreadProfiling function

Enables thread profiling on the specified thread.


DWORD APIENTRY EnableThreadProfiling(
  _In_  HANDLE  ThreadHandle,
  _In_  DWORD   Flags,
  _In_  DWORD64 HardwareCounters,
  _Out_ HANDLE  PerformanceDataHandle


ThreadHandle [in]

The handle to the thread on which you want to enable profiling. This must be the current thread.

Flags [in]

To receive thread profiling data such as context switch count, set this parameter to THREAD_PROFILING_FLAG_DISPATCH; otherwise, set to 0.

HardwareCounters [in]

To receive hardware performance counter data, set this parameter to a bitmask that identifies the hardware counters to collect. You can specify up to 16 performance counters. Each bit relates directly to the zero-based hardware counter index for the hardware performance counters that you configured. Set to zero if you are not collecting hardware counter data. If you set a bit for a hardware counter that has not been configured, the counter value that is read for that counter is zero.

PerformanceDataHandle [out]

An opaque handle that you use when calling the ReadThreadProfilingData and DisableThreadProfiling functions.

Return value

Returns ERROR_SUCCESS if the call is successful; otherwise, a system error code (see Winerror.h).


You must call the DisableThreadProfiling function before exiting the thread.

To profile hardware performance counters, you need a driver to configure the counters. The performance counters are configured globally for the system, so every thread has access to the same hardware counter data. The counters must be configured before you enable profiling. For information on configuring hardware performance counters, see the KeSetHardwareCounterConfiguration function in the Windows Driver Kit (WDK).


Minimum supported client

Windows 7 [desktop apps only]

Minimum supported server

Windows Server 2008 R2 [desktop apps only]


Winbase.h (include Windows.h)





See also