{"id":3437,"date":"2011-10-15T14:53:00","date_gmt":"2011-10-15T14:53:00","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/event-driven-debugging\/"},"modified":"2016-07-28T10:50:37","modified_gmt":"2016-07-28T10:50:37","slug":"event-driven-debugging","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/event-driven-debugging\/","title":{"rendered":"Event-Driven Debugging"},"content":{"rendered":"<p>Most application troubleshooting involves getting an error, analyzing the error message, and at worst, attaching a debugger to work out the real cause. What is not really covered is how to troubleshoot an applicaiton that is not errant, but is having a performance issue, and more than likely, in the middle of the night when you are snug in your bed, sawing logs. What you need is an ever-vigilant cyborg who never sleeps to sit in front of your server all night, but as SkyNet is not live yet, you can settle for the next-best thing. <\/p>\n<p> Windows provides performance counters and alerts that can tell you when an applicaiton reaches an unacceptable threshold of naughty behavior, but although it can tattle on your brainchild, it won&#8217;t be the child psychiatrist that you need to tell you why he&#8217;s pulling your server&#8217;s pigtails and pulling faces at the teacher. What you need is to plug a debugger into performance monitor and have it tell you what&#8217;s going on with your applicaiton at the time.<\/p>\n<p>  For this purpose, I&#8217;d used Microsoft&#8217;s MDbgEngine as the basis for an applicaiton that will dump a program&#8217;s stacks, I call it Application Slicer Dicer Wonder Dumper Super Cyborg, or <a href=\"ftp:\/\/support.red-gate.com\/utilities\/stackomatic.zip\">StackOMatic<\/a> for short. StackOMatic can look at a program&#8217;s behavior and tell you if the stacks are not moving, but it can also work on the command-line to dump all managed methods on the stack at will. <\/p>\n<p> Now that there is a command you can use to dump the stacks, all you need to do is politely tell Windows to run it when you&#8217;re displeased with your creation as it&#8217;s trashing the CPU of your server at 3 AM. <\/p>\n<p> The first step is to create a scheduled task to tell StackOMatic to dump your applicaiton. Start Task Scheduler and right-click Task Scheduler Library and then Create Task. For this exercise I&#8217;m creating a task that will dump the Red Gate SQL Monitor Base Monitor Service. In the Actions tab, I enter the path to StackOMatic and use the arguments to log the stack dump to a file: <\/p>\n<p> \/PN:RedGate.Response.Engine.Alerting.Base.Service \/OUT:c:usersadministratorMonitorLog.txt <\/p>\n<p> Next, I go into Windows Server 2008&#8217;s Reliability and Performance Monitor and add a new Data Collector Set. This set will produce an alert on the %Processor Time for the service. When the processor time breaches 50%, it will run the StackDumpBaseService task I created. <\/p>\n<p> Whenever the service misbehaves, it will append to the log file. Now when I go to work in the morning, I can see what the service was doing when it overloaded the processor and take action. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most application troubleshooting involves getting an error, analyzing the error message, and at worst, attaching a debugger to work out the real cause. What is not really covered is how to troubleshoot an applicaiton that is not errant, but is having a performance issue, and more than likely, in the middle of the night when&#8230;&hellip;<\/p>\n","protected":false},"author":27149,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"coauthors":[],"class_list":["post-3437","post","type-post","status-publish","format-standard","hentry","category-blogs"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3437","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/27149"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=3437"}],"version-history":[{"count":1,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3437\/revisions"}],"predecessor-version":[{"id":25400,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3437\/revisions\/25400"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=3437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=3437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=3437"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=3437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}