我在w3wp.exe中拥有100%的CPU利用率,CPU的前3个线程如下所示
当我切换到其中一个有问题的线程时(例如18)我在尝试走动callstack时会得到以下错误,所以我认为它只是非托管代码而且“k”和“dumpstack”也在下面
所以我的问题是如何找出在这些Theadpool工作线程上占用所有CPU的内容?
0:018> !runaway
User Mode Time
Thread Time
15:12a4 0 days 0:13:15.359
18:830 0 days 0:10:49.046
17:1084 0 days 0:10:47.343
12:fc 0 days 0:00:36.828
...
0:018> !threadpool
CPU utilization 100%
Worker Thread: Total: 3 Running: 0 Idle: 3 MaxLimit: 100 MinLimit: 1
Work Request in Queue: 6
--------------------------------------
Number of Timers: 8
--------------------------------------
Completion Port Thread:Total: 1 Free: 1 MaxFree: 2 CurrentLimit: 0 MaxLimit: 100 MinLimit: 1
0:018> !threads
ThreadCount: 10
UnstartedThread: 0
BackgroundThread: 10
PendingThread: 0
DeadThread: 0
Hosted Runtime: no
PreEmptive GC Alloc Lock
ID OSID ThreadOBJ State GC Context Domain Count APT Exception
7 1 1078 016eced8 8220 Enabled 00000000:00000000 016e84d0 0 Ukn
12 2 fc 016fb0c8 b220 Enabled 00000000:00000000 016e84d0 0 MTA (Finalizer)
10 3 1148 01717b60 880a220 Enabled 00000000:00000000 016e84d0 0 MTA (Threadpool Completion Port)
13 4 680 0171dad8 80a220 Enabled 00000000:00000000 016e84d0 0 MTA (Threadpool Completion Port)
14 5 9b8 0171e470 1220 Enabled 00000000:00000000 016e84d0 0 Ukn
15 6 12a4 017629f0 180b220 Enabled 00000000:00000000 016e84d0 0 MTA (Threadpool Worker)
3 7 1188 016ef888 220 Enabled 00000000:00000000 016e84d0 0 Ukn
17 8 1084 003085e8 180b220 Enabled 00000000:00000000 016e84d0 0 MTA (Threadpool Worker)
18 9 830 03e433b8 180b220 Enabled 00000000:00000000 016e84d0 0 MTA (Threadpool Worker)
19 a f3c 03e79448 220 Enabled 00000000:00000000 016e84d0 0 Ukn
0:018> !clrstack
OS Thread Id: 0x830 (18)
Failed to start stack walk: 80004005
0:018> k
ChildEBP RetAddr
077ef7a4 76630a91 ntdll!ZwWaitForSingleObject+0x15
077ef810 75711194 KERNELBASE!WaitForSingleObjectEx+0x98
077ef828 6ec25497 kernel32!WaitForSingleObjectExImplementation+0x75
077ef86c 6ec253e3 mscorwks!PEImage::LoadImage+0x1af
077ef8bc 6ec25402 mscorwks!CLREvent::WaitEx+0x117
077ef8d0 6ec8b75f mscorwks!CLREvent::Wait+0x17
077ef950 6ec8bbed mscorwks!ThreadpoolMgr::SafeWait+0x73
077ef9b4 6ed8305a mscorwks!ThreadpoolMgr::WorkerThreadStart+0x11c
077efc58 7571339a mscorwks!Thread::intermediateThreadProc+0x49
077efc64 77559ef2 kernel32!BaseThreadInitThunk+0xe
077efca4 77559ec5 ntdll!__RtlUserThreadStart+0x70
077efcbc 00000000 ntdll!_RtlUserThreadStart+0x1b
0:018> !dumpstack
OS Thread Id: 0x830 (18)
Current frame: ntdll!ZwWaitForSingleObject+0x15
ChildEBP RetAddr Caller,Callee
077ef7a4 76630a91 KERNELBASE!WaitForSingleObjectEx+0x98, calling ntdll!ZwWaitForSingleObject
077ef810 75711194 kernel32!WaitForSingleObjectExImplementation+0x75, calling KERNELBASE!WaitForSingleObjectEx
077ef828 6ec25497 mscorwks!PEImage::LoadImage+0x1af
077ef854 6eea07a9 mscorwks!UM2MDoADCallBack+0x98, calling mscorwks!_EH_epilog3
077ef86c 6ec253e3 mscorwks!CLREvent::WaitEx+0x117, calling mscorwks!PEImage::LoadImage+0x180
077ef89c 6ec243ea mscorwks!UnsafeEELeaveCriticalSection+0x25, calling mscorwks!DECTHREADNONHOSTLOCKCOUNT
077ef8a8 6ec243ab mscorwks!CrstBase::Leave+0x8c, calling mscorwks!UnsafeEELeaveCriticalSection
077ef8bc 6ec25402 mscorwks!CLREvent::Wait+0x17, calling mscorwks!CLREvent::WaitEx
077ef8d0 6ec8b75f mscorwks!ThreadpoolMgr::SafeWait+0x73, calling mscorwks!CLREvent::Wait
077ef8f8 6ec2d529 mscorwks!GCHolder<1,0,1>::GCHolder<1,0,1>+0x29, calling mscorwks!Thread::DisablePreemptiveGC
077ef900 6ec299cc mscorwks!Thread::EnablePreemptiveGC+0xf, calling mscorwks!Thread::CatchAtSafePoint
077ef950 6ec8bbed mscorwks!ThreadpoolMgr::WorkerThreadStart+0x11c, calling mscorwks!ThreadpoolMgr::SafeWait
077ef9b4 6ed8305a mscorwks!Thread::intermediateThreadProc+0x49
077ef9d0 77559e83 ntdll!LdrInitializeThunk+0x1a, calling ntdll!NtContinue
077efc44 6ed83048 mscorwks!Thread::intermediateThreadProc+0x37, calling mscorwks!_alloca_probe_16
077efc58 7571339a kernel32!BaseThreadInitThunk+0xe
077efc64 77559ef2 ntdll!__RtlUserThreadStart+0x70
077efca4 77559ec5 ntdll!_RtlUserThreadStart+0x1b, calling ntdll!__RtlUserThreadStart
最佳答案 是的,这是非托管代码.
尝试分析您的代码,以确定代码的哪个部分正在吸收CPU.有一些免费的代码分析器,请查看此主题:
https://stackoverflow.com/questions/308816/any-good-free-net-profiler