{"id":1103,"date":"2013-10-22T00:02:00","date_gmt":"2013-10-22T00:02:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2013\/10\/22\/the-new-performance-optimization-tool-for-visual-c-applications\/"},"modified":"2021-09-28T15:34:35","modified_gmt":"2021-09-28T15:34:35","slug":"the-new-performance-optimization-tool-for-visual-c-applications","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/the-new-performance-optimization-tool-for-visual-c-applications\/","title":{"rendered":"The *New Performance Optimization Tool* for Visual C++ applications"},"content":{"rendered":"<p><span style=\"font-size: 14pt; text-decoration: underline; font-family: 'times new roman', times;\"><strong>Introduction <\/strong><\/span><\/p>\n<p style=\"text-align: left; margin-left: 18pt;\"><span style=\"font-family: 'times new roman', times;\">As a part of the VS2013 preview release the &#8216;<a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2013\/07\/12\/performance-and-diagnostics-hub-in-visual-studio-2013.aspx\">Performance and Diagnostics Hub<\/a>&#8216; was introduced. The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/e7k32f4k(v=vs.90).aspx\">Profile Guided Optimization<\/a> (PGO) <a href=\"http:\/\/visualstudiogallery.msdn.microsoft.com\/5a691c97-fe10-4a8a-aced-c33e0adeed4b\/file\/114220\/1\/pgoui.vsix\">tool\u00a0<\/a>is a new <strong>performance optimization tool\u00a0<\/strong> that integrates with &#8216;<a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2013\/07\/12\/performance-and-diagnostics-hub-in-visual-studio-2013.aspx\">Performance and Diagnostic Hub<\/a>&#8216;. The <a href=\"http:\/\/visualstudiogallery.msdn.microsoft.com\/5a691c97-fe10-4a8a-aced-c33e0adeed4b\/file\/114220\/1\/pgoui.vsix\">tool <\/a>is not a part of the out of the box install of Visual Studio 2013 but can be downloaded and installed from <a href=\"http:\/\/visualstudiogallery.msdn.microsoft.com\/5a691c97-fe10-4a8a-aced-c33e0adeed4b?SRC=Home\">VSGallery<\/a>\u00a0(<span style=\"font-size: medium;\"><strong>Download <a href=\"http:\/\/visualstudiogallery.msdn.microsoft.com\/5a691c97-fe10-4a8a-aced-c33e0adeed4b\">here<\/a><\/strong><\/span>)<span style=\"font-size: medium;\">.<\/span> This tool is for you if care about boosting your application&#8217;s runtime performance. <\/span><\/p>\n<p><span style=\"font-family: 'times new roman', times;\">This tool aims at improving the user experience of carrying out PGO in Visual Studio by providing a <strong>guided experience<\/strong> through the various phases of the PGO process. In addition to this, the <a href=\"http:\/\/visualstudiogallery.msdn.microsoft.com\/5a691c97-fe10-4a8a-aced-c33e0adeed4b\/file\/114220\/1\/pgoui.vsix\">PGO tool<\/a> will also provide functionality currently only exposed when using PGO from the command line. This includes being able to train disjoint training sets and making use of PGO utilities such as &#8216;<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/2kw46d8w.aspx\">pgomgr<\/a>&#8216; to view and <strong>analyze the quality of training <\/strong>performed for the training phase of PGO.<\/span><\/p>\n<p style=\"text-align: left; margin-left: 18pt;\"><span style=\"font-family: 'times new roman', times;\">The net goal of using this tool is to collect training data which represents performance centric scenarios. This training data is then used to optimize future builds of your application made possible as the plugin changes the resultant build configuration to always build with PGO.<\/span><\/p>\n<p style=\"text-align: left; margin-left: 18pt;\"><span style=\"font-family: 'times new roman', times;\">Please note, with this tool now you can <strong>also<\/strong> PGO&#8217;ize modern or immersive applications for the Windows Store. This tool is <strong>only <\/strong>available for <strong>native<\/strong> applications and is currently enabled for x86\/x64 platform. <em>As mentioned earlier, this tool is currently not a part of out-of-the-box install of Visual Studio. It is a prototype that we are really hoping if you can provide us feedback to help getting it to the next stage. Please let us know what you think about it?<\/em><\/span><\/p>\n<p><span style=\"font-size: 14pt; text-decoration: underline; font-family: 'times new roman', times;\"><strong>Walkthrough <\/strong><\/span><\/p>\n<p style=\"margin-left: 18pt;\"><span style=\"font-family: 'times new roman', times;\">The tool is available for use as a part of the &#8216;<strong>Performance and Diagnostics Hub<\/strong>&#8216; as long as a solution with a native startup project is selected in solution explorer. To start the tool, select &#8216;<strong>Profile Guided Optimization<\/strong>&#8216; and click &#8216;<strong>Start<\/strong>&#8216; as shown in figure 1 below:<\/span><\/p>\n<p style=\"margin-left: 18pt;\"><span style=\"font-family: 'times new roman', times;\">\n<a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/0724.102113_0701_TheallnewP1.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-28789\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/0724.102113_0701_TheallnewP1.png\" alt=\"Image 0724 102113 0701 TheallnewP1\" width=\"623\" height=\"306\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/0724.102113_0701_TheallnewP1.png 623w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/0724.102113_0701_TheallnewP1-300x147.png 300w\" sizes=\"(max-width: 623px) 100vw, 623px\" \/><\/a><\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"margin-left: 72pt; text-align: center;\"><span style=\"color: #44546a; font-size: 9pt; font-family: 'times new roman', times;\"><em>Figure 1: &#8216;Profile Guided Optimization&#8217; tool in &#8216;Performance and Diagnostic&#8217; hub. <\/em><\/span><\/p>\n<p style=\"margin-left: 18pt;\"><span style=\"font-family: 'times new roman', times;\">The &#8216;Start&#8217; screen for the plugin provides an overview for the process involved in PGO&#8217;izing your application. The &#8216;Analysis Target&#8217; always points to the &#8216;startup project&#8217; in your solution. The three simple steps are &#8216;Instrumentation&#8217;, &#8216;Training&#8217; and &#8216;Analyze&#8217;.<\/span><\/p>\n<p style=\"margin-left: 18pt;\"><span style=\"font-family: 'times new roman', times;\">Clicking &#8216;Start&#8217; begins the <strong>&#8216;Instrumentation&#8217; step<\/strong> for the tool as shown in figure 2. below.<\/span><\/p>\n<p style=\"margin-left: 18pt;\">\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/8371.102113_0701_TheallnewP2.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-28794\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/8371.102113_0701_TheallnewP2.png\" alt=\"Image 8371 102113 0701 TheallnewP2\" width=\"623\" height=\"310\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/8371.102113_0701_TheallnewP2.png 623w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/8371.102113_0701_TheallnewP2-300x149.png 300w\" sizes=\"(max-width: 623px) 100vw, 623px\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><span style=\"color: #44546a; font-size: 9pt; font-family: 'times new roman', times;\"><em> Figure 2: Instrumentation step for Profile Guided Optimization (PGO) <\/em><\/span><\/p>\n<p style=\"text-align: justify; margin-left: 18pt;\"><span style=\"font-family: 'times new roman', times;\"><strong>&#8216;Training is initially enabled&#8217;<\/strong> option provides the user with a choice to include the startup phase of the application as a part of the training exercise. In other words if this option is de-selected no training data will be collected for the startup or any other phase of the application until training is explicitly enabled.<\/span><\/p>\n<p style=\"text-align: justify; margin-left: 18pt;\"><span style=\"font-family: 'times new roman', times;\">Clicking &#8216;Instrument&#8217; will launch an instrumented build for the application (Figure 3). For the instrumented build the application is built with a special set of build flags. During this build the compiler inserts probe instructions into the generated code which are used to record training data for the training phase. Once the instrumented build of the application is complete, the application is launched automatically.<\/span><\/p>\n<p style=\"text-align: justify; margin-left: 18pt;\"><span style=\"font-family: 'times new roman', times;\">If you see any warnings pop up, please take time to address them and then click &#8216;Start&#8217; again to begin the instrumentation phase for the plugin.<\/span><\/p>\n<p style=\"text-align: justify; margin-left: 18pt;\">\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/5483.102113_0701_TheallnewP3.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-28790\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/5483.102113_0701_TheallnewP3.png\" alt=\"Image 5483 102113 0701 TheallnewP3\" width=\"561\" height=\"354\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/5483.102113_0701_TheallnewP3.png 561w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/5483.102113_0701_TheallnewP3-300x189.png 300w\" sizes=\"(max-width: 561px) 100vw, 561px\" \/><\/a><\/p>\n<p style=\"text-align: justify; margin-left: 144pt;\"><span style=\"color: #44546a; font-size: 9pt; font-family: 'times new roman', times;\"><em>Figure 3: Instrumented build started <\/em><\/span><\/p>\n<p><span style=\"font-size: 10pt; font-family: 'times new roman', times;\"> The &#8216;Start\/Pause&#8217; training links are used to control collection of training data (figure 4). The performance gains that you will get from PGO are directly proportional to how well you train your application. If you are unsure how to train your application or what constitutes a good set of training scenarios try using performance test suite as your training scenario set. Every &#8216;start\/pause training&#8217; sequence essentially marks the period where training data is recorded (figure 4). The training data recorded is dumped to a PGO data file (&lt;startup_project_name&gt;.pgd) which is finalized together during the analyze phase of the PGO lifecycle. Once the training phase is complete, click &#8216;Analyze&#8217; to start analyzing the training data collected. <\/span><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/0285.102113_0701_TheallnewP4.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-28788\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/0285.102113_0701_TheallnewP4.png\" alt=\"Image 0285 102113 0701 TheallnewP4\" width=\"605\" height=\"300\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/0285.102113_0701_TheallnewP4.png 605w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/0285.102113_0701_TheallnewP4-300x149.png 300w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/><\/a><\/p>\n<p style=\"margin-left: 72pt; text-align: center;\"><span style=\"color: #44546a; font-size: 9pt; font-family: 'times new roman', times;\"><em>Figure 4: Training phase for Profile Guided Optimization <\/em><\/span><\/p>\n<p><span style=\"font-family: 'times new roman', times;\">In the <strong>analyze<\/strong> phase of PGO, the training data collected is merged together and the table presents the amount of time spent (Dynamic Instruction Count (%)) in each function exclusively along with additional information such as function call count (Figure 5). This table provides data which is similar to what a profiler reports and should be used to validate that performance centric code sections are included as a part of the training step.<\/span><\/p>\n<p><span style=\"font-family: 'times new roman', times;\">The compiler uses this training data collected to optimize for application performance. With PGO, functions that are hot (i.e. frequently executed) during the training session are optimized for speed, the rest are optimized for size. As a result with PGO the resulting binary is smaller and faster. <\/span><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/8244.102113_0701_TheallnewP5.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-28793\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/8244.102113_0701_TheallnewP5.png\" alt=\"Image 8244 102113 0701 TheallnewP5\" width=\"624\" height=\"419\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/8244.102113_0701_TheallnewP5.png 624w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/8244.102113_0701_TheallnewP5-300x201.png 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/a><\/p>\n<p style=\"margin-left: 72pt; text-align: center;\"><span style=\"color: #44546a; font-size: 9pt; font-family: 'times new roman', times;\"><em>Figure 5: Analyze phase for Profile Guided Optimization <\/em><\/span><\/p>\n<p><span style=\"font-family: 'times new roman', times;\">Once the training data collected has been reviewed, click <strong>&#8216;Save changes&#8217;<\/strong> to enable future application builds to build with PGO. If however based upon your review, key performance centric functions seem to be missing from the table or are associated with very low dynamic instruction count (%), click <strong>&#8216;Redo Training&#8217;<\/strong> to redo the training phase of the application. Please note, clicking the <strong>&#8216;Redo Training&#8217;<\/strong> button resets the training data collected.<\/span><\/p>\n<p><span style=\"font-family: 'times new roman', times;\">As a result of clicking <strong>&#8216;Save changes&#8217;<\/strong> the tool dumps the training data collected into a PGO data file (&lt;startup_project_name&gt;.pgd. The PGO data file is written in a new folder called &#8216;PGO Training Data&#8217; created under the &#8216;startup project&#8217; head as depicted in figure 6 below. This data file is used by the compiler to enable a PGO compile.<\/span><\/p>\n<p style=\"margin-left: 36pt;\">\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/8737.102113_0701_TheallnewP6.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-28795\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/8737.102113_0701_TheallnewP6.png\" alt=\"Image 8737 102113 0701 TheallnewP6\" width=\"423\" height=\"352\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/8737.102113_0701_TheallnewP6.png 423w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/8737.102113_0701_TheallnewP6-300x250.png 300w\" sizes=\"(max-width: 423px) 100vw, 423px\" \/><\/a><\/p>\n<p style=\"margin-left: 36pt; text-align: center;\"><span style=\"color: #44546a; font-size: 9pt; font-family: 'times new roman', times;\"><em> Figure 6: Profile Guided Optimization Data file (&lt;startup-project-name&gt;.pgd) <\/em><\/span><\/p>\n<p><span style=\"font-family: 'times new roman', times;\">At this point &#8216;Profile Guided Optimization&#8217; is enabled for the chosen build configuration and can be initiated by an application rebuild. On application rebuild take notice of the extra PGO related diagnostic information in the Build Output window (Figure 7).<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/7563.102113_0701_TheallnewP7.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-28791\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/7563.102113_0701_TheallnewP7.png\" alt=\"Image 7563 102113 0701 TheallnewP7\" width=\"623\" height=\"143\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/7563.102113_0701_TheallnewP7.png 623w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/10\/7563.102113_0701_TheallnewP7-300x69.png 300w\" sizes=\"(max-width: 623px) 100vw, 623px\" \/><\/a><\/p>\n<p style=\"margin-left: 72pt; text-align: center;\"><span style=\"color: #44546a; font-size: 9pt; font-family: 'times new roman', times;\"><em>Figure 7: Profile Guided Optimization diagnostics in Build Output <\/em><\/span><\/p>\n<p><span style=\"font-family: 'times new roman', times;\">As you make significant code changes to your application code base it will become necessary to retrain your application to regenerate a new PGO training data file. It is recommended to retrain your application when the <span style=\"color: red;\">highlighted <\/span>PGO diagnostic information falls below &#8216;80%&#8217;.<\/span><\/p>\n<p><span style=\"font-family: 'times new roman', times;\">To view the performance benefits with PGO, re-execute your training scenarios with the PGO-optimized build of the application to notice the performance gains.\n<\/span><\/p>\n<p><span style=\"font-size: 14pt; text-decoration: underline; font-family: 'times new roman', times;\"><strong>Wrap Up <\/strong><\/span><\/p>\n<p><span style=\"font-family: 'times new roman', times;\">We are really looking to learn from your feedback w.r.t this tool so please leave us a note on what you think of it once you get a chance to play around with it. Ideally we would like to make this part of the product in a future release of Visual Studio.<\/span><\/p>\n<p><span style=\"font-family: 'times new roman', times;\">For more information about what PGO is all about please refer to one of my earlier <a href=\"http:\/\/blogs.msdn.com\/b\/vcblog\/archive\/2013\/04\/04\/how-to-build-faster-and-high-performing-native-applications-using-pgo.aspx\">blogs<\/a>. For more information about this tool please visit this link on <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dn457343(v=vs.120).aspx\">MSDN<\/a>. Additionally, if you would like us to blog about some other compiler technology or tool please let us know we are always interested in learning from your feedback.\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction As a part of the VS2013 preview release the &#8216;Performance and Diagnostics Hub&#8216; was introduced. The Profile Guided Optimization (PGO) tool\u00a0is a new performance optimization tool\u00a0 that integrates with &#8216;Performance and Diagnostic Hub&#8216;. The tool is not a part of the out of the box install of Visual Studio 2013 but can be downloaded [&hellip;]<\/p>\n","protected":false},"author":265,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1103","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>Introduction As a part of the VS2013 preview release the &#8216;Performance and Diagnostics Hub&#8216; was introduced. The Profile Guided Optimization (PGO) tool\u00a0is a new performance optimization tool\u00a0 that integrates with &#8216;Performance and Diagnostic Hub&#8216;. The tool is not a part of the out of the box install of Visual Studio 2013 but can be downloaded [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/1103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/265"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=1103"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/1103\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=1103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=1103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=1103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}