Memory profiling support for allocations made from a title’s custom allocator

Steven Pratschner

Starting with the 2303.02 release of PIX on Windows, PIX timing captures can track memory allocations and frees made by your custom memory allocators.

By calling the new APIs, PIXRecordMemoryAllocationEvent and PIXRecordMemoryFreeEvent, you provide PIX with the data it needs to display information about all memory allocations and frees made from within your title’s custom memory allocators. The data shown for your custom allocators is the same as the data shown for allocations made using either VirtualAlloc or HeapAlloc.

PIXRecordMemoryAllocationEvent and PIXRecordMemoryFreeEvent are available in version 1.0.230302001 or later of the WinPIXEventRuntime.

To call PIXRecordMemoryAllocationEvent and PIXRecordMemoryFreeEvent, include pix3.h in your source code, and ensure that USE_PIX is defined. Call the APIs as shown in the following example.

#include “pix3.h”

void* TitleAllocate(size_t size, UINT64 metadata)

{

    void *pAddress = layer_allocate(size);

    if (pAddress == NULL)

        return NULL;

    PIXRecordMemoryAllocationEvent(TITLE_ALLOCATOR, pAddress, size,

                                   metadata);

    return pAddress;

}

 

void TitleFree(void* baseAddress, size_t size, UINT64 metadata)

{

    layer_free(baseAddress, 0);

    PIXRecordMemoryFreeEvent(TITLE_ALLOCATOR, baseAddress, size,

                             metadata);

}

To see memory events corresponding to your calls to PIXRecordMemoryAllocationEvent and PIXRecordMemoryFreeEvent, select the Custom Allocator events check box before starting a timing capture:

Image winpix custom allocators options pane

 

PIX displays information about your custom allocations and frees alongside the data for other allocation types in the Range Details view of timing captures.  Custom allocator events are grouped by allocator and shown under the Title Allocators by Id node.  The allocator id is the first parameter to PIXRecordMemoryAllocationEvent.  Note that the last parameter to PIXRecordMemoryAllocationEvent, the metadata parameter, is currently not displayed in PIX.

 

Image winpix custom allocators range details

See Analyzing Memory usage and performance for more details on the memory profiling features in Timing Captures.

As always, please keep sending feedback and bug requests our way using the feedback button in the upper right corner of the PIX UI.

Steven.

0 comments

Comments are closed. Login to edit/delete your existing comments

Feedback usabilla icon