Close

Results 1 to 10 of 10
  1. #1
    DF Probation Goldberg's Avatar
    Join Date
    Jun 2001
    Location
    Landaaaan!
    Posts
    14,453
    Thanks
    1,325
    Thanked:        1,547
    Karma Level
    1153

    Default Log CPU Usage in VB.Net

    As per the title, any ideas?

    Done some searches on Google with no joy. There must be a way to log the current CPU usage in VB.Net?

    Thanks,

    Goldy
    We all make mistakes sometimes

  2. #2
    DF VIP Member shadowdancer's Avatar
    Join Date
    May 2002
    Location
    Inverness
    Posts
    1,536
    Thanks
    0
    Thanked:        0
    Karma Level
    395

    Default Re: Log CPU Usage in VB.Net

    never done it myself yet but this might help a bit, its some c# code that explains a fair bit about it.
    should be a simple process to convert to vb.net if you need to

    http://www.codeproject.com/csharp/processescpuusage.asp

  3. #3
    DF Probation Goldberg's Avatar
    Join Date
    Jun 2001
    Location
    Landaaaan!
    Posts
    14,453
    Thanks
    1,325
    Thanked:        1,547
    Karma Level
    1153

    Default Re: Log CPU Usage in VB.Net

    Cheers mate, had a go with a few examples will let you know how I get on.
    We all make mistakes sometimes

  4. #4
    DF Member keifster's Avatar
    Join Date
    Aug 2006
    Location
    UK
    Posts
    48
    Thanks
    0
    Thanked:        0
    Karma Level
    0

    Default Re: Log CPU Usage in VB.Net

    what version of vb are you using?

  5. #5
    DF VIP Member Nikki's Avatar
    Join Date
    Dec 2002
    Location
    Walsall
    Posts
    12,413
    Thanks
    559
    Thanked:        148
    Karma Level
    899

    Default Re: Log CPU Usage in VB.Net

    Have you sorted this yet goldberg?

  6. #6
    DF Probation Goldberg's Avatar
    Join Date
    Jun 2001
    Location
    Landaaaan!
    Posts
    14,453
    Thanks
    1,325
    Thanked:        1,547
    Karma Level
    1153

    Default Re: Log CPU Usage in VB.Net

    Yes mate, however it's at work. If you want to know what I did I can post it later.

    Sorry for the delays in getting back, I've had probs getting Sky BRoadband sorted
    We all make mistakes sometimes

  7. #7
    DF VIP Member Nikki's Avatar
    Join Date
    Dec 2002
    Location
    Walsall
    Posts
    12,413
    Thanks
    559
    Thanked:        148
    Karma Level
    899

    Default Re: Log CPU Usage in VB.Net

    no probs. yeah it would be good to know that matey,

    cheers

  8. #8
    DF Probation Goldberg's Avatar
    Join Date
    Jun 2001
    Location
    Landaaaan!
    Posts
    14,453
    Thanks
    1,325
    Thanked:        1,547
    Karma Level
    1153

    Default Re: Log CPU Usage in VB.Net

    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
    Last edited by Goldberg; 28th September 2006 at 11:53 AM.
    We all make mistakes sometimes

  9. #9
    DF Member keifster's Avatar
    Join Date
    Aug 2006
    Location
    UK
    Posts
    48
    Thanks
    0
    Thanked:        0
    Karma Level
    0

    Default Re: Log CPU Usage in VB.Net

    I'm a bit confused.... you don't set the value of Cores anywhere

  10. #10
    DF Probation Goldberg's Avatar
    Join Date
    Jun 2001
    Location
    Landaaaan!
    Posts
    14,453
    Thanks
    1,325
    Thanked:        1,547
    Karma Level
    1153

    Default Re: Log CPU Usage in VB.Net

    Ah, I do that in a different procedure. I have 3 radio buttons and depending on which radio button is checked sets the value once the 'Start' button is pressed.

    The reason I have 'Dim Cores as Integer' in the example is to list the variables I am using. Cores is a Global Variable and is set when the program loads.
    We all make mistakes sometimes

Similar Threads

  1. CPU Usage 100%
    By Elbow in forum PC Problems
    Replies: 10
    Last Post: 3rd April 2005, 12:20 PM
  2. Power usage
    By hangmansjoe in forum PC Problems
    Replies: 3
    Last Post: 4th January 2005, 12:09 PM
  3. Replies: 2
    Last Post: 19th June 2004, 11:37 PM
  4. WtoolsA.exe - 100% CPU usage
    By lombie in forum PC Problems
    Replies: 2
    Last Post: 19th May 2004, 07:32 PM
  5. CPU Usage
    By Knight-templar in forum PC Problems
    Replies: 1
    Last Post: 30th October 2003, 11:32 PM

Social Networking Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •