From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26117 invoked by alias); 12 Mar 2019 16:10:05 -0000 Mailing-List: contact cygwin-cvs-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-cvs-owner@cygwin.com Received: (qmail 26075 invoked by uid 9078); 12 Mar 2019 16:10:05 -0000 Date: Tue, 12 Mar 2019 16:10:00 -0000 Message-ID: <20190312161005.26073.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: loadavg: improve debugging of load_init X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 673a3daa84c33bf95833237e35791c773b25bcd5 X-Git-Newrev: de7f13aa9acec022ad1e4b3f929d4dc982ddf60b X-SW-Source: 2019-q1/txt/msg00229.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=de7f13aa9acec022ad1e4b3f929d4dc982ddf60b commit de7f13aa9acec022ad1e4b3f929d4dc982ddf60b Author: Corinna Vinschen Date: Tue Mar 12 17:09:42 2019 +0100 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 Diff: --- winsup/cygwin/autoload.cc | 4 ++-- winsup/cygwin/loadavg.cc | 40 +++++++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index 056fac7..c4d9161 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -755,8 +755,8 @@ LoadDLLfunc (WSASocketW, 24, ws2_32) // LoadDLLfunc (WSAStartup, 8, ws2_32) LoadDLLfunc (WSAWaitForMultipleEvents, 20, ws2_32) -LoadDLLfunc (PdhAddEnglishCounterA, 16, pdh) +LoadDLLfunc (PdhAddEnglishCounterW, 16, pdh) LoadDLLfunc (PdhCollectQueryData, 4, pdh) LoadDLLfunc (PdhGetFormattedCounterValue, 16, pdh) -LoadDLLfunc (PdhOpenQueryA, 12, pdh) +LoadDLLfunc (PdhOpenQueryW, 12, pdh) } diff --git a/winsup/cygwin/loadavg.cc b/winsup/cygwin/loadavg.cc index bef80e1..127591a 100644 --- a/winsup/cygwin/loadavg.cc +++ b/winsup/cygwin/loadavg.cc @@ -39,14 +39,7 @@ #include #include #include - -/* Prototype for PdhAddEnglishCounterA in pdh.h under _WIN32_WINNT >= 0x0600 is - missing WINAPI */ -#undef _WIN32_WINNT #include -extern "C" -PDH_FUNCTION PdhAddEnglishCounterA(PDH_HQUERY hQuery, LPCSTR szFullCounterPath, - DWORD_PTR dwUserData, PDH_HCOUNTER *phCounter); static PDH_HQUERY query; static PDH_HCOUNTER counter1; @@ -61,14 +54,31 @@ static bool load_init (void) if (!tried) { tried = true; - if (!((PdhOpenQueryA (NULL, 0, &query) == ERROR_SUCCESS) && - (PdhAddEnglishCounterA (query, "\\Processor(_Total)\\% Processor Time", - 0, &counter1) == ERROR_SUCCESS) && - (PdhAddEnglishCounterA (query, "\\System\\Processor Queue Length", - 0, &counter2) == ERROR_SUCCESS))) { - debug_printf("loadavg PDH initialization failed\n"); - return false; - } + PDH_STATUS status; + + status = PdhOpenQueryW (NULL, 0, &query); + if (status != STATUS_SUCCESS) + { + debug_printf ("PdhOpenQueryW, status %y", status); + 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"); if (!mutex) {