Search  
Wednesday, May 23, 2012 ..:: Forum ::.. Register  Login
 Forum Minimize
Pentru a putea posta mesaje trebuie să vă înregistraţi.
Notă: Mesajele cu conţinut jignitor sau ilegal (inclusiv cereri de soft piratat) nu sunt acceptate şi vor fi şterse imediat .

Pentru a primi raspunsuri rapide si corecte, scrieti in mesaj ce intentionati sa faceti, ce mesaj de eroare primiti, in ce context si in urma caror actiuni. De asemenea, mentionati versiunea de FoxPro in care lucrati!
Dacă nu specificați versiunea, se consideră VFP 9.0 SP2.

SearchForum Home
  Visual FoxPro  Win32 API  CPU Load cu Get...
 CPU Load cu GetSystemTimes
 
 11/15/2006 12:18:41 PM
User is offlineVladPop
250 posts
4th




CPU Load cu GetSystemTimes
 (N/A)
Am vazut un exemplu in VB care folosetse GetSystemTimes() pt returnarea CPU Load.

Pe scurt, scriptul arata asa:

Public Declare Auto Function GetSystemTimes Lib "kernel32.dll" (ByRef idleTime As Int64, ByRef kernelTime As Int64, ByRef userTime As Int64) As Boolean

Public Sub getCPUUsage()
        '
        'These variable are to hold the ending times values.
        Dim eIdle As Int64
        Dim eKernel As Int64
        Dim eUser As Int64
        '
        'These are to hold the starting times values.
        Dim sIdle As Int64
        Dim sKernel As Int64
        Dim sUser As Int64
        '
        'These will hold the values that are calculated from the ending and starting times values.
        Dim cIdle As Int64
        Dim cKernel As Int64
        Dim cUser As Int64
        '
        Dim systemTime As Int32
        Dim totalCpuUsage As Single 'Long 'Int64
        '
        'Update the runLoop variable to False.
        runLoop = False

        Do
            '
            'Retrieve the Times values before starting the delay.
            GetSystemTimes(sIdle, sKernel, sUser)
            '
            'The delay for how often to check and update the cpu usage values.
            cpuUsageThread.Sleep(updateSpeed)
            '
            'Retrieve the Times values after the Delay.
            GetSystemTimes(eIdle, eKernel, eUser)
            '
            'Get the values calculated between the starting and ending Times values.
            cIdle = (eIdle - sIdle)
            cKernel = (eKernel - sKernel)
            cUser = (eUser - sUser)
            '
            'Calculate the total system time. Which is Kernel and User time together.
            systemTime = (cKernel + cUser)
            '
            'Simply check if the rounded option is true or not and display the usage value.
            If chkRound.Checked Then
                '
                'Calculate the total System CPU Usage. If you have a Dual Core/Dual CPU system like I
                'have, then this value will be the usage value based on BOTH cpu's. Ex: CPU1 is at 100%
                'usage, CPU2 is at 0% usage, then the Total Usage would be 50%.
                totalCpuUsage = (systemTime - cIdle) * (100) \ (systemTime)

            Else
                '
                'Calculate the total System CPU Usage. If you have a Dual Core/Dual CPU system like I
                'have, then this value will be the usage value based on BOTH cpu's. Ex: CPU1 is at 100%
                'usage, CPU2 is at 0% usage, then the Total Usage would be 50%.
                totalCpuUsage = (systemTime - cIdle) * (100) / (systemTime)

            End If

            'System.Windows.Forms.Application.DoEvents()

            lblCPUUsage.Text = "Total CPU Usage: " & totalCpuUsage.ToString & "%"

        Loop Until runLoop = True

    End Sub

OK. Acum am incercat si in VFP sa fac chestia asta:
 
DECLARE GetSystemTimes in kernel32 Long @idleTime, Long @kernelTime, Long @userTime

LOCAL sidleTime as Long , skernelTime as Long , suserTime  as Long

GetSystemTimes(@sidleTime, @skernelTime, @suserTime)

? suserTime
DISPLAY DLLS

Ei, in acest moment suserTime returneaza .T., in schimb cred ca ar trebui sa returneze un numar. TRUE ar trebui sa returneze functia in sine si nu inteleg de ce variabila nu primeste valoarea care trebuie. Unde e problema?

Link la MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemtimes.asp



Vlad Pop.
  Visual FoxPro  Win32 API  CPU Load cu Get...

Search  Forum Home         

 Google Ads Minimize

    

Copyright 2002-2010 Profox   Terms Of Use  Privacy Statement