Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. cpu performance

cpu performance

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hph
    wrote on last edited by
    #1

    hello, i need to know how to determine the total cpu usage expressed in percent. Is there any function which can provide this value ? Please help me it's urgent. Thanks in advance!

    D B 3 Replies Last reply
    0
    • H hph

      hello, i need to know how to determine the total cpu usage expressed in percent. Is there any function which can provide this value ? Please help me it's urgent. Thanks in advance!

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      See my response here.


      "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

      1 Reply Last reply
      0
      • H hph

        hello, i need to know how to determine the total cpu usage expressed in percent. Is there any function which can provide this value ? Please help me it's urgent. Thanks in advance!

        B Offline
        B Offline
        bikram singh
        wrote on last edited by
        #3

        On Win9x, i think the HKEY_DYN_DATA registry key provides some performance data, but im not sure if the CPU's included.. On NT/XP/2000, use performance counters:

        HQUERY hQuery;
        HCOUNTER hCounter;

        if(ERROR_SUCCESS == PdhOpenQuery(0, 0, &hQuery))
        {
        if(ERROR_SUCCESS == PdhAddCounter (hQuery,TEXT("\\Processor(0)\\% Processor Time"),0,&hCounter))
        {
        int i = 0;
        while(i < 5)
        {
        ++i;
        if(ERROR_SUCCESS == PdhCollectQueryData(hQuery))
        {
        PDH_FMT_COUNTERVALUE val;
        if(ERROR_SUCCESS == PdhGetFormattedCounterValue(hCounter,PDH_FMT_LONG|PDH_FMT_NOSCALE,0, &val))
        {
        printf("\nCPU is at %d %%",val.longValue);
        }
        }
        Sleep(500); //wait for some time(not absolutely needed though, but better to wait some time atleast!)
        }
        PdhRemoveCounter(hCounter);
        }
        PdhCloseQuery(hQuery);
        }

        Bikram Singh

        1 Reply Last reply
        0
        • H hph

          hello, i need to know how to determine the total cpu usage expressed in percent. Is there any function which can provide this value ? Please help me it's urgent. Thanks in advance!

          B Offline
          B Offline
          bikram singh
          wrote on last edited by
          #4

          HQUERY hQuery;
          HCOUNTER hCounter;

          if(ERROR_SUCCESS == PdhOpenQuery(0, 0, &hQuery))
          {
          if(ERROR_SUCCESS == PdhAddCounter (hQuery,TEXT("\\Processor(0)\\% Processor Time"),0,&hCounter))
          {
          int i = 0;
          while(i < 5)
          {
          ++i;
          if(ERROR_SUCCESS == PdhCollectQueryData(hQuery))
          {
          PDH_FMT_COUNTERVALUE val;
          if(ERROR_SUCCESS == PdhGetFormattedCounterValue(hCounter,PDH_FMT_LONG|PDH_FMT_NOSCALE,0, &val))
          {
          printf("\nCPU is at %d %%",val.longValue);
          }
          }
          Sleep(500); //wait for some time(not absolutely needed though, but better to wait some time atleast!)
          }
          PdhRemoveCounter(hCounter);
          }
          PdhCloseQuery(hQuery);
          }

          Bikram Singh

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups