@Bisonte:
Good start, thank you!
Some suggestions:
1.) Please split the CPU info to number of CPUs + all CPUs (CPU 1: 100% CPU 2: 0% CPU 3: 0% CPU 4: 0% CPU ALL: 25%)
2.) Add CPU peak display, same as (1) but peak
3.) Make the CPU and CPU peak simple graphical bars. (You could join CPU and CPU peak into one image)
Code: Select all
Structure CpuInfo
current.i
peak.i
falldown.i
image.i
EndStructure
Global Dim CPU.CpuInfo(4)
Procedure RedrawCPUImage(cpu,value,falldown=#False)
CPU(cpu)\current = value
If CPU(cpu)\peak < CPU(cpu)\current
CPU(cpu)\peak = CPU(cpu)\current
CPU(cpu)\falldown = CPU(cpu)\current
Else
If falldown = #True
CPU(cpu)\falldown - 3
If CPU(cpu)\falldown < CPU(cpu)\current
CPU(cpu)\falldown = CPU(cpu)\current
EndIf
EndIf
EndIf
If CPU(cpu)\image = 0
CPU(cpu)\image = CreateImage(#PB_Any,20,100,24)
EndIf
If CPU(cpu)\image And StartDrawing( ImageOutput( CPU(cpu)\image ) )
Box(0,0,20,100,0)
;Box(0,100-CPU(cpu)\peak ,20,100,RGB(255, 0 ,0))
Box(0,100-CPU(cpu)\current,20,100,RGB(255,255,0))
If falldown
Box(0,100-CPU(cpu)\falldown,20, 2,RGB(0,255,0))
EndIf
Box(0,100-CPU(cpu)\peak ,20, 2,RGB(255, 0 ,0))
StopDrawing()
EndIf
EndProcedure
If OpenWindow(0, 0, 0, 300, 200, "CPU", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ImageGadget(1, 10, 10, 20, 100, 0, #PB_Image_Border)
ImageGadget(2, 35, 10, 20, 100, 0, #PB_Image_Border)
ImageGadget(3, 60, 10, 20, 100, 0, #PB_Image_Border)
ImageGadget(4, 85, 10, 20, 100, 0, #PB_Image_Border)
AddWindowTimer(0,0,250)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
Case #PB_Event_Timer
RedrawCPUImage(1, Random(80))
SetGadgetState(1, ImageID(CPU(1)\image))
RedrawCPUImage(2, Random(35))
SetGadgetState(2, ImageID(CPU(2)\image))
RedrawCPUImage(3, Random(100), #True)
SetGadgetState(3, ImageID(CPU(3)\image))
RedrawCPUImage(4, Random(70), #True)
SetGadgetState(4, ImageID(CPU(4)\image))
EndSelect
ForEver
EndIf
4.) Monitor handles used by the process:
Code: Select all
#GR_GDIOBJECTS = 0
#GR_GDIOBJECTS_PEAK = 2
#GR_USEROBJECTS = 1
#GR_USEROBJECTS_PEAK = 4
ProcessHandle = OpenProcess_(#PROCESS_QUERY_INFORMATION,#False,GetCurrentProcessId_())
If ProcessHandle
Debug "GDI handles : "+Str( GetGuiResources_(ProcessHandle, #GR_GDIOBJECTS))
If OSVersion() >= #PB_OS_Windows_7 ;Or OSVersion() >= #PB_OS_Windows_Server_2008_R2
Debug "GDI (peak) : "+Str( GetGuiResources_(ProcessHandle, #GR_GDIOBJECTS_PEAK))
EndIf
Debug "USER handles: "+Str( GetGuiResources_(ProcessHandle, #GR_USEROBJECTS))
If OSVersion() >= #PB_OS_Windows_7 ;Or OSVersion() >= #PB_OS_Windows_Server_2008_R2
Debug "USER (peak) : "+Str( GetGuiResources_(ProcessHandle, #GR_USEROBJECTS_PEAK))
EndIf
CloseHandle_(ProcessHandle)
EndIf
5.) Make a macro and compile it with /RESIDENT switch. Put it in "PureBasic\residents" folder.
Code: Select all
Macro ShowResourceViewer()
RunProgram(#PB_Compiler_Home + "PureMonitor.exe", Str(GetCurrentProcessId_()), "")
EndMacro
We just use ShowResourceViewer() in our sources (like ShowMemoryViewer() and ShowAssemblyViewer()).
It should also work with disabled debugger, the user can add "CompilerIf #PB_Compiler_Debugger" himself if he wants.
6.) Remember the window position (like ShowMemoryViewer() and ShowAssemblyViewer())
7.) Maybe make the window size-able, and remember the size.
EDIT:
8.) Of course also memory peak would be useful (how much memory was consumed at most)
9.) Please add general process handle count and peak for it (in addition to GDI/USER handles)
Code: Select all
Import "Kernel32.lib"
GetProcessHandleCount(hProcess,pHandles.l)
EndImport
Procedure GetHandleCount()
Protected handleCount.l
ProcessHandle = OpenProcess_(#PROCESS_ALL_ACCESS,#False,GetCurrentProcessId_())
If ProcessHandle
GetProcessHandleCount(ProcessHandle,@handleCount)
CloseHandle_(ProcessHandle)
EndIf
ProcedureReturn handleCount
EndProcedure
handles = GetHandleCount()
If handles > peak_handles
peak_handles = handles
EndIf
Debug handles
Debug peak_handles