{"id":92111,"date":"2015-11-13T07:00:00","date_gmt":"2015-11-13T22:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20151113-00\/?p=92111\/"},"modified":"2019-03-13T12:21:46","modified_gmt":"2019-03-13T19:21:46","slug":"20151113-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20151113-00\/?p=92111\/","title":{"rendered":"Diagnosing high CPU by studying profiling results, example"},"content":{"rendered":"<p>A customer asked for assistance determining why their program demonstrated sporadic high CPU. It occurred only at a client location, so they couldn&#8217;t set up a full debugging environment. They were able to convince the client to trace one of the spikes <a HREF=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/hardware\/hh448170.aspx\">in a profiler<\/a>. During this capture, high CPU was recorded for around 20% of the running time. Here is the drill-down of where most of that time was going. <\/p>\n<table BORDER=\"1\" STYLE=\"border-collapse: collapse\" CELLPADDING=\"2\">\n<tr>\n<td>Stack<\/td>\n<td ALIGN=\"right\">% Weight<\/td>\n<\/tr>\n<tr>\n<td>[Root]<\/td>\n<td ALIGN=\"right\">19.36<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;|- ntdll.dll!RtlUserThreadStart<\/td>\n<td ALIGN=\"right\">19.36<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;kernel32.dll!BaseThreadInitThunk<\/td>\n<td ALIGN=\"right\">19.36<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;contoso.exe!__wmainCRTStartup<\/td>\n<td ALIGN=\"right\">19.36<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;contoso.exe!wWinMain<\/td>\n<td ALIGN=\"right\">19.36<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &#x22ee;<\/td>\n<td ALIGN=\"right\">&#x22ee;<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;fabrikam.dll!Widget::~Widget<\/td>\n<td ALIGN=\"right\">19.36<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;fabrikam.dll!WidgetProxy::Disconnect<\/td>\n<td ALIGN=\"right\">19.36<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;fabrikam.dll!WidgetProxy::DisconnectAll<\/td>\n<td ALIGN=\"right\">19.36<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;fabrikam.dll!WidgetProxy::TransactCommand<\/td>\n<td ALIGN=\"right\">19.36<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;fabrikam.dll!WidgetProxy::WaitForResponse<\/td>\n<td ALIGN=\"right\">19.36<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;|- user32.dll!MsgWaitForMultipleObjectsEx<\/td>\n<td ALIGN=\"right\">18.63<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- kernel32.dll!WaitForMultipleObjectsExImplementation<\/td>\n<td ALIGN=\"right\">17.37<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- KernelBase.dll!WaitForMultipleObjectsEx<\/td>\n<td ALIGN=\"right\">16.55<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntdll.dll!ZwWaitForMultipleObjects<\/td>\n<td ALIGN=\"right\">8.69<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiSystemServiceCopyEnd<\/td>\n<td ALIGN=\"right\">4.76<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!NtWaitForMultipleObjects<\/td>\n<td ALIGN=\"right\">4.71<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!ObpWaitForMultipleObjects<\/td>\n<td ALIGN=\"right\">4.02<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!ObpWaitForMultipleObjects<\/td>\n<td ALIGN=\"right\">4.02<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiInterruptDispatchNoLock<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiCheckForKernelApcDelivery<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiDpcInterrupt<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiInterruptDispatch<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!NtWaitForMultipleObjects<\/td>\n<td ALIGN=\"right\">0.49<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!memcpy<\/td>\n<td ALIGN=\"right\">0.20<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiInterruptDispatchNoLock<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiDpcInterrupt<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiSystemServiceCopyEnd<\/td>\n<td ALIGN=\"right\">0.05<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiSystemCall64<\/td>\n<td ALIGN=\"right\">1.84<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntdll.dll!ZwWaitForMultipleObjects<\/td>\n<td ALIGN=\"right\">1.20<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiSystemServiceExit<\/td>\n<td ALIGN=\"right\">0.56<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiSystemServiceRepeat<\/td>\n<td ALIGN=\"right\">0.16<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiSystemServiceGdiTebAccess<\/td>\n<td ALIGN=\"right\">0.13<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiSystemServiceStart<\/td>\n<td ALIGN=\"right\">0.03<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiSystemServiceCopyStart<\/td>\n<td ALIGN=\"right\">0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiInterruptDispatchNoLock<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- KernelBase.dll!BaseSetLastNTError<\/td>\n<td ALIGN=\"right\">6.57<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntdll.dll!RtlNtStatusToDosError<\/td>\n<td ALIGN=\"right\">6.33<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntdll.dll!RtlNtStatusToDosErrorNoTeb<\/td>\n<td ALIGN=\"right\">6.05<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntdll.dll!RtlNtStatusToDosErrorNoTeb<\/td>\n<td ALIGN=\"right\">6.04<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiDpcInterrupt<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiApcInterrupt<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiInterruptDispatchNoLock<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntdll.dll!RtlNtStatusToDosError<\/td>\n<td ALIGN=\"right\">0.29<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiInterruptDispatchNoLock<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- KernelBase.dll!BaseSetLastNTError<\/td>\n<td ALIGN=\"right\">0.19<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntdll.dll!RtlSetLastWin32Error<\/td>\n<td ALIGN=\"right\">0.05<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntdll.dll!memcpy<\/td>\n<td ALIGN=\"right\">0.15<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- KernelBase.dll!memcpy<\/td>\n<td ALIGN=\"right\">0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiApcInterrupt<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiDpcInterrupt<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- kernel32.dll!WaitForMultipleObjectsExImplementation<\/td>\n<td ALIGN=\"right\">0.60<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntdll.dll!memcpy<\/td>\n<td ALIGN=\"right\">0.16<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- kernel32.dll!WaitForMultipleObjectsEx<\/td>\n<td ALIGN=\"right\">0.04<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- kernel32.dll!memcpy<\/td>\n<td ALIGN=\"right\">0.02<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiInterruptDispatchNoLock<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiApcInterrupt<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiDpcInterrupt<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiApcInterrupt<\/td>\n<td ALIGN=\"right\">&lt;0.01<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;|- KernelBase.dll!GetTickCount<\/td>\n<td ALIGN=\"right\">0.24<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;|- KernelBase.dll!GetLastError<\/td>\n<td ALIGN=\"right\">0.20<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;|- fabrikam.dll!GetLastError<\/td>\n<td ALIGN=\"right\">0.09<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;|- kernel32.dll!GetLastError<\/td>\n<td ALIGN=\"right\">0.02<\/td>\n<\/tr>\n<\/table>\n<p>From this chart, you can see that all of the time is consumed in <code>Widget&shy;Proxy::Wait&shy;For&shy;Response<\/code>, and most of that time is in <code>Msg&shy;Wait&shy;For&shy;Multiple&shy;Objects&shy;Ex<\/code>. There is a lot of detail inside that function, so let&#8217;s hide everything that contributes less than one percent. <\/p>\n<table BORDER=\"1\" STYLE=\"border-collapse: collapse\" CELLPADDING=\"2\">\n<tr>\n<td>Stack<\/td>\n<td ALIGN=\"right\">% Weight<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;fabrikam.dll!WidgetProxy::WaitForResponse<\/td>\n<td ALIGN=\"right\">19.36<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;|- user32.dll!MsgWaitForMultipleObjectsEx<\/td>\n<td ALIGN=\"right\">18.63<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- kernel32.dll!WaitForMultipleObjectsExImplementation<\/td>\n<td ALIGN=\"right\">17.37<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- KernelBase.dll!WaitForMultipleObjectsEx<\/td>\n<td ALIGN=\"right\">16.55<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntdll.dll!ZwWaitForMultipleObjects<\/td>\n<td ALIGN=\"right\">8.69<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiSystemServiceCopyEnd<\/td>\n<td ALIGN=\"right\">4.76<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!NtWaitForMultipleObjects<\/td>\n<td ALIGN=\"right\">4.71<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- ntoskrnl.exe!KiSystemCall64<\/td>\n<td ALIGN=\"right\">1.84<\/td>\n<\/tr>\n<tr>\n<td>&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;|- KernelBase.dll!BaseSetLastNTError<\/td>\n<td ALIGN=\"right\">6.57<\/td>\n<\/tr>\n<\/table>\n<p>If we look only at the time spent in <code>Wait&shy;For&shy;Multiple&shy;Objects&shy;Ex<\/code>, 8.69%\/16.55% = around half of the time is spent in <code>Zw&shy;Wait&shy;For&shy;Multiple&shy;Objects<\/code> (the kernel part of the function which does the waiting), and 6.57%\/16.55% = around 40% of the time is the time setting the last error code. <\/p>\n<p>That&#8217;s odd. Why is this function spending nearly half of its time setting the last error code? <\/p>\n<p>My theory: Because the call is failing with an error! <\/p>\n<p>That explains the high CPU. The call to <code>Wait&shy;For&shy;Multiple&shy;Objects&shy;Ex<\/code> is failing, which means that instead of waiting, it returns immediately with an error code. The <code>Widget&shy;Proxy::Wait&shy;For&shy;Response<\/code> function doesn&#8217;t quite know what to do in that case, so it shrugs its shoulders and tries waiting again. Eventually, whatever it&#8217;s waiting for actually happens, and the call returns, but instead of waiting at low CPU, it accidentally created a CPU spin loop. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why would a wait consume so much CPU time?<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-92111","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Why would a wait consume so much CPU time?<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/92111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=92111"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/92111\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=92111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=92111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=92111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}