{"id":4447,"date":"2019-05-07T15:49:39","date_gmt":"2019-05-07T22:49:39","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/pix\/?p=4447"},"modified":"2019-05-09T09:43:43","modified_gmt":"2019-05-09T16:43:43","slug":"pix-cpu-tools-graphing-pixreportcounter-values-in-the-metrics-view","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/pix\/pix-cpu-tools-graphing-pixreportcounter-values-in-the-metrics-view\/","title":{"rendered":"PIX CPU Tools: Graphing PIXReportCounter values in the Metrics View"},"content":{"rendered":"<p>The Metrics view in <a href=\"https:\/\/devblogs.microsoft.com\/pix\/timing-captures-new\/\">New Timing Captures<\/a> allows you to graph the duration of PIX CPU events and any counter values that are reported using the <a href=\"https:\/\/devblogs.microsoft.com\/pix\/winpixeventruntime\/\">PIXReportCounter<\/a> API.\u00a0 Graphing event durations is fairly discoverable in the UI, but I think it&#8217;s less well-known that counter values can be graphed as well.<\/p>\n<p>Annotating your title with calls to <a href=\"https:\/\/devblogs.microsoft.com\/pix\/winpixeventruntime\/\">PIXReportCounter<\/a> and graphing the resulting custom data in the Metrics view can be very helpful when investigating performance outliers.\u00a0 For example, in the following picture, when looking at the frame that is highlighted,\u00a0it&#8217;s fairly obvious that the duration of the <strong>UpdateEnemyPositions<\/strong> PIX event is responsible for the unusually long frame time.\u00a0 In the neighboring frames, the <strong>UpdateEnemyPositions<\/strong> PIX event is of small enough duration that it doesn&#8217;t even appear at this zoom level, while in the longer frame, the duration of <strong>UpdateEnemyPositions<\/strong> really stands out.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-4451\" src=\"http:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2019\/05\/UpdateEnemyPositions_frame.png\" alt=\"\" width=\"620\" height=\"303\" srcset=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2019\/05\/UpdateEnemyPositions_frame.png 620w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2019\/05\/UpdateEnemyPositions_frame-300x147.png 300w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/p>\n<p>Even though we can see that the duration of <strong>UpdateEnemyPositions<\/strong> in this frame is an outlier when compared to other frames, we still don&#8217;t know why.\u00a0 There are a few alternatives for gathering more detailed information. First, if you collected CPU samples when the capture was taken, you might be able to glean some useful information by looking at the sample callstacks in the Element Details view.\u00a0 Another approach would be to go back to your title and add additional calls to <a href=\"https:\/\/devblogs.microsoft.com\/pix\/winpixeventruntime\/\">PIXBeginEvent<\/a> in functions called by <strong>UpdateEnemyPositions <\/strong>(if there are any).<\/p>\n<p>Sometimes, however, more than just a call stack or an event duration is needed to diagnose an issue.\u00a0 In this case, if the title reported custom data using <a href=\"https:\/\/devblogs.microsoft.com\/pix\/winpixeventruntime\/\">PIXReportCounter<\/a>, I can graph that data, along with the duration of <strong>UpdateEnemyPositions<\/strong> to see if that helps me establish some correlations that will help determine what&#8217;s going on.<\/p>\n<p>For example, say that my title is reporting custom data related to updating enemy positions such as &#8220;the number of enemies&#8221;.\u00a0 <a href=\"https:\/\/devblogs.microsoft.com\/pix\/winpixeventruntime\/\">PIXReportCounter<\/a> let&#8217;s you specify custom data such at this by specifying string\/value pairs:<\/p>\n<p><span style=\"font-family: courier new,courier,monospace;\">PIXReportCounter(L&#8221;NumEnemies&#8221;, m_numEnemies);<\/span><\/p>\n<p>Now, I can use the Metrics view to graph the custom counter data.\u00a0 All counters added with <a href=\"https:\/\/devblogs.microsoft.com\/pix\/winpixeventruntime\/\">PIXReportCounter<\/a> show up under a <strong>Custom counters<\/strong> node in the Metrics view Selector panel.\u00a0 By graphing my custom data along with the duration of related events, I can start to determine whether a correlation exists between the value of my custom counter and the duration of an event.\u00a0 In our example, we can see if spikes in the duration of <strong>UpdateEnemyPositions<\/strong> always correlate to relatively large values in the <strong>NumEnemies<\/strong> counter.\u00a0 If so, that probably provides a clue on the algorithm in your title to optimize.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-4454\" src=\"http:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2019\/05\/pix_report_counter_metrics_view.png\" alt=\"\" width=\"1212\" height=\"779\" srcset=\"https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2019\/05\/pix_report_counter_metrics_view.png 1212w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2019\/05\/pix_report_counter_metrics_view-300x193.png 300w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2019\/05\/pix_report_counter_metrics_view-768x494.png 768w, https:\/\/devblogs.microsoft.com\/pix\/wp-content\/uploads\/sites\/41\/2019\/05\/pix_report_counter_metrics_view-1024x658.png 1024w\" sizes=\"(max-width: 1212px) 100vw, 1212px\" \/><\/p>\n<p>Steven Pratschner<\/p>\n<p>PIX Team<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Metrics view in New Timing Captures allows you to graph the duration of PIX CPU events and any counter values that are reported using the PIXReportCounter API.\u00a0 Graphing event durations is fairly discoverable in the UI, but I think it&#8217;s less well-known that counter values can be graphed as well. Annotating your title with [&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-4447","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pix"],"acf":[],"blog_post_summary":"<p>The Metrics view in New Timing Captures allows you to graph the duration of PIX CPU events and any counter values that are reported using the PIXReportCounter API.\u00a0 Graphing event durations is fairly discoverable in the UI, but I think it&#8217;s less well-known that counter values can be graphed as well. Annotating your title with [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/posts\/4447","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=4447"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/posts\/4447\/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=4447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/categories?post=4447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/pix\/wp-json\/wp\/v2\/tags?post=4447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}