Here you go mate, hopefully this makes sense, I've put in the whole sub procedure. It basically log's individual Cores (in percent) then I work out from that the overall percentage.
Takes a while to do but does work The debug comments are so I can see in VS. This basically writes out to a log file. You need : Imports System.Diagnostics
We have machines with 8 dual core CPU's fecking mad they are!
Code:
Private Sub CPU_Usage()
Dim objWMI As Object
Dim j As Integer
Dim Machine As Integer
Dim Cores As Integer
'Procedure to get the cpu usage whilst playback is taking place.
objWMI = GetObject("winmgmts:")
Dim strCls, strCPU As String
Dim Usage As Integer
Dim TotalUse As Integer
Dim i As Integer
strCls = "Win32_Processor"
'Create File and open to append
Dim desktoppath As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\logs.txt".ToString()
Dim oFile As System.IO.File
Dim oWrite As System.IO.StreamWriter
oWrite = oFile.AppendText(desktoppath)
'Need to repeat for each thread. X5 will be 4, X9 will be 8 and X17 will be 16!
For i = 1 To Cores
strCPU = "CPU" & i - 1
'Debug.WriteLine(objWMI.InstancesOf(strCls)(strCls & ".DeviceID=""" & strCPU & """").LoadPercentage)
Usage = (objWMI.InstancesOf(strCls)(strCls & ".DeviceID=""" & strCPU & """").LoadPercentage)
Debug.WriteLine(Usage)
'Store each thread each time
TotalUse = TotalUse + Usage
'Want to open and close the file each pass so that if we crash we still keep all dat we logged.
'Now write threads to file
oWrite.WriteLine("Thread " & i & " " & Usage & "%")
oWrite.Close()
're-open for the next pass.
oWrite = oFile.AppendText(desktoppath)
Next i
'Calculate the Average based on core's 4 for X5, 8 for X9 and 18 for X17
TotalUse = TotalUse / Cores
Debug.WriteLine(TotalUse & "%")
oWrite.WriteLine("Total CPU Use: " & TotalUse & "%")
oWrite.WriteLine()
oWrite.Close()
End Sub
Social Networking Bookmarks