Re: 99% CPU usage in CWinThread::PumpMessage
From: KS (ks_at_blah.com)
Date: 04/12/04
- Next message: Yasoo: "Windows NT Symbols Setup"
- Previous message: David W. Simmonds: "MFC Extension library problem"
- In reply to: Olaf van der Spek: "Re: 99% CPU usage in CWinThread::PumpMessage"
- Next in thread: Olaf van der Spek: "Re: 99% CPU usage in CWinThread::PumpMessage"
- Reply: Olaf van der Spek: "Re: 99% CPU usage in CWinThread::PumpMessage"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 12 Apr 2004 10:18:44 -0600
Here's the code from ThrdCore.cpp
BOOL CWinThread::PumpMessage()
{
ASSERT_VALID(this);
if (!::GetMessage(&m_msgCur, NULL, NULL, NULL))
{
#ifdef _DEBUG
if (afxTraceFlags & traceAppMsg)
TRACE0("CWinThread::PumpMessage - Received WM_QUIT.\n");
m_nDisablePumpCount++; // application must die
// Note: prevents calling message loop things in 'ExitInstance'
// will never be decremented
#endif
return FALSE;
}
#ifdef _DEBUG
if (m_nDisablePumpCount != 0)
{
TRACE0("Error: CWinThread::PumpMessage called when not permitted.\n");
ASSERT(FALSE);
}
#endif
#ifdef _DEBUG
if (afxTraceFlags & traceAppMsg)
_AfxTraceMsg(_T("PumpMessage"), &m_msgCur);
#endif
// process this message
if (m_msgCur.message != WM_KICKIDLE && !PreTranslateMessage(&m_msgCur))
{
::TranslateMessage(&m_msgCur);
::DispatchMessage(&m_msgCur);
}
return TRUE;
}
You can see it really doesn't do much, other than a ::TranslateMessage() and
::DispatchMessage() ...
The only suggestion I have is to subclass the CWinThread class with your own
class and override this method and put the same code into your method. Then
after the ::DispatchMessage() add a Sleep(10). You'd also be able to see
what messages are being passed that is hogging up all the CPU usage.
KS
"Olaf van der Spek" <Olaf@XCC.TMFWeb.NL> wrote in message
news:utEhUWKIEHA.3276@tk2msftngp13.phx.gbl...
> KS wrote:
> > Not sure without seeing the code.
>
> If I understand the profiler output correctly, the following lines tell
> me that the PumpMessage function consumed 98.6% of the time itself and
> 99.1% of the time was consumed by itself and it's children.
> >> 75351,273 98,6 75773,696 99,1 1437
> >>CWinThread::PumpMessage(void) (mfc42d.dll)
>
> > But if you have a thread that has a loop in it, I'd suggest putting a
> > Sleep(100) inside the loop. I've had problems with threads hogging up
> > resources.
>
> I do have a loop, but it's blocking on a select call.
> >
> > Another possibility is to lower the thread's priority.
>
> That won't solve the CPU usage itself, although it's a reasonable
> temporary workaround.
> >
> > KS
> >
> > "Olaf van der Spek" <Olaf@XCC.TMFWeb.NL> wrote in message
> > news:u6f7utJIEHA.3444@TK2MSFTNGP11.phx.gbl...
> >
> >>Hi,
> >>
> >>I'm writing a file transfer application and I'm stuck with a nasty
> >>issue. For some weird reason, CPU usage hits 99% some times. So I fired
> >>up the VC6 profiler, the results are attached.
> >>
> >>98% of the time is spend inside CWinThread::PumpMessage
> >>But that's a simple function, how can so much time be spend there?
> >>
> >>Profile: Function timing, sorted by time
> >>Date: Sun Apr 11 21:12:13 2004
> >>
> >>
> >>Program Statistics
> >>------------------
> >> Command line at 2004 Apr 11 20:57: "F:\VC\xbt\XBT Client\Debug\XBT
> >>Client"
> >> Total time: 76459,318 millisecond
> >> Time outside of functions: 20,774 millisecond
> >> Call depth: 36
> >> Total functions: 3188
> >> Total hits: 1435373
> >> Function coverage: 39,6%
> >> Overhead Calculated 2
> >> Overhead Average 2
> >>
> >>Module Statistics for xbt client.exe
> >>------------------------------------
> >> Time in module: 76438,544 millisecond
> >> Percent of time in module: 100,0%
> >> Functions in module: 3188
> >> Hits in module: 1435373
> >> Module function coverage: 39,6%
> >>
> >> Func Func+Child Hit
> >> Time % Time % Count Function
> >>---------------------------------------------------------
> >> 75351,273 98,6 75773,696 99,1 1437
> >>CWinThread::PumpMessage(void) (mfc42d.dll)
> >> 75,806 0,1 75,806 0,1 58546 operator delete(void *)
> >>(mfc42d.dll)
> >> 73,318 0,1 107,126 0,1 155186
> >>std::allocator<bool>::destroy(bool *) (bt_file.obj)
> >
> >
> >
- Next message: Yasoo: "Windows NT Symbols Setup"
- Previous message: David W. Simmonds: "MFC Extension library problem"
- In reply to: Olaf van der Spek: "Re: 99% CPU usage in CWinThread::PumpMessage"
- Next in thread: Olaf van der Spek: "Re: 99% CPU usage in CWinThread::PumpMessage"
- Reply: Olaf van der Spek: "Re: 99% CPU usage in CWinThread::PumpMessage"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|