Cygwin: loadavg: improve debugging of load_init

When logging in via ssh with an unprivileged account,
PdhAddEnglishCounter returns with status 0x800007D0,
PDH_CSTATUS_NO_MACHINE.  We didn't find any workaround
but the changes to improve debugging output may help
in future.  Using UNICODE instead of ANSI functions is
a result of trying to fix this problem.

Also drop the prototype workaround for PdhAddEnglishCounterA.
It's not required anymore since Mingw-w64's pdh.h catched up.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2019-03-12 17:09:42 +01:00
parent 673a3daa84
commit de7f13aa9a
2 changed files with 27 additions and 17 deletions

View File

@ -755,8 +755,8 @@ LoadDLLfunc (WSASocketW, 24, ws2_32)
// LoadDLLfunc (WSAStartup, 8, ws2_32) // LoadDLLfunc (WSAStartup, 8, ws2_32)
LoadDLLfunc (WSAWaitForMultipleEvents, 20, ws2_32) LoadDLLfunc (WSAWaitForMultipleEvents, 20, ws2_32)
LoadDLLfunc (PdhAddEnglishCounterA, 16, pdh) LoadDLLfunc (PdhAddEnglishCounterW, 16, pdh)
LoadDLLfunc (PdhCollectQueryData, 4, pdh) LoadDLLfunc (PdhCollectQueryData, 4, pdh)
LoadDLLfunc (PdhGetFormattedCounterValue, 16, pdh) LoadDLLfunc (PdhGetFormattedCounterValue, 16, pdh)
LoadDLLfunc (PdhOpenQueryA, 12, pdh) LoadDLLfunc (PdhOpenQueryW, 12, pdh)
} }

View File

@ -39,14 +39,7 @@
#include <math.h> #include <math.h>
#include <time.h> #include <time.h>
#include <sys/strace.h> #include <sys/strace.h>
/* Prototype for PdhAddEnglishCounterA in pdh.h under _WIN32_WINNT >= 0x0600 is
missing WINAPI */
#undef _WIN32_WINNT
#include <pdh.h> #include <pdh.h>
extern "C"
PDH_FUNCTION PdhAddEnglishCounterA(PDH_HQUERY hQuery, LPCSTR szFullCounterPath,
DWORD_PTR dwUserData, PDH_HCOUNTER *phCounter);
static PDH_HQUERY query; static PDH_HQUERY query;
static PDH_HCOUNTER counter1; static PDH_HCOUNTER counter1;
@ -61,14 +54,31 @@ static bool load_init (void)
if (!tried) { if (!tried) {
tried = true; tried = true;
if (!((PdhOpenQueryA (NULL, 0, &query) == ERROR_SUCCESS) && PDH_STATUS status;
(PdhAddEnglishCounterA (query, "\\Processor(_Total)\\% Processor Time",
0, &counter1) == ERROR_SUCCESS) && status = PdhOpenQueryW (NULL, 0, &query);
(PdhAddEnglishCounterA (query, "\\System\\Processor Queue Length", if (status != STATUS_SUCCESS)
0, &counter2) == ERROR_SUCCESS))) { {
debug_printf("loadavg PDH initialization failed\n"); debug_printf ("PdhOpenQueryW, status %y", status);
return false; return false;
} }
status = PdhAddEnglishCounterW (query,
L"\\Processor(_Total)\\% Processor Time",
0, &counter1);
if (status != STATUS_SUCCESS)
{
debug_printf ("PdhAddEnglishCounterW(time), status %y", status);
return false;
}
status = PdhAddEnglishCounterW (query,
L"\\System\\Processor Queue Length",
0, &counter2);
if (status != STATUS_SUCCESS)
{
debug_printf ("PdhAddEnglishCounterW(queue length), status %y", status);
return false;
}
mutex = CreateMutex(&sec_all_nih, FALSE, "cyg.loadavg.mutex"); mutex = CreateMutex(&sec_all_nih, FALSE, "cyg.loadavg.mutex");
if (!mutex) { if (!mutex) {