IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++Builder Discussion :

Comment récupérer le % d'utilisation du processeur ?


Sujet :

C++Builder

  1. #1
    Membre régulier

    Inscrit en
    Janvier 2003
    Messages
    38
    Détails du profil
    Informations forums :
    Inscription : Janvier 2003
    Messages : 38
    Points : 76
    Points
    76
    Par défaut Comment récupérer le % d'utilisation du processeur ?
    Bonjour,

    Je cherche à récupérer le % d'utilisation du processeur d'une machine à un instant t. Quelqu'un saurait-il comment procéder ?

    Merci.
    sly

  2. #2
    Membre actif

    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    472
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Septembre 2002
    Messages : 472
    Points : 262
    Points
    262
    Par défaut yop
    Salut,
    J'ai regardé un peu sur le net... Je pense qu'il faut passer par de l'assembleur. Regarde sur Torry.net du coté des composants qui font ça!
    Bon Courrage,
    Bonne Nuit,
    MaTHieU_
    Embarcadero RAD Studio XE / Microsoft Windows 7 Édition Intégrale (64 bits)

  3. #3
    Membre régulier

    Inscrit en
    Janvier 2003
    Messages
    38
    Détails du profil
    Informations forums :
    Inscription : Janvier 2003
    Messages : 38
    Points : 76
    Points
    76
    Par défaut
    J'ai trouvé
    pour ceux que ça intéresse:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
     
    #include <windows.h>
    #include <conio.h>
    #include <stdio.h>
     
    #define SystemBasicInformation       0
    #define SystemPerformanceInformation 2
    #define SystemTimeInformation        3
     
    #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + (double)((x).LowPart))
     
    typedef struct
    {
        DWORD   dwUnknown1;
        ULONG   uKeMaximumIncrement;
        ULONG   uPageSize;
        ULONG   uMmNumberOfPhysicalPages;
        ULONG   uMmLowestPhysicalPage;
        ULONG   uMmHighestPhysicalPage;
        ULONG   uAllocationGranularity;
        PVOID   pLowestUserAddress;
        PVOID   pMmHighestUserAddress;
        ULONG   uKeActiveProcessors;
        BYTE    bKeNumberProcessors;
        BYTE    bUnknown2;
        WORD    wUnknown3;
    } SYSTEM_BASIC_INFORMATION;
     
    typedef struct
    {
        LARGE_INTEGER   liIdleTime;
        DWORD           dwSpare[76];
    } SYSTEM_PERFORMANCE_INFORMATION;
     
    typedef struct
    {
        LARGE_INTEGER liKeBootTime;
        LARGE_INTEGER liKeSystemTime;
        LARGE_INTEGER liExpTimeZoneBias;
        ULONG         uCurrentTimeZoneId;
        DWORD         dwReserved;
    } SYSTEM_TIME_INFORMATION;
     
     
    // ntdll!NtQuerySystemInformation (NT specific!)
    //
    // The function copies the system information of the
    // specified type into a buffer
    //
    // NTSYSAPI
    // NTSTATUS
    // NTAPI
    // NtQuerySystemInformation(
    //    IN UINT SystemInformationClass,    // information type
    //    OUT PVOID SystemInformation,       // pointer to buffer
    //    IN ULONG SystemInformationLength,  // buffer size in bytes
    //    OUT PULONG ReturnLength OPTIONAL   // pointer to a 32-bit
    //                                       // variable that receives
    //                                       // the number of bytes
    //                                       // written to the buffer 
    // );
    typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);
     
    PROCNTQSI NtQuerySystemInformation;
     
     
    void main(void)
    {
        SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
        SYSTEM_TIME_INFORMATION        SysTimeInfo;
        SYSTEM_BASIC_INFORMATION       SysBaseInfo;
        double                         dbIdleTime;
        double                         dbSystemTime;
        LONG                           status;
        LARGE_INTEGER                  liOldIdleTime = {0,0};
        LARGE_INTEGER                  liOldSystemTime = {0,0};
     
        NtQuerySystemInformation = (PROCNTQSI)GetProcAddress(
                                              GetModuleHandle("ntdll"),
                                             "NtQuerySystemInformation"
                                             );
     
        if (!NtQuerySystemInformation)
            return;
     
        // get number of processors in the system
        status = NtQuerySystemInformation(SystemBasicInformation,&SysBaseInfo,sizeof(SysBaseInfo),NULL);
        if (status != NO_ERROR)
            return;
     
     printf("\nCPU Usage (press any key to exit):    ");
        while(!kbhit())
        {
            // get new system time
         status = NtQuerySystemInformation(SystemTimeInformation,&SysTimeInfo,sizeof(SysTimeInfo),0);
            if (status!=NO_ERROR)
                return;
     
            // get new CPU's idle time
            status = NtQuerySystemInformation(SystemPerformanceInformation,&SysPerfInfo,sizeof(SysPerfInfo),NULL);
            if (status != NO_ERROR)
                return;
     
            // if it's a first call - skip it
           if (liOldIdleTime.QuadPart != 0)
           {
                // CurrentValue = NewValue - OldValue
                dbIdleTime = Li2Double(SysPerfInfo.liIdleTime) - Li2Double(liOldIdleTime);
                dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime);
     
                // CurrentCpuIdle = IdleTime / SystemTime
                dbIdleTime = dbIdleTime / dbSystemTime;
     
                // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors
                dbIdleTime = 100.0 - dbIdleTime * 100.0 / (double)SysBaseInfo.bKeNumberProcessors + 0.5;
     
                printf("\b\b\b\b%3d%%",(UINT)dbIdleTime);
           }
     
            // store new CPU's idle and system time
            liOldIdleTime = SysPerfInfo.liIdleTime;
            liOldSystemTime = SysTimeInfo.liKeSystemTime;
     
            // wait one second
            Sleep(1000);
        } printf("\n");
    }
    voilà @++
    sly

  4. #4
    Membre actif

    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    472
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Septembre 2002
    Messages : 472
    Points : 262
    Points
    262
    Par défaut yop
    Salut,
    Merci,
    Ca peut être utile!
    Bonne Journée,
    MaTHieU_
    Embarcadero RAD Studio XE / Microsoft Windows 7 Édition Intégrale (64 bits)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 20/06/2011, 17h22
  2. Comment récupérer une image de fond en utilisant Infomaniak
    Par Aikoo dans le forum Autres hébergeurs
    Réponses: 0
    Dernier message: 15/04/2009, 14h00
  3. [MooTools] Request,comment récupérer le contenu pour l'utiliser dans le script ?
    Par dawadam dans le forum Bibliothèques & Frameworks
    Réponses: 1
    Dernier message: 09/07/2008, 23h22
  4. [CKEditor] Utilisation : comment récupérer le contenu de ma saisie ?
    Par MasterChief78 dans le forum Bibliothèques & Frameworks
    Réponses: 7
    Dernier message: 13/04/2007, 17h53

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo