{"id":298,"date":"2011-01-04T14:23:32","date_gmt":"2011-01-04T13:23:32","guid":{"rendered":"http:\/\/floris.briolas.nl\/floris\/?p=298"},"modified":"2011-01-05T08:16:08","modified_gmt":"2011-01-05T07:16:08","slug":"profiling-a-windows-service","status":"publish","type":"post","link":"https:\/\/floris.briolas.nl\/floris\/2011\/01\/profiling-a-windows-service\/","title":{"rendered":"Profiling a Windows Service"},"content":{"rendered":"<p>You need to do a little bit extra to profile a service, if you get &#8220;<strong>VSPerfCLREnv was not set up correctly<\/strong>&#8221; solution is here.<\/p>\n<p>This &#8220;howto&#8221; has been written for a really simple service, wich you can <a href=\"http:\/\/floris.briolas.nl\/floris\/downloads\/WindowsServicePrflTst.zip\">download<\/a>. It&#8217;s tiny so you can isolate the &#8220;how do i&#8221; from the &#8220;for my service&#8221;.<\/p>\n<p>To quickly start do this:<\/p>\n<p>run &#8220;<strong>VSPerfCLREnv.cmd \/globalsampleon<\/strong>&#8221; this cmd is located in &#8220;Team Tools\\Performance Tools&#8221;(Vs2008\/vs2010) install folder, for me that is : &#8220;C:\\Program Files\\Microsoft Visual Studio 9.0\\Team Tools\\Performance Tools\\&#8221; . This will be &#8220;C:\\Program Files\\Microsoft Visual Studio 10.0\\Team Tools\\Performance Tools\\&#8221; for vs2010.<\/p>\n<p>If your Service starts at startup, reboot, else stop and start your service. I booted just to be sure.<\/p>\n<p>Open your &#8220;windows service&#8221; project in Visual Studio.<\/p>\n<p>When you are using my sample do this:<\/p>\n<p>Compile solution (this\u00a0installs\u00a0the service and starts the service, see: &#8220;build event&#8221;)<\/p>\n<p>Start Wizzard : Analyze &gt; Launch Performance Wizzard , select &#8220;sampling&#8221; and finish.<\/p>\n<p><a href=\"http:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/wiz1.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-300\" title=\"wiz1\" src=\"http:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/wiz1-300x256.jpg\" alt=\"\" width=\"300\" height=\"256\" srcset=\"https:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/wiz1-300x256.jpg 300w, https:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/wiz1.jpg 647w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><a href=\"http:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/wiz2.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-301\" title=\"wiz2\" src=\"http:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/wiz2-300x256.jpg\" alt=\"\" width=\"300\" height=\"256\" srcset=\"https:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/wiz2-300x256.jpg 300w, https:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/wiz2.jpg 647w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><a href=\"http:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/wiz3.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-302\" title=\"wiz3\" src=\"http:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/wiz3-300x256.jpg\" alt=\"\" width=\"300\" height=\"256\" srcset=\"https:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/wiz3-300x256.jpg 300w, https:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/wiz3.jpg 647w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now you can&#8217;t &#8220;Launch with Profiling&#8221; (you can&#8217;t start a service directly), you need to &#8220;<strong>Attach<\/strong>&#8221; to it, find your\u00a0service\u00a0process. <span style=\"text-decoration: underline;\">Check<\/span> the &#8220;<strong>Show processes from all users<\/strong>&#8221; and &#8220;<strong>Show processes in all sessions<\/strong>&#8220;.<\/p>\n<p><a href=\"http:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/attach1.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-303\" title=\"attach1\" src=\"http:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/attach1-300x214.jpg\" alt=\"\" width=\"300\" height=\"214\" srcset=\"https:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/attach1-300x214.jpg 300w, https:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/attach1.jpg 408w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><a href=\"http:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/attach2.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-304\" title=\"attach2\" src=\"http:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/attach2-300x161.jpg\" alt=\"\" width=\"300\" height=\"161\" srcset=\"https:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/attach2-300x161.jpg 300w, https:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/attach2.jpg 690w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Run it as long as you wish until you are done. Press stop and you&#8217;ll\u00a0receive\u00a0report which you can drill down into.<\/p>\n<p><a href=\"http:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/report.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-thumbnail wp-image-306\" title=\"report\" src=\"http:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/report-150x150.jpg\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><\/p>\n<p>Now in real live applications your service might not be a hog for cpu cycles. So you might get an error that &#8220;<strong>No Data was Collected<\/strong>&#8220;.<\/p>\n<p><a href=\"http:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/prob11.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-307\" title=\"prob1\" src=\"http:\/\/floris.briolas.nl\/floris\/wp-content\/uploads\/2011\/01\/prob11.jpg\" alt=\"\" width=\"291\" height=\"169\" \/><\/a><\/p>\n<p>This could happen:<\/p>\n<ul>\n<li>You did not attach to correct process!<\/li>\n<li>Your app does so little, when the profiler does some sampeling your service is idle and therfore invisible to the profiler<\/li>\n<\/ul>\n<p><strong>Finally:<\/strong><\/p>\n<p>When you are done with profiling call &#8220;<strong>VSPerfCLREnv.cmd&#8221; \/globaloff<\/strong>&#8221; this will disable profiling and give you back those cpu cycles otherwise used for profiling.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You need to do a little bit extra to profile a service, if you get &#8220;VSPerfCLREnv was not set up correctly&#8221; solution is here. This &#8220;howto&#8221; has been written for a really simple service, wich you can download. It&#8217;s tiny so you can isolate the &#8220;how do i&#8221; from the &#8220;for my service&#8221;. To quickly [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[3],"tags":[7,13],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p61yPs-4O","_links":{"self":[{"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/posts\/298"}],"collection":[{"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/comments?post=298"}],"version-history":[{"count":6,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/posts\/298\/revisions"}],"predecessor-version":[{"id":311,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/posts\/298\/revisions\/311"}],"wp:attachment":[{"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/media?parent=298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/categories?post=298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/floris.briolas.nl\/floris\/wp-json\/wp\/v2\/tags?post=298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}