Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2613035
  • 博文数量: 877
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 5921
  • 用 户 组: 普通用户
  • 注册时间: 2013-12-05 12:25
个人简介

技术的乐趣在于分享,欢迎多多交流,多多沟通。

文章分类

全部博文(877)

文章存档

2021年(2)

2016年(20)

2015年(471)

2014年(358)

2013年(26)

分类: Windows平台

2015-05-07 13:19:53

The following sample code shows how to trace function entry and exit calls. This code works in Windows 2000 and later versions of Windows.

First, add the definition of the  macro to a source or header file. When defining the , define a flag for function tracing, as shown in the following example:

#define WPP_CONTROL_GUIDS \
    WPP_DEFINE_CONTROL_GUID(CtlGuid,(a044090f,3d9d,48cf,b7ee,9fb114702dc1),  \
        WPP_DEFINE_BIT(ERROR)                \
        WPP_DEFINE_BIT(Unusual)              \
        WPP_DEFINE_BIT(Noise)                \
 WPP_DEFINE_BIT(FuncTrace) )
 

Then, in the same file, add the configuration data for the trace messages. Start the configuration data with a begin_wpp config statement, and end it with an end_wpp statement. Then add the definitions for the macros that support FuncTrace.

// begin_wpp config
// FUNC FuncEntry();
// FUNC FuncExit();
// USESUFFIX(FuncEntry, " Entry to %!FUNC!");
// USESUFFIX(FuncExit, " Exit from %!FUNC!");
// end_wpp
 
// Map the null flags used by Entry/Exit to a function called FuncTrace
#define WPP__ENABLED() WPP_LEVEL_ENABLED(FuncTrace)
#define WPP__LOGGER() WPP_LEVEL_LOGGER(FuncTrace)
 

In the source file, surround the function code with FuncEntry() and FuncExit() calls.

#include "mytrace.h"
#include "entryexit.tmh"
void examplesub(int x)
{
    FuncEntry();
    // function code
    FuncExit();
}

For example:

#include "mytrace.h"
#include "entryexit.tmh"
void examplesub(int x)
{
    FuncEntry();
       DoTraceMessage(Noise, "Value is %d",x);
    FuncExit();
}

If you put configuration data in a header file, use the -scan parameter to direct WPP to look for configuration data in the specified file. In this example, the configuration data is in the mytrace.h file.

RUN_WPP=$(SOURCES) -km -scan:mytrace.h

Note  You must not specify the -km switch in the RUN_WPP directive for user-mode applications or dynamic-link libraries (DLLs).

For a complete list of the optional parameters for RUN_WPP, see .

阅读(525) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~