1、如果新建工程时没有使能WPP,则在工程属性中的 Wpp Tracing->General->Run Wpp Tracing->Yes;
Wpp Tracing->File Options->Scan Configuration Data->Trace.h; 然后复制Trace.h文件到工程目录下。
2、打开Trace.h, 修改#define WPP_CONTROL_GUIDS 的定义。需要使用新的GUID,改为工程名,文件名。
#define WPP_CONTROL_GUIDS \
WPP_DEFINE_CONTROL_GUID( \
工程名Guid, (xxxxxxxx,xxxx,xxxx,xxxx,xxxxxxxxxxxx), \
\
WPP_DEFINE_BIT(FILE_NAME1) \
WPP_DEFINE_BIT(FILE_NAME2) \
WPP_DEFINE_BIT(FILE_NAME3) \
WPP_DEFINE_BIT(FILE_NAME4) \
)
其中新的GUID可以用Tools中的Create GUID 产生,可选不同的格式。
3、在需要打印log的源文件开始处添加头文件等,如 driver.c 文件需要添加#include "Trace.h" 和 #include "driver.tmh"
#include "driver.h" // 原来就有
#include "Trace.h"
#include "driver.tmh"
4、在需要打印log的地方使用
FUNC TraceEvents(LEVEL, FLAGS, MSG, ...);
如 TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, "%!FUNC! Entry");
----------------------------------------------------------------------------
https://docs.microsoft.com/zh-tw/windows-hardware/drivers/devtest/wpp-software-tracing
https://docs.microsoft.com/zh-cn/windows-hardware/drivers/devtest/wpp-software-tracing
Use Windows software trace preprocessor (WPP) to trace the operation of a software component (trace provider). A trace provider can be one of the following:
-
A kernel-mode driver.
-
A user-mode driver, application, or dynamic-link library (DLL).
When should you use WPP software tracing? WPP software tracing is primarily intended for debugging code during development. If you want to publish events that can be consumed by applications interested in structured ETW events, in addition to tracing during development, use the following:
- For kernel-mode drivers, use the Event Tracing for Windows (ETW) API.
- For user-mode drivers or applications, use the Event Tracing (Windows Desktop) API.