8245042: Improve scalability of reading Windows Performance counters via PDH when using the Process object

Reviewed-by: dcubed, egahlin
This commit is contained in:
Markus Grönlund 2020-05-20 12:06:05 +02:00
parent 8c7fac8a2d
commit 0d5f6548a9
3 changed files with 702 additions and 586 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -37,6 +37,7 @@ typedef PDH_STATUS (WINAPI *PdhEnumObjectItems_Fn)(LPCTSTR, LPCTSTR, LPCTSTR, LP
typedef PDH_STATUS (WINAPI *PdhRemoveCounter_Fn)(HCOUNTER);
typedef PDH_STATUS (WINAPI *PdhLookupPerfNameByIndex_Fn)(LPCSTR, DWORD, LPSTR, LPDWORD);
typedef PDH_STATUS (WINAPI *PdhMakeCounterPath_Fn)(PDH_COUNTER_PATH_ELEMENTS*, LPTSTR, LPDWORD, DWORD);
typedef PDH_STATUS (WINAPI *PdhExpandWildCardPath_Fn)(LPCSTR, LPCSTR, PZZSTR, LPDWORD, DWORD);
PdhAddCounter_Fn PdhDll::_PdhAddCounter = NULL;
PdhOpenQuery_Fn PdhDll::_PdhOpenQuery = NULL;
@ -47,6 +48,7 @@ PdhEnumObjectItems_Fn PdhDll::_PdhEnumObjectItems = NULL;
PdhRemoveCounter_Fn PdhDll::_PdhRemoveCounter = NULL;
PdhLookupPerfNameByIndex_Fn PdhDll::_PdhLookupPerfNameByIndex = NULL;
PdhMakeCounterPath_Fn PdhDll::_PdhMakeCounterPath = NULL;
PdhExpandWildCardPath_Fn PdhDll::_PdhExpandWildCardPath = NULL;
LONG PdhDll::_critical_section = 0;
LONG PdhDll::_initialized = 0;
@ -68,6 +70,7 @@ void PdhDll::initialize(void) {
_PdhRemoveCounter = (PdhRemoveCounter_Fn)::GetProcAddress(_hModule, "PdhRemoveCounter");
_PdhLookupPerfNameByIndex = (PdhLookupPerfNameByIndex_Fn)::GetProcAddress(_hModule, "PdhLookupPerfNameByIndexA");
_PdhMakeCounterPath = (PdhMakeCounterPath_Fn)::GetProcAddress(_hModule, "PdhMakeCounterPathA");
_PdhExpandWildCardPath = (PdhExpandWildCardPath_Fn)::GetProcAddress(_hModule, "PdhExpandWildCardPathA");
InterlockedExchange(&_initialized, 1);
}
@ -88,6 +91,7 @@ bool PdhDll::PdhDetach(void) {
_PdhRemoveCounter = NULL;
_PdhLookupPerfNameByIndex = NULL;
_PdhMakeCounterPath = NULL;
_PdhExpandWildCardPath = NULL;
InterlockedExchange(&_initialized, 0);
}
}
@ -109,7 +113,7 @@ bool PdhDll::PdhAttach(void) {
&& _PdhCloseQuery != NULL && PdhCollectQueryData != NULL
&& _PdhGetFormattedCounterValue != NULL && _PdhEnumObjectItems != NULL
&& _PdhRemoveCounter != NULL && PdhLookupPerfNameByIndex != NULL
&& _PdhMakeCounterPath != NULL);
&& _PdhMakeCounterPath != NULL && _PdhExpandWildCardPath != NULL);
}
PDH_STATUS PdhDll::PdhAddCounter(HQUERY hQuery, LPCSTR szFullCounterPath, DWORD dwUserData, HCOUNTER* phCounter) {
@ -160,6 +164,11 @@ PDH_STATUS PdhDll::PdhMakeCounterPath(PDH_COUNTER_PATH_ELEMENTS* pCounterPathEle
return _PdhMakeCounterPath(pCounterPathElements, szFullPathBuffer, pcchBufferSize, dwFlags);
}
PDH_STATUS PdhDll::PdhExpandWildCardPath(LPCSTR szDataSource, LPCSTR szWildCardPath, PZZSTR mszExpandedPathList, LPDWORD pcchPathListLength, DWORD dwFlags) {
assert(_initialized && PdhExpandWildCardPath != NULL, "PdhAvailable() not yet called");
return _PdhExpandWildCardPath(szDataSource, szWildCardPath, mszExpandedPathList, pcchPathListLength, dwFlags);
}
bool PdhDll::PdhStatusFail(PDH_STATUS pdhStat) {
return pdhStat != ERROR_SUCCESS && pdhStat != PDH_MORE_DATA;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -45,6 +45,7 @@ class PdhDll: public AllStatic {
static PDH_STATUS (WINAPI *_PdhRemoveCounter)(HCOUNTER);
static PDH_STATUS (WINAPI *_PdhLookupPerfNameByIndex)(LPCSTR, DWORD, LPSTR, LPDWORD);
static PDH_STATUS (WINAPI *_PdhMakeCounterPath)(PPDH_COUNTER_PATH_ELEMENTS, LPTSTR, LPDWORD, DWORD);
static PDH_STATUS (WINAPI *_PdhExpandWildCardPath)(LPCSTR, LPCSTR, PZZSTR, LPDWORD, DWORD);
public:
static PDH_STATUS PdhAddCounter(HQUERY, LPCSTR, DWORD, HCOUNTER*);
@ -56,6 +57,7 @@ class PdhDll: public AllStatic {
static PDH_STATUS PdhRemoveCounter(HCOUNTER);
static PDH_STATUS PdhLookupPerfNameByIndex(LPCSTR, DWORD, LPSTR, LPDWORD);
static PDH_STATUS PdhMakeCounterPath(PPDH_COUNTER_PATH_ELEMENTS, LPTSTR, LPDWORD, DWORD);
static PDH_STATUS PdhExpandWildCardPath(LPCSTR, LPCSTR, PZZSTR, LPDWORD, DWORD);
static bool PdhStatusFail(PDH_STATUS pdhStat);
static bool PdhAttach();
static bool PdhDetach();