wpp at application layer and use of macros

Hi,

Is there any simple sample which can give me some direction regarding
implementation of wpp at application layer.

Right now I have written a simple piece of code

#define WPP_CONTROL_GUIDS \
WPP_DEFINE_CONTROL_GUID{ } <br> WPP_DEFINE_BIT(FLAG_ONE)
WPP_DEFINE_BIT(FLAG_TWO)

void main()
{
WPP_INIT_TRACING();
}

Its giving lot of error as I understand its incomplete.

I am trying to write a simple application to log traces using wpp as a proof
of conecpt as I have my doubts regarding usage of wpp at application layer.

The tracedrv sample in wdk gives details of wpp and macro implementation at
driver layer. But there is no detail of its implementaion at user layer. eg
WPP_INIT_TRACING takes driverobject and registry path at driver layer, but
at application layer we dont have driver object, so what should we pass.

Further wdk\bin folder contains certain um template file, but I am unable to
figure out its usage…

Please suggest some sample or hints on the above problem

Thanks
Anshul Makkar

For a simple, *complete* and *working* app example, please just google
for the post I’ve mentioned earlier:

Subject: Re: What does the DDK compiler have that the Visual C++ 2005/8
doesn’t?
Sent: Wednesday, March 19, 2008 23:47
Newsgroups: microsoft.public.development.device.drivers
From: “Ivan Brugiolo [MSFT]”

Though, it needs some cleanup: remove non existing #includes, use
windows.h instead. I’ll repost this sample as it works for me, in a
separate message.

Regards,
–PA

anshul makkar wrote:
> Hi,
>
> Is there any simple sample which can give me some direction regarding
> implementation of wpp at application layer.
>
> Right now I have written a simple piece of code
>
> #define WPP_CONTROL_GUIDS <br>> WPP_DEFINE_CONTROL_GUID{ } <br>> WPP_DEFINE_BIT(FLAG_ONE)
> WPP_DEFINE_BIT(FLAG_TWO)
>
> void main()
> {
> WPP_INIT_TRACING();
> }
>
> Its giving lot of error as I understand its incomplete.
>
> I am trying to write a simple application to log traces using wpp as a
> proof of conecpt as I have my doubts regarding usage of wpp at
> application layer.
>
> The tracedrv sample in wdk gives details of wpp and macro implementation
> at driver layer. But there is no detail of its implementaion at user
> layer. eg WPP_INIT_TRACING takes driverobject and registry path at
> driver layer, but at application layer we dont have driver object, so
> what should we pass.
>
> Further wdk\bin folder contains certain um template file, but I am
> unable to figure out its usage…
>
> Please suggest some sample or hints on the above problem
>
> Thanks
> Anshul Makkar

Pavel A. wrote:

… I’ll repost this sample as it works for me, in a
separate message.

Here it goes:

------------- SOURCES -----------
TARGETNAME=testWPP
TARGETTYPE=PROGRAM
TARGETPATH=obj
UMENTRY=wmain
UMTYPE=console

TARGETLIBS=\
$(SDK_LIB_PATH)\ntdll.lib \
$(SDK_LIB_PATH)\kernel32.lib

INCLUDES=$(DDK_INC_PATH);

USE_MSVCRT=1
USE_NATIVE_EH=ASYNC
USE_STL=1
STL_VER=70
BUFFER_OVERFLOW_CHECKS=NTDLL
MSC_WARNING_LEVEL=/W3 /WX
C_DEFINES=$(C_DEFINES) -DUNICODE -D_UNICODE

SOURCES=testWPP.cpp

RUN_WPP= $(SOURCES) -scan:trace.h

_NT_TARGET_VERSION = $(_NT_TARGET_VERSION_WINXP)

------------------ trace.h -----------------------

#ifndef trace_h
#define trace_h

#define WPP_CONTROL_GUIDS \
WPP_DEFINE_CONTROL_GUID(TestWPPGuid,(11223344, AAAA, BBBB, CCCC, \
DDFFFF112233), \
WPP_DEFINE_BIT(MY_ERROR) \
WPP_DEFINE_BIT(MY_WARN) \
WPP_DEFINE_BIT(MY_NOISE))

// begin_wpp config
//
// FUNC TestWPPLog(LEVEL,MSG,…);
//
// end_wpp

#endif /* trace_h */

------------------------ testwpp.cpp ----------------------

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <strsafe.h>
#include <memory.h>

#include “trace.h”

//Following is needed because of some mess in levels vs. flags +pa
#define Verbose MY_NOISE //defined in trace.h
#define Error MY_ERROR

#if 1 //+pa enable debug of the wpp stuff. see the .tmh for details.
// This allows to duplicate traces (to ODS, dbgprint…) :
#define WPP_DEBUG printf(“\n”),printf
// This enables internal debug spew of wpp:
#define WppDebug(a,b) printf(“\n”),printf b
#endif // enable wpp debug

#include “testWPP.tmh” // file created by WPP

class TestClass {
private:
BYTE Array[256];
public:
TestClass();
virtual ~TestClass();
};

TestClass::TestClass(){
TestWPPLog(Verbose,“%s”, FUNCTION );
}

TestClass::~TestClass(){
TestWPPLog(Error,“%s”, FUNCTION );
}

int __cdecl wmain( int argc, WCHAR **argv)
{

#ifdef WppDebug
printf(“debug messages from WPP will be printed\n”);
#endif

#ifdef WPP_DEBUG
printf(“traces will be echoed to printf\n”);
#endif

WPP_INIT_TRACING( L"UmWppTest" );

TestWPPLog(Verbose,“WPP test - begin log”);

TestClass * p = new TestClass;

delete p;

TestWPPLog(Error,“WPP test - end log”);

WPP_CLEANUP();

return 0;
}
----------------- end------------------</memory.h></strsafe.h></stdlib.h></stdio.h></windows.h>

Hi Pavel,

Thanks a lot… Its compiling properly . Thanks

But still I am unable to see the log in the output file . The process I am
following is

  1. Tracepdb -f <tracewpp.pdb> //generates the tmf file

    2) I am saving the guid in trace.ctl file which I am supplying to tracelog
    command in next step.

    The content of the file is 11223344, AAAA, BBBB, CCCC, DDFFFF112233
    TestWPPGUID

    3) tracelog - start -guid <.ctl file> -f -
    flag 1

    4) execute traceWPP.exe
    5) stop the session using tracelog
    6) tracefmt to get the output file
    tracefmt trace.etl trace.out

    Please, confirm , whether I am missing something.

    Another important point that I want to clarify before implementing this for
    my project is how can I automatically generate etl file without starting
    tracelog file.

    Like in etl file using starttrace etc (starting a session), .etl file is
    automatically generated. So how similar thing can be achieved. This is an
    important requirement for me.
    Please if you can throw some light on that.

    Again, thanks a lot.

    Thanks
    Anshul Makkar

    On Wed, Jul 29, 2009 at 10:06 PM, Pavel A. wrote:

    > Pavel A. wrote:
    >
    >> … I’ll repost this sample as it works for me, in a separate message.
    >>
    >
    > Here it goes:
    >
    >
    >
    > ------------- SOURCES -----------
    > TARGETNAME=testWPP
    > TARGETTYPE=PROGRAM
    > TARGETPATH=obj
    > UMENTRY=wmain
    > UMTYPE=console
    >
    > TARGETLIBS=<br>> $(SDK_LIB_PATH)\ntdll.lib <br>> $(SDK_LIB_PATH)\kernel32.lib
    >
    > INCLUDES=$(DDK_INC_PATH);
    >
    > USE_MSVCRT=1
    > USE_NATIVE_EH=ASYNC
    > USE_STL=1
    > STL_VER=70
    > BUFFER_OVERFLOW_CHECKS=NTDLL
    > MSC_WARNING_LEVEL=/W3 /WX
    > C_DEFINES=$(C_DEFINES) -DUNICODE -D_UNICODE
    >
    > SOURCES=testWPP.cpp
    >
    > RUN_WPP= $(SOURCES) -scan:trace.h
    >
    > _NT_TARGET_VERSION = $(_NT_TARGET_VERSION_WINXP)
    >
    >
    > ------------------ trace.h -----------------------
    >
    > #ifndef trace_h
    > #define trace_h
    >
    > #define WPP_CONTROL_GUIDS <br>> WPP_DEFINE_CONTROL_GUID(TestWPPGuid,(11223344, AAAA, BBBB, CCCC, <br>> DDFFFF112233), <br>> WPP_DEFINE_BIT(MY_ERROR) <br>> WPP_DEFINE_BIT(MY_WARN) <br>> WPP_DEFINE_BIT(MY_NOISE))
    >
    > // begin_wpp config
    > //
    > // FUNC TestWPPLog(LEVEL,MSG,…);
    > //
    > // end_wpp
    >
    > #endif /* trace_h */
    >
    > ------------------------ testwpp.cpp ----------------------
    >
    > #include <windows.h>
    > #include <stdio.h>
    > #include <stdlib.h>
    > #include <strsafe.h>
    > #include <memory.h>
    >
    > #include “trace.h”
    >
    > //Following is needed because of some mess in levels vs. flags +pa
    > #define Verbose MY_NOISE //defined in trace.h
    > #define Error MY_ERROR
    >
    > #if 1 //+pa enable debug of the wpp stuff. see the .tmh for details.
    > // This allows to duplicate traces (to ODS, dbgprint…) :
    > #define WPP_DEBUG printf(“\n”),printf
    > // This enables internal debug spew of wpp:
    > #define WppDebug(a,b) printf(“\n”),printf b
    > #endif // enable wpp debug
    >
    > #include “testWPP.tmh” // file created by WPP
    >
    > class TestClass {
    > private:
    > BYTE Array[256];
    > public:
    > TestClass();
    > virtual ~TestClass();
    > };
    >
    > TestClass::TestClass(){
    > TestWPPLog(Verbose,“%s”, FUNCTION );
    > }
    >
    > TestClass::~TestClass(){
    > TestWPPLog(Error,“%s”, FUNCTION );
    > }
    >
    >
    > int __cdecl wmain( int argc, WCHAR **argv)
    > {
    >
    > #ifdef WppDebug
    > printf(“debug messages from WPP will be printed\n”);
    > #endif
    >
    > #ifdef WPP_DEBUG
    > printf(“traces will be echoed to printf\n”);
    > #endif
    >
    > WPP_INIT_TRACING( L"UmWppTest" );
    >
    > TestWPPLog(Verbose,“WPP test - begin log”);
    >
    > TestClass * p = new TestClass;
    >
    > delete p;
    >
    > TestWPPLog(Error,“WPP test - end log”);
    >
    > WPP_CLEANUP();
    >
    > return 0;
    > }
    > ----------------- end------------------
    >
    >
    > —
    > NTDEV is sponsored by OSR
    >
    > For our schedule of WDF, WDM, debugging and other seminars visit:
    > http://www.osr.com/seminars
    >
    > To unsubscribe, visit the List Server section of OSR Online at
    > http://www.osronline.com/page.cfm?name=ListServer
    ></memory.h></strsafe.h></stdlib.h></stdio.h></windows.h></tracewpp.pdb>

Start with traceview.
Just feed the pdb into it, no need to create tmf or ctl files.
( Create new log session, add provider, select method = PDB ).

–pa

anshul makkar wrote:

Hi Pavel,

Thanks a lot… Its compiling properly . Thanks

But still I am unable to see the log in the output file . The process I
am following is

  1. Tracepdb -f <tracewpp.pdb> //generates the tmf file
    >
    > 2) I am saving the guid in trace.ctl file which I am supplying to
    > tracelog command in next step.
    >
    > The content of the file is 11223344, AAAA, BBBB, CCCC, DDFFFF112233
    > TestWPPGUID
    >
    > 3) tracelog - start -guid <.ctl file> -f -
    > flag 1
    ></tracewpp.pdb>

I think it should be noted that instead of doing something like:

TestWPPLog(Error,“%s”,FUNCTION);

A better approach would be to do:

TestWPPLog(Error,“%!FUNC!”);

This way function name becomes part of the annotation in the PDB and is not a string in the executable. It also results in smaller logs. Here is a list of build in variables which can be used inside WPP messages. You can also display them by configuring TRACE_FORMAT_PREFIX.
Thanks,
Alex

%!FILE!
Displays the name of the source file from which the trace message was generated. This variable can also be used in the trace message prefix.

%!FLAGS!
Displays the value of the trace flags that enables the trace message. This variable can also be used in the trace message prefix.

%!FUNC!
Displays the function that generated the trace message. This variable can also be used in the trace message prefix.

%!LEVEL!
Displays the name of the trace level that enables the trace message. This variable can also be used in the trace message prefix.

%!LINE!
Displays line number of the line in the code that generated the trace prefix. This variable can also be used in the trace message prefix.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Pavel A.
Sent: Wednesday, July 29, 2009 9:36 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] wpp at application layer and use of macros

Pavel A. wrote:

… I’ll repost this sample as it works for me, in a
separate message.

Here it goes:

------------- SOURCES -----------
TARGETNAME=testWPP
TARGETTYPE=PROGRAM
TARGETPATH=obj
UMENTRY=wmain
UMTYPE=console

TARGETLIBS=\
$(SDK_LIB_PATH)\ntdll.lib \
$(SDK_LIB_PATH)\kernel32.lib

INCLUDES=$(DDK_INC_PATH);

USE_MSVCRT=1
USE_NATIVE_EH=ASYNC
USE_STL=1
STL_VER=70
BUFFER_OVERFLOW_CHECKS=NTDLL
MSC_WARNING_LEVEL=/W3 /WX
C_DEFINES=$(C_DEFINES) -DUNICODE -D_UNICODE

SOURCES=testWPP.cpp

RUN_WPP= $(SOURCES) -scan:trace.h

_NT_TARGET_VERSION = $(_NT_TARGET_VERSION_WINXP)

------------------ trace.h -----------------------

#ifndef trace_h
#define trace_h

#define WPP_CONTROL_GUIDS \
WPP_DEFINE_CONTROL_GUID(TestWPPGuid,(11223344, AAAA, BBBB, CCCC, \
DDFFFF112233), \
WPP_DEFINE_BIT(MY_ERROR) \
WPP_DEFINE_BIT(MY_WARN) \
WPP_DEFINE_BIT(MY_NOISE))

// begin_wpp config
//
// FUNC TestWPPLog(LEVEL,MSG,…);
//
// end_wpp

#endif /* trace_h */

------------------------ testwpp.cpp ----------------------

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <strsafe.h>
#include <memory.h>

#include “trace.h”

//Following is needed because of some mess in levels vs. flags +pa
#define Verbose MY_NOISE //defined in trace.h
#define Error MY_ERROR

#if 1 //+pa enable debug of the wpp stuff. see the .tmh for details.
// This allows to duplicate traces (to ODS, dbgprint…) :
#define WPP_DEBUG printf(“\n”),printf
// This enables internal debug spew of wpp:
#define WppDebug(a,b) printf(“\n”),printf b
#endif // enable wpp debug

#include “testWPP.tmh” // file created by WPP

class TestClass {
private:
BYTE Array[256];
public:
TestClass();
virtual ~TestClass();
};

TestClass::TestClass(){
TestWPPLog(Verbose,“%s”, FUNCTION );
}

TestClass::~TestClass(){
TestWPPLog(Error,“%s”, FUNCTION );
}

int __cdecl wmain( int argc, WCHAR **argv)
{

#ifdef WppDebug
printf(“debug messages from WPP will be printed\n”);
#endif

#ifdef WPP_DEBUG
printf(“traces will be echoed to printf\n”);
#endif

WPP_INIT_TRACING( L"UmWppTest" );

TestWPPLog(Verbose,“WPP test - begin log”);

TestClass * p = new TestClass;

delete p;

TestWPPLog(Error,“WPP test - end log”);

WPP_CLEANUP();

return 0;
}
----------------- end------------------


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</memory.h></strsafe.h></stdlib.h></stdio.h></windows.h>

WPP works both for kernel and for user mode and the usage is strikingly similar. For user mode you need to add the following to your makefile or sources file (whichever one you are using):

RUN_WPP= $(SOURCES)

For kernel mode there is also a (-km) switch after sources.
Here is a simple program which uses WPP in the user mode. Note that in user mode WPP_INIT_TRACING() macro takes one parameter, not two which should just be NULL. For kernel mode unless your code needs to work on W2K the parameters to WPP_INIT_TRACING() can/should also be NULL as they are not used.
Sample bellow uses flags, if you want a sample which uses both levels and flags there should be one in the WDK.

If you search for “WPP tracing presentations” on the net you will find some talks going into the details of how it works, etc… There should also be an FAQ which most people find helpful.
Alex

#include <windows.h>

#define WPP_CONTROL_GUIDS <br> WPP_DEFINE_CONTROL_GUID(CtlGuid,(a044090f,3d9d,48cf,b7ee,9fb114702dc1), <br> WPP_DEFINE_BIT(Info))

#include “example1.tmh”

int
__cdecl
main(
)
{
WPP_INIT_TRACING(NULL);

DoTraceMessage(Info, “Hello World”);

WPP_CLEANUP();

return ERROR_SUCCESS;
}

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of anshul makkar
Sent: Wednesday, July 29, 2009 8:34 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] wpp at application layer and use of macros

Hi,

Is there any simple sample which can give me some direction regarding implementation of wpp at application layer.

Right now I have written a simple piece of code

#define WPP_CONTROL_GUIDS <br> WPP_DEFINE_CONTROL_GUID{ } <br> WPP_DEFINE_BIT(FLAG_ONE)
WPP_DEFINE_BIT(FLAG_TWO)

void main()
{
WPP_INIT_TRACING();
}

Its giving lot of error as I understand its incomplete.

I am trying to write a simple application to log traces using wpp as a proof of conecpt as I have my doubts regarding usage of wpp at application layer.

The tracedrv sample in wdk gives details of wpp and macro implementation at driver layer. But there is no detail of its implementaion at user layer. eg WPP_INIT_TRACING takes driverobject and registry path at driver layer, but at application layer we dont have driver object, so what should we pass.

Further wdk\bin folder contains certain um template file, but I am unable to figure out its usage…

Please suggest some sample or hints on the above problem

Thanks
Anshul Makkar
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</windows.h>