Figure 1 Counting Function Calls

void _penter ( void )
{
    if processing turned off
    {
        return
    }
    Get the return address
    Find the module which contains the return address
    If the module is not found
    {
        Initialize the new module data
        Load the module data
    }
    Find the function associated with that address in the module
    Increment the execution count for that function
}
Figure 2 File Handling for SWS
/*———————————————————————————————————
      John Robbins - Bugslayer Column - October 2000 MSDN Magazine
———————————————————————————————————*/
#ifndef _SWSFILEFORMAT_H
#define _SWSFILEFORMAT_H

/*//////////////////////////////////////////////////////////////////////
                         Defines and Structures
//////////////////////////////////////////////////////////////////////*/
// The SWS file signature (SWS0).
#define SIG_SWSFILE '0SWS'
// The SDW file signature (SDW0)
#define SIG_SDWFILE '0WDS'

// Flags specified in the file headers.
// Bit 0: 1 = UNICODE file.  0 = NOT UNICODE.
#define UNICODE_SWSFILE 0x00001
#define UNICODE_SWDFILE UNICODE_SWSFILE

// The maximum symbol size, in characters.  This number comes from the
// documentation on the C4786 error, which indicates that the maximum
// symbol size is 255 characters.
#define MAX_SYM_SIZE 256

/*//////////////////////////////////////////////////////////////////////
                      The SWS and SWD File Header
//////////////////////////////////////////////////////////////////////*/
// The SWS file header structure.  Each file starts with one of these.
typedef struct tag_SWSFILEHEADER
{
    // The file signature.  See the SIG_* defines above.
    DWORD dwSignature ;
    // The link time for the binary associated with this file.
    DWORD dwLinkTime ;
    // The number of entries in this file.
    DWORD dwEntryCount ;
    // The flags field.
    DWORD dwFlags ;
} SWSFILEHEADER , * LPSWSFILEHEADER ;

// Map the SWD file header to the SWS file header.
typedef SWSFILEHEADER SWDFILEHEADER ;
typedef LPSWSFILEHEADER LPSWDFILEHEADER ;

/*//////////////////////////////////////////////////////////////////////
                       SWS File Entry Structures
//////////////////////////////////////////////////////////////////////*/
// For SWS files, the header dwEntryCount indicates how many of these
// structures follow the header.
typedef struct tag_SWSENTRY
{
    // The function address.
    DWORD_PTR dwFnAddr ;
    // The execution count for this function address.
    UINT uiExecCount ;
} SWSENTRY , * LPSWSENTRY ;

/*//////////////////////////////////////////////////////////////////////
                       SWD File Entry Structures
//////////////////////////////////////////////////////////////////////*/
// For SWD files, the header dwEntryCount indicates how many of these
// structures follow the header.
typedef struct tag_SDWENTRYA
{
    // The function address.
    DWORD_PTR dwFnAddr ;
    // The size of the function.  Depending on what the DBGHELP.DLL
    // symbol engine returns, this might be zero.
    DWORD dwSize ;
    // The function name.
    char szName[ MAX_SYM_SIZE ] ;
} SDWENTRYA , * LPSDWENTRYA ;

typedef struct tag_SDWENTRYW
{
    // The function address.
    DWORD_PTR dwFnAddr ;
    // The size of the function.  Depending on what the DBGHELP.DLL
    // symbol engine returns, this might be zero.
    DWORD dwSize ;
    // The function name.
    wchar_t szName[ MAX_SYM_SIZE ] ;
} SDWENTRYW , * LPSDWENTRYW ;

#ifdef _UNICODE
#define SDWENTRY SDWENTRYW
#define LPSDWENTRY LPSDWENTRYW
#else
#define SDWENTRY SDWENTRYA
#define LPSDWENTRY LPSDWENTRYA
#endif

#endif  // _SWSFILEFORMAT_H
Show: