Request for test by users seeing 0.00 load average in spite of a busy system

Mark Geisert mark@maxrnd.com
Wed Oct 2 06:34:08 GMT 2024


Hi folks,
I may have a handle on why you're seeing 0.00 load averages. Would you 
kindly compile the attached program, run it, and post its results along 
with which version of Windows you are running?
For example,
     gcc -Wall -ggdb -o test test.c -lpdh
     ./test
Thanks for your help,

..mark
-------------- next part --------------
//	test.c
//	See if PDH counters needed for Cygwin load averages are present
//	2024/10/01 Mark Geisert <mark@maxrnd.com>
//
#include <stdio.h>

#define _WIN32_WINNT 0x0600
#include <pdh.h>

PDH_HQUERY query;
PDH_HCOUNTER counter1;
PDH_HCOUNTER counter2;
PDH_HCOUNTER counter3;
#define c1name L"\\Processor(_Total)\\% Processor Time"
#define c2name L"\\Processor Information(_Total)\\% Processor Time"
#define c3name L"\\System\\Processor Queue Length"

char *
pdh_status (PDH_STATUS err)
{
  static FILE *f = NULL;
  static char  buf[132];
  static char  hexcode[32];
         char  line[132];
         char  prefix[80];
         char  middle[80];
  static char  suffix[80];

  snprintf (hexcode, sizeof hexcode, "0x%X", err);
  if (strstr (suffix, hexcode))
    goto done; /* same as last time called */
  if (f)
    (void) fseek (f, 0, SEEK_SET);
  else
    f = fopen ("/usr/include/w32api/pdhmsg.h", "r");
  if (!f)
    goto bail;
  while (!feof (f)) {
    (void) fgets (line, (sizeof line) - 1, f);
    if (strncmp (line, "#define PDH_", 12))
      continue;
    if (!strstr (line, hexcode))
      continue;
    int num = sscanf (line, "%s %s %s", prefix, middle, suffix);
    if (num != 3)
      continue;
    snprintf (buf, sizeof buf, "returns %s", middle);
    goto done;
  }
bail:
  snprintf (buf, sizeof buf, "returns %s", hexcode);
done:
  return buf;
}

void
load_init (void)
{
  PDH_STATUS ret = PdhOpenQueryW (NULL, 0, &query);
  fprintf (stderr, "PdhOpenQueryW           %s\n", pdh_status (ret));
  ret = PdhAddEnglishCounterW (query, c1name, 0, &counter1);
  fprintf (stderr, "PdhAddEnglishCounterW#1 %s\n", pdh_status (ret));
  ret = PdhAddEnglishCounterW (query, c2name, 0, &counter2);
  fprintf (stderr, "PdhAddEnglishCounterW#2 %s\n", pdh_status (ret));
  ret = PdhAddEnglishCounterW (query, c3name, 0, &counter3);
  fprintf (stderr, "PdhAddEnglishCounterW#3 %s\n", pdh_status (ret));
}

int
main (int argc, char **argv)
{
  load_init ();
  return 0;
}


More information about the Cygwin mailing list