{"id":5267,"date":"2021-02-03T14:23:10","date_gmt":"2021-02-03T22:23:10","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/pix\/?p=5267"},"modified":"2021-02-03T16:17:25","modified_gmt":"2021-02-04T00:17:25","slug":"filtering-cpu-samples-by-one-or-more-pix-events","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/pix\/filtering-cpu-samples-by-one-or-more-pix-events\/","title":{"rendered":"Filtering CPU Samples by one or more PIX Events"},"content":{"rendered":"<p>The <a href=\"https:\/\/devblogs.microsoft.com\/pix\/analyzing-cpu-samples-in-timing-captures\/\">Sampling Profiler<\/a> included in the <a href=\"https:\/\/devblogs.microsoft.com\/pix\/pix-2101-27\/\">2101.27 release of PIX on Windows<\/a> includes a novel new feature that allows you to filter the analysis of CPU samples down to just those samples that were collected during the time when one or more PIX events was running.\u00a0 This capability is particularly useful for seeing which functions ran the most frequently, or took the most time, in places where your title is only sparsely instrumented with PIX events.<\/p>\n<p>For example, the following picture shows several CPU frames in the <strong>Timeline<\/strong> view of a <a href=\"https:\/\/devblogs.microsoft.com\/pix\/timing-captures-new\/\">Timing Capture<\/a>.\u00a0 The top-most frame event is called <em>MainLoop<\/em>.\u00a0 It&#8217;s clear that the frame encircled in red took substantially longer the execute than the frames around it.\u00a0 To begin to understand why, I&#8217;ve selected a range of time roughly equivalent to my long frame and have populated the <strong>Range Details<\/strong> view with an aggregated tree of the CPU samples that were collected during that time range.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_long_frame-1.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-5271\" src=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_long_frame-1.png\" alt=\"Image pix events long frame\" width=\"1348\" height=\"622\" srcset=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_long_frame-1.png 1348w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_long_frame-1-300x138.png 300w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_long_frame-1-1024x472.png 1024w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_long_frame-1-768x354.png 768w\" sizes=\"(max-width: 1348px) 100vw, 1348px\" \/><\/a><\/p>\n<p>The characteristic of my long frame that stands out is the exceptionally long duration of the <em>UpdateEnemyPositions<\/em> event.\u00a0 The &#8220;normal&#8221; frames either don&#8217;t have an instance of this event at all, or the event&#8217;s duration is so small that it doesn&#8217;t appear at my current zoom level.\u00a0 Unfortunately, there is no further PIX event instrumentation underneath <em>UpdateEnemyPositions<\/em> to help diagnose what&#8217;s going on.<\/p>\n<p>This is where the ability to filter the Sampled Functions tree using a particular PIX event comes in handy.\u00a0 Start by selecting the down arrow next to <strong>PIX events: All<\/strong> in the <strong>Display Options<\/strong> panel.\u00a0 Depending on how heavily your title is instrumented, the filter control may initially indicate that there are too many events to display.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_too_many_events.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-5273\" src=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_too_many_events.png\" alt=\"Image pix events too many events\" width=\"291\" height=\"281\" \/><\/a><\/p>\n<p>Use the filter bar to find the <em>UpdateEnemyPositions<\/em> event and select <strong>Apply<\/strong>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_filtered.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-5274\" src=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_filtered.png\" alt=\"Image pix events filtered\" width=\"338\" height=\"350\" srcset=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_filtered.png 338w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_filtered-290x300.png 290w\" sizes=\"(max-width: 338px) 100vw, 338px\" \/><\/a><\/p>\n<p>The tree of aggregated samples is rebuilt to include only those samples that were collected during the period of time while <em>UpdateEnemyPositions<\/em> was running.\u00a0 Drilling into the tree shows that memory allocation is the culprit here.\u00a0 As can be seen in the following picture, the vast majority of the time spent in <em>UpdateEnemyPositions<\/em> is a callpath that goes through operator <em>new<\/em>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_filtered_stack_tree.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-5277\" src=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_filtered_stack_tree.png\" alt=\"Image pix events filtered stack tree\" width=\"1349\" height=\"775\" srcset=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_filtered_stack_tree.png 1349w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_filtered_stack_tree-300x172.png 300w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_filtered_stack_tree-1024x588.png 1024w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2021\/02\/pix_events_filtered_stack_tree-768x441.png 768w\" sizes=\"(max-width: 1349px) 100vw, 1349px\" \/><\/a><\/p>\n<p>While viewing the sampled functions tree filtered by one or more PIX events, keep in mind that the set of samples displayed are all samples collected during the time specified PIX event(s) was running <strong><em>across all threads and cores<\/em><\/strong>.\u00a0 If the PIX event(s) you selected as your filter criteria runs on several threads or cores, consider organizing the tree by using the <strong>Group By<\/strong> dropdown in the <strong>Display Options<\/strong> panel if needed.<\/p>\n<p>Steven.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Sampling Profiler included in the 2101.27 release of PIX on Windows includes a novel new feature that allows you to filter the analysis of CPU samples down to just those samples that were collected during the time when one or more PIX events was running.\u00a0 This capability is particularly useful for seeing which functions [&hellip;]<\/p>\n","protected":false},"author":1915,"featured_media":4769,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5267","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pix"],"acf":[],"blog_post_summary":"<p>The Sampling Profiler included in the 2101.27 release of PIX on Windows includes a novel new feature that allows you to filter the analysis of CPU samples down to just those samples that were collected during the time when one or more PIX events was running.\u00a0 This capability is particularly useful for seeing which functions [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/posts\/5267","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=5267"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/posts\/5267\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/media\/4769"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/media?parent=5267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/categories?post=5267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/tags?post=5267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}