@Tmyke, une fois le code si dessous chargé pourrais-tu me dire si la colonne nommé (% (25)) en toute logique correspond bien à la division par 4 de la colonne (% Usage).
Structure SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
IdleTime.q
KernelTime.q
UserTime.q
Reserved1.q[3]
EndStructure
#SystemProcessorPerformanceInformation = 8
#SysProcPerfInfoLength = 48
#PROCESS_QUERY_INFORMATION = $400
#HUNDRED_NANOSEC = 10000000
Declare.l cpu_count()
Global Frequency.q, TimeStart.q
Global NumberOfProcessors = cpu_count()
Global Dim CpuInfo.SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION(NumberOfProcessors)
Global Dim KernelTimesStart.d(NumberOfProcessors+1)
Global Dim UserTimesStart.d(NumberOfProcessors+1)
Global Dim IdleTimesStart.d(NumberOfProcessors+1)
Global Dim KernelTimesStop.d(NumberOfProcessors+1)
Global Dim UserTimesStop.d(NumberOfProcessors+1)
Global Dim IdleTimesStop.d(NumberOfProcessors+1)
Global Dim KernelTimesDelta.d(NumberOfProcessors+1)
Global Dim UserTimesDelta.d(NumberOfProcessors+1)
Global Dim IdleTimesDelta.d(NumberOfProcessors+1)
Global Dim CpuUsages.d(NumberOfProcessors+1)
Procedure.l cpu_count() ; Retourne le nombre de processeur
Protected SI.SYSTEM_INFO
GetSystemInfo_ (@SI)
ProcedureReturn SI\dwNumberOfProcessors
EndProcedure
Procedure.s TimeConvert(time.q)
hr.l = Round (time/36000000000, 0)
time = time-(hr*36000000000)
min.l = Round (time/600000000, 0)
time = time-(min*600000000)
sec.l = Round (time/10000000, 0)
time = time-(sec*10000000)
ms.l = Round (time/10000, 0)
ProcedureReturn Str (hr)+ ":" + RSet ( Str (min), 2, "0" )+ ":" + RSet ( Str (sec), 2, "0" )+ ":" + RSet ( Str (ms), 3, "0" )
EndProcedure
Procedure GetProcessorsTimes(start = #True )
Protected Lib
Lib = OpenLibrary ( #PB_Any , "ntdll.dll" )
If Lib
Function = GetFunction (Lib, "NtQuerySystemInformation" )
If CallFunctionFast (Function, #SystemProcessorPerformanceInformation , @CpuInfo(), #SysProcPerfInfoLength * NumberOfProcessors, 0) = 0
If start = #True
KernelTimesStart(NumberOfProcessors) = 0
IdleTimesStart(NumberOfProcessors) = 0
UserTimesStart(NumberOfProcessors) = 0
For i = 0 To NumberOfProcessors - 1
KernelTimesStart(i) = CpuInfo(i)\KernelTime
IdleTimesStart(i) = CpuInfo(i)\IdleTime
UserTimesStart(i) = CpuInfo(i)\UserTime
KernelTimesStart(NumberOfProcessors) = KernelTimesStart(NumberOfProcessors) + CpuInfo(i)\KernelTime
IdleTimesStart(NumberOfProcessors) = IdleTimesStart(NumberOfProcessors) + CpuInfo(i)\IdleTime
UserTimesStart(NumberOfProcessors) = UserTimesStart(NumberOfProcessors) + CpuInfo(i)\UserTime
Next
Else
KernelTimesStop(NumberOfProcessors) = 0
IdleTimesStop(NumberOfProcessors) = 0
UserTimesStop(NumberOfProcessors) = 0
For i = 0 To NumberOfProcessors - 1
KernelTimesStop(i) = CpuInfo(i)\KernelTime
IdleTimesStop(i) = CpuInfo(i)\IdleTime
UserTimesStop(i) = CpuInfo(i)\UserTime
KernelTimesStop(NumberOfProcessors) = KernelTimesStop(NumberOfProcessors) + CpuInfo(i)\KernelTime
IdleTimesStop(NumberOfProcessors) = IdleTimesStop(NumberOfProcessors) + CpuInfo(i)\IdleTime
UserTimesStop(NumberOfProcessors) = UserTimesStop(NumberOfProcessors) + CpuInfo(i)\UserTime
Next
EndIf
EndIf
CloseLibrary (Lib)
EndIf
EndProcedure
Procedure refresh()
Protected CpuTime.d, CurTime.q, DiffTime.d
QueryPerformanceCounter_ (@CurTime)
GetProcessorsTimes( #False )
CpuUsages(NumberOfProcessors) = 0
For i = 0 To NumberOfProcessors - 1
KernelTimesDelta(i) = KernelTimesStop(i) - KernelTimesStart(i)
UserTimesDelta(i) = UserTimesStop(i) - UserTimesStart(i)
IdleTimesDelta(i) = IdleTimesStop(i) - IdleTimesStart(i)
CpuTime = (KernelTimesDelta(i) + UserTimesDelta(i) + IdleTimesDelta(i))
DiffTime = (CurTime - TimeStart) / Frequency
If DiffTime > 0 : CpuTime = ((CpuTime) / (DiffTime)) / NumberOfProcessors : EndIf
CpuUsages(i) = (100 * (1 - CpuTime / #HUNDRED_NANOSEC ))
If NumberOfProcessors = 1 : CpuUsages(i) = 100 + CpuUsages(i) : EndIf
If CpuUsages(i) < 0 : CpuUsages(i) = 0 : EndIf
If CpuUsages(i) > (100/NumberOfProcessors) : CpuUsages(i) = (100/NumberOfProcessors) : EndIf
SetGadgetItemText (1, i, StrD (CpuUsages(i), 3), 2)
CpuUsages(NumberOfProcessors) = CpuUsages(NumberOfProcessors) + CpuUsages(i)
CpuUsages(i) = CpuUsages(i) * NumberOfProcessors
KernelTimesStart(i) = KernelTimesStop(i)
UserTimesStart(i) = UserTimesStop(i)
IdleTimesStart(i) = IdleTimesStop(i)
SetGadgetItemText (1, i, StrD (CpuUsages(i), 3), 1)
SetGadgetItemText (1, i, TimeConvert(KernelTimesStart(i)), 3)
SetGadgetItemText (1, i, TimeConvert(UserTimesStart(i)), 4)
SetGadgetItemText (1, i, TimeConvert(IdleTimesStart(i)), 5)
Next
KernelTimesStart(NumberOfProcessors) = KernelTimesStop(NumberOfProcessors)
UserTimesStart(NumberOfProcessors) = UserTimesStop(NumberOfProcessors)
IdleTimesStart(NumberOfProcessors) = IdleTimesStop(NumberOfProcessors)
SetGadgetItemText (1, NumberOfProcessors, StrD (CpuUsages(NumberOfProcessors), 3), 1)
SetGadgetItemText (1, NumberOfProcessors, TimeConvert(KernelTimesStart(NumberOfProcessors)), 3)
SetGadgetItemText (1, NumberOfProcessors, TimeConvert(UserTimesStart(NumberOfProcessors)), 4)
SetGadgetItemText (1, NumberOfProcessors, TimeConvert(IdleTimesStart(NumberOfProcessors)), 5)
TimeStart = CurTime
EndProcedure
QueryPerformanceFrequency_ (@Frequency)
QueryPerformanceCounter_ (@TimeStart)
GetProcessorsTimes()
Win = OpenWindow ( #PB_Any , 0, 0, 535, 140, "CPU Usage Multi-Processors" , #PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget )
If IsWindow (Win) And CreateGadgetList ( WindowID (Win))
ListIconGadget (1, 10, 10, 515, 120, "CPU" , 75)
AddGadgetColumn (1, 1, "% Usage" , 60)
AddGadgetColumn (1, 2, "% (" + Str (100/NumberOfProcessors)+ ")" , 60)
AddGadgetColumn (1, 3, "Kernel Time" , 100)
AddGadgetColumn (1, 4, "User Time" , 100)
AddGadgetColumn (1, 5, "Idle Time" , 100)
For i=0 To NumberOfProcessors-1
AddGadgetItem (1, -1, "CPU " + Str (i))
Next
AddGadgetItem (1, NumberOfProcessors, "CPU TOTAL" )
SetTimer_ ( WindowID (Win), 1, 1000, @refresh())
Repeat
Select WaitWindowEvent ()
Case #PB_Event_Gadget
Select EventGadget ()
;Case
EndSelect
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
KillTimer_ ( WindowID (Win), 1)
EndIf