Announcement

Collapse
No announcement yet.

System Resources

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • System Resources

    Does anyone know how the system resources is calculated?

    Ie my system currently states I have 83% system resources available..

    I'm playing around with a function to determine the load on the system...

    So far I have this...hehe

    Function GetHealthOfServer() As Long
    Local vi As OSVERSIONINFO
    Local m As MEMORYSTATUS
    Local mPercent As Long
    Local pPercent As Long
    Local vPercent As Long
    'Get version of windows
    vi.dwOsVersionInfoSize = SizeOf(vi)
    GetVersionEx vi
    'Get memory information
    GlobalMemoryStatus m

    pPercent = (m.dwAvailPhys / m.dwTotalPhys) * 100 'How much Physical ram
    vPercent = (m.dwAvailVirtual / m.dwTotalVirtual) * 100 'Virtual Ram
    mPercent = m.dwMemoryLoad 'Memory load on system
    End Function



    -------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    I'm curious now...
    I ran a program that I am working on, and just by opening up ONE created DDT dialog, It created 6 threads, then settled back to 4 when the splash screen was done...
    There's 4 open threads for one GUI interface, when it goes out and checks the atomic clock I open a new thread, it increments on Windows 2000 meter, the time returns from teh atomic clock, and then the thread decrements, but where are the other 4 coming from? Just internal stuff??


    And how do you determine CPU utilization?? Anyone done this before???


    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

    Comment


    • #3
      I would suspect that Winsock is the cause of the additional threads... you are using Winsock (or the PB/DLL encapsulation of Winsock) in your code I assume?

      I don't have the information handy, but I remember reading that CPU utilization can be queried from the registry (of all places!)... I also recall that this only works under Windows NT (if my memory serves me correctly... the usual disclaimer applies! ).

      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Scott --
        About 9x - see http://www.codepile.com/tric20.shtml
        About NT - I saw also (maybe I'll remember and will add reference here).
        But almost sure that are used logs of perfmon.exe (you can find it in WinNt\system32; all more or less described in it's help)

        [This message has been edited by Semen Matusovski (edited April 11, 2000).]

        Comment


        • #5

          Here's one that might be easier for you. You will still have to translate the code from VB to PB, but it shouldn't take that long. The results will be worth it!

          Code:
          Option Explicit
          
          ' api declaration to get the cursors position
          Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
          
          ' declare type to store the coordinates
          Private Type POINTAPI
              X As Long
              Y As Long
          End Type
          
          ' api declarations for our CPU meter
          Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As LARGE_INTEGER) As Long
          Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As LARGE_INTEGER) As Long
          
          Const REG_DWORD = 4
          Const HKEY_DYN_DATA = &H80000006
          
          Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
          Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
          Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
          
          Private Type LARGE_INTEGER
              lowpart As Long
              highpart As Long
          End Type
          
          ' api declarations to raise our form
          Private Declare Function DrawFrameControl Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal un1 As Long, ByVal un2 As Long) As Long
          Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
          Private Declare Function OffsetRect Lib "user32" (lpRect As RECT, ByVal X As Long, ByVal Y As Long) As Long
          
          Const DFC_BUTTON = 4
          Const DFCS_BUTTON3STATE = &H10
          
          Private Type RECT
              Left As Long
              Top As Long
              Right As Long
              Bottom As Long
          End Type
          
          ' api declarations to make form stay on top
          Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
          
          Const SWP_NOMOVE = &H2
          Const SWP_NOSIZE = &H1
          Const SWP_SHOWWINDOW = &H40
          Const HWND_TOPMOST = -1
          Const HWND_NOTTOPMOST = -2
          
          
          Private Sub Form_Load()
          
              ' set the two timer intervals
              tmrFormMove.Interval = 1
              tmrCpuStatus.Interval = 500 'used 500 cause our program needs resources too
              
              ' color the background shape and picturebox
              shpBack.BackColor = RGB(0, 10, 90)
              shpBack.BorderColor = RGB(0, 10, 90)
              picStatus.BackColor = RGB(130, 130, 170)
              
              ' raise our form
              RaiseForm
              
              ' initialize our CPU meter
              InitCPU
              
          End Sub
          
          
          Private Sub RaiseForm()
              
              Dim R As RECT
              
              Me.ScaleMode = vbPixels
              SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
              DrawFrameControl Me.hdc, R, DFC_BUTTON, DFCS_BUTTON3STATE
              OffsetRect R, 0, 22
          
          End Sub
          
          
          Private Sub InitCPU()
          
              Dim lData As Long
              Dim lType As Long
              Dim lSize As Long
              Dim hKey As Long
              Dim Qry As String
              
              Qry = RegOpenKey(HKEY_DYN_DATA, "PerfStats\StartStat", hKey)
              
              If Qry <> 0 Then
                      MsgBox "Could not open registery!"
                  End
              End If
              
              lType = REG_DWORD
              lSize = 4
              
              Qry = RegQueryValueEx(hKey, "KERNEL\CPUUsage", 0, lType, lData, lSize)
              Qry = RegCloseKey(hKey)
          
          End Sub
          
          
          Private Sub tmrFormMove_Timer()
              
              Dim Point As POINTAPI
              
              ' get the cursorposition
              GetCursorPos Point
          
              ' multiply the coordinates to convert twips to pixel and place the form
              Me.Left = Point.X * 15 + 200
              Me.Top = Point.Y * 15 + 150
              
               ' make our form stay on top
              SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE + SWP_NOMOVE
              
          End Sub
          
          
          Private Sub tmrCpuStatus_Timer()
          
              Dim lData As Long
              Dim lType As Long
              Dim lSize As Long
              Dim hKey As Long
              Dim Qry As String
              Dim Status As Long
                            
              Qry = RegOpenKey(HKEY_DYN_DATA, "PerfStats\StatData", hKey)
                          
              If Qry <> 0 Then
                      MsgBox "Could not open registery!"
                  End
              End If
                          
              lType = REG_DWORD
              lSize = 4
                          
              Qry = RegQueryValueEx(hKey, "KERNEL\CPUUsage", 0, lType, lData, lSize)
              
              Status = Int(lData)
          
              ' show CPU usage in Label
              lblStatus.Caption = Status & "%"
              
              ' show CPU usage in our selfmade progressbar
              ' when CPU usage is over 80% then color the status red
              If Status < 80 Then
              picStatus.Line (Status, 0)-(0, 10), RGB(255, 245, 85), BF
              Else
              picStatus.Line (Status, 0)-(0, 10), RGB(245, 10, 0), BF
              End If
              picStatus.Line (Status, 0)-(100, 10), RGB(130, 130, 170), BF
              
              Qry = RegCloseKey(hKey)
          
          End Sub
          Have a great day!

          MWM



          ------------------
          mwm
          mwm

          Comment


          • #6
            Thanks
            I took the link, translated the C++ code and posted it in the source code forum, it works, but it's alla bout averages and "At taht very moment", which means you may have to test it repeatedly.

            I tested 30 times in a row, 8%, told it to test 300 times, 12%, which is fair, I was draining a bit of processor time doing it

            Think I'm good to go now!
            Thanks all!

            Scott

            ------------------
            Scott
            mailto:[email protected][email protected]</A>
            Scott Turchin
            MCSE, MCP+I
            http://www.tngbbs.com
            ----------------------
            True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

            Comment


            • #7
              I need to return information on the physical memory of servers (win 2003 OS) as part of an inventory process. The following code only returns a maximum of 2gigabytes even when the server physical memory is greater than this, has any one come across this before?

              Code:
              $INCLUDE "WIN32API.INC"
              
              'TYPE MEMORYSTATUS
              '  dwLength AS DWORD
              '  dwMemoryLoad AS DWORD
              '  dwTotalPhys AS DWORD
              '  dwAvailPhys AS DWORD
              '  dwTotalPageFile AS DWORD
              '  dwAvailPageFile AS DWORD
              '  dwTotalVirtual AS DWORD
              '  dwAvailVirtual AS DWORD
              'END TYPE
              
              
              FUNCTION PBMAIN()
                  DIM temp AS LONG
                  DIM Mem_status AS MEMORYSTATUS
                  GlobalMemoryStatus  Mem_Status
                  STDOUT "PHYSICAL MEMORY      : "+STR$(mem_status.dwTotalPhys/(1024*1024))+" MB"
                  STDOUT "PHYSICAL MEMORY AVAIL: "+STR$(mem_status.dwAvailPhys/(1024*1024))+" MB"
                  STDOUT "PAGE FILE TOTAL      : "+STR$(mem_status.dwTotalPageFile/(1024*1024))+" MB"
                  STDOUT "PAGE FILE AVAIL      : "+STR$(mem_status.dwAvailPageFile/(1024*1024))+" MB"
                  STDOUT "VIRTUAL MEMORY       : "+STR$(mem_status.dwTotalVirtual/(1024*1024))+" MB"
                  STDOUT "VIRTUAL MEMORY AVAIL : "+STR$(mem_status.dwAvailVirtual/(1024*1024))+" MB"
                  WAITKEY$
              END FUNCTION

              Comment


              • #8
                From MSDN:
                On computers with more than 4 GB of memory, the MEMORYSTATUS structure can return incorrect information, reporting a value of –1 to indicate an overflow. If your application is at risk for this behavior, use the GlobalMemoryStatusEx function instead of the GlobalMemoryStatus function.
                Code:
                $INCLUDE "WIN32API.INC"
                
                
                FUNCTION PBMAIN()
                    DIM Mem_status AS MEMORYSTATUSEX
                    Mem_status.dwLength = SIZEOF(Mem_status)
                    
                    GlobalMemoryStatusEx  Mem_Status
                    STDOUT "PHYSICAL MEMORY      : "+STR$(mem_status.ullTotalPhys/(1024*1024))+" MB"
                    WAITKEY$
                END FUNCTION
                Last edited by Paul Dixon; 25 Jun 2010, 06:49 AM.

                Comment


                • #9
                  Many thanks Paul

                  That's just what I was looking for

                  Comment

                  Working...
                  X