Detect slow response apps!

Share your advanced PureBasic knowledge/code with the community.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Detect slow response apps!

Post by Rescator »

Code updated for 5.20+

Note! Code is rudimentary! It fails to get the correct filename in some cases, and the window/program title may be blank or just a letter or some other weirdness! Hopefully the processid will help you though.
Task Manager should have a view setting in it's menu to show PID's,
or get Process Explorer from http://www.sysinternals.com which is task manager on steroids!

Code: Select all

;This little program let you detect slow response apps,
;usually apps that have bad message loops and sleeps and polls every few seconds
;rather than wait for messages, this behaviour can cause general system slowdowns
;as such apps could delay the respone of the system message queue.

OpenConsole()

Global NewList windowHandles()

Procedure EnumWindowsProc(hwnd, lParam)
 AddElement(windowHandles())
 If hwnd<>0
  windowHandles()=hwnd
 EndIf
 ProcedureReturn #True
EndProcedure

timeBeginPeriod_(1)
EnumWindows_(@EnumWindowsProc(),#Null)
PrintN("Found "+Str(ListSize(windowHandles()))+" windows!")
PrintN("")
startTime=0
messageTime=0
result=0
windowName$=Space(#MAX_PATH)
fileName$=Space(#MAX_PATH)
ForEach windowHandles()
 startTime=timeGetTime_()
 SendMessageTimeout_(windowHandles(),#WM_NULL,0,0,#SMTO_BLOCK,1000,@result)
 messageTime=timeGetTime_()-startTime
 If messageTime>10
  GetWindowText_(windowHandles(),windowName$,#MAX_PATH-1)
  GetWindowThreadProcessId_(windowHandles(),@processId)
  GetWindowModuleFileName_(windowHandles(),fileName$,#MAX_PATH-1)
  PrintN("Window "+Chr(34)+windowName$+Chr(34)+" (procId "+Str(processId)+") took "+Str(messageTime)+"ms to respond!")
  PrintN("File: "+fileName$)
  PrintN("")
 EndIf
Next
timeEndPeriod_(1)

PrintN("")
PrintN("Press a key to quit!")
Input()
djk
New User
New User
Posts: 2
Joined: Tue Oct 25, 2005 2:20 pm
Location: On a dirt road in the USA

Post by djk »

Thanks sos much R... This is perfect for what I need at present
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Thanks for posting the link to Sysinternals, that's quite a task manager replacement.
BERESHEIT
Post Reply