{"id":6059,"date":"2023-03-13T17:16:47","date_gmt":"2023-03-14T00:16:47","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/pix\/?p=6059"},"modified":"2023-03-15T09:47:32","modified_gmt":"2023-03-15T16:47:32","slug":"memory-profiling-support-for-allocations-made-from-a-titles-custom-allocator","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/pix\/memory-profiling-support-for-allocations-made-from-a-titles-custom-allocator\/","title":{"rendered":"Memory profiling support for allocations made from a title&#8217;s custom allocator"},"content":{"rendered":"<p>Starting with the <a href=\"https:\/\/devblogs.microsoft.com\/pix\/pix-2303-02\/\">2303.02 release of PIX on Windows<\/a>, <span style=\"font-size: 1rem; text-align: var(--bs-body-text-align);\"><a href=\"https:\/\/devblogs.microsoft.com\/pix\/timing-captures-new\/\">PIX timing captures<\/a> can track memory allocations and frees made by your custom memory allocators.<\/span><\/p>\n<p>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\u2019s 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.<\/p>\n<p>PIXRecordMemoryAllocationEvent and PIXRecordMemoryFreeEvent are available in version 1.0.230302001 or later of the <a href=\"https:\/\/devblogs.microsoft.com\/pix\/winpixeventruntime\/\">WinPIXEventRuntime<\/a>.<\/p>\n<p>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.<\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">#include &#8220;pix3.h&#8221;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">void* TitleAllocate(size_t size, UINT64 metadata)<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">{<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">\u00a0 \u00a0 void *pAddress = layer_allocate(size);<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">\u00a0 \u00a0 if (pAddress == NULL)<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">\u00a0 \u00a0 \u00a0 \u00a0 return NULL;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">\u00a0 \u00a0 PIXRecordMemoryAllocationEvent(TITLE_ALLOCATOR, pAddress, size, <\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0metadata);<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">\u00a0 \u00a0 return pAddress;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">void TitleFree(void* baseAddress, size_t size, UINT64 metadata)<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">{<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">\u00a0 \u00a0 layer_free(baseAddress, 0);<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">\u00a0 \u00a0 PIXRecordMemoryFreeEvent(TITLE_ALLOCATOR, baseAddress, size, <\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0metadata);<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace;\">}<\/span><\/p>\n<p>To see memory events corresponding to your calls to PIXRecordMemoryAllocationEvent and PIXRecordMemoryFreeEvent, select the <strong>Custom Allocator events<\/strong> check box before starting a timing capture:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2023\/03\/winpix_custom_allocators_options_pane.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-6062\" src=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2023\/03\/winpix_custom_allocators_options_pane.png\" alt=\"Image winpix custom allocators options pane\" width=\"571\" height=\"611\" srcset=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2023\/03\/winpix_custom_allocators_options_pane.png 571w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2023\/03\/winpix_custom_allocators_options_pane-280x300.png 280w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>PIX displays information about your custom allocations and frees alongside the data for other allocation types in the <strong>Range Details<\/strong> view of timing captures.\u00a0 Custom allocator events are grouped by allocator and shown under the <strong>Title Allocators by Id<\/strong> node.\u00a0 The allocator id is the first parameter to PIXRecordMemoryAllocationEvent.\u00a0 Note that the last parameter to PIXRecordMemoryAllocationEvent, the metadata parameter, is currently not displayed in PIX.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2023\/03\/winpix_custom_allocators_range_details.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-6063\" src=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2023\/03\/winpix_custom_allocators_range_details.png\" alt=\"Image winpix custom allocators range details\" width=\"1438\" height=\"372\" srcset=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2023\/03\/winpix_custom_allocators_range_details.png 1438w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2023\/03\/winpix_custom_allocators_range_details-300x78.png 300w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2023\/03\/winpix_custom_allocators_range_details-1024x265.png 1024w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2023\/03\/winpix_custom_allocators_range_details-768x199.png 768w\" sizes=\"(max-width: 1438px) 100vw, 1438px\" \/><\/a><\/p>\n<p>See <a href=\"https:\/\/devblogs.microsoft.com\/pix\/analyzing-memory-usage-and-performance-in-timing-captures\/\">Analyzing Memory usage and performance<\/a> for more details on the memory profiling features in Timing Captures.<\/p>\n<p>As always, please keep sending feedback and bug requests our way using the feedback button in the upper right corner of the PIX UI.<\/p>\n<p>Steven.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2019s custom [&hellip;]<\/p>\n","protected":false},"author":1915,"featured_media":6063,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6059","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pix"],"acf":[],"blog_post_summary":"<p>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\u2019s custom [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/posts\/6059","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/users\/1915"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/comments?post=6059"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/posts\/6059\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/media\/6063"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/media?parent=6059"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/categories?post=6059"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/tags?post=6059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}