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. How do I get the system performance

How do I get the system performance

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabasebusinessjsonperformance
1 Posts 1 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.
  • B Offline
    B Offline
    Bill Wilson
    wrote on last edited by
    #1

    I have a need to know "how busy" a system is on a regular basis. My program launches worker threads in response to requests from client programs. One of the requirements is that the execution of these asynchronous functions do not adversly effect interactive users on the same system. To do this, I check the system load before launching a worker thread. If it is "too high" my program waits to launch the thread. This application must run on NT 4 and W2K. I have tried three differnt approaches: 1. My first attempt was to use the WMI provider Win32_Processors and the LoadPercentage. This is advertised as being the average system load over the last 1 second. The problem is that it appears to wait for the second before returning a result! (see earlier post WMI Query too slow if you want the coee). 2. My second attempt is to use the perf lib api. I can't seem to get this to work properly, however. 3. My best solution so far (ugly as it is) is to have the WMI query running continuously on a thead. Sample the result whenever I need it. The frequency of the requests is in the 10 miilisecond range. Here is some code I got of the internet that attempts to implement #2. It runs ok, but gets an error as explained below. If I could get this to work it would solve all my problems and avoid using the dreaded option 3 (chich does actually work). Or... is there a better way to do this I haven't thought of yet. #include "stdafx.h" #include #include "CPUUsage.h" #pragma comment(lib, "pdh") //#include "winerror.h" CCPUUsage::CCPUUsage(LONG nMinTicksBetweenSamples) { m_nMinTicksBetweenSamples = nMinTicksBetweenSamples; m_msLastTick = GetTickCount(); PDH_STATUS pdhs = PdhOpenQuery(NULL, 0, &m_hQuery); pdhs = PdhAddCounter(m_hQuery, TEXT("\\Processor(_Total)\\% processor time"), 0, &m_hCounter); } CCPUUsage::~CCPUUsage() { PdhCloseQuery(m_hQuery); } int CCPUUsage::GetUsage(PBOOL pfNewSample ) { BOOL fNewSample; if (pfNewSample == NULL) pfNewSample = &fNewSample; *pfNewSample = FALSE; DWORD msCurrentTick = GetTickCount(); DWORD msLastTick = m_msLastTick; if (msCurrentTick < msLastTick) { // Wrap around, always sample *pfNewSample = TRUE; } else { if ((msLastTick + m_nMinTicksBetweenSamples) < msCurrentTick) { // It's been long since the last sample, get a new sample *pfNewSample = TRUE; } } if (*pfNewSample) { if ((DWORD) Interlocke

    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