1 /*
2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  *
23  */
24 
25 #ifndef OS_WINDOWS_PDH_INTERFACE_HPP
26 #define OS_WINDOWS_PDH_INTERFACE_HPP
27 
28 #include "memory/allocation.hpp"
29 #include <pdh.h>
30 #include <pdhmsg.h>
31 
32 class PdhDll: public AllStatic {
33  private:
34   static LONG       _pdh_reference_count;
35   static LONG       _critical_section;
36   static LONG       _initialized;
37   static HMODULE    _hModule;
38   static void       initialize();
39   static PDH_STATUS (WINAPI *_PdhAddCounter)(HQUERY, LPCSTR, DWORD, HCOUNTER*);
40   static PDH_STATUS (WINAPI *_PdhOpenQuery)(LPCWSTR, DWORD, HQUERY*);
41   static DWORD      (WINAPI *_PdhCloseQuery)(HQUERY);
42   static PDH_STATUS (WINAPI *_PdhCollectQueryData)(HQUERY);
43   static DWORD      (WINAPI *_PdhGetFormattedCounterValue)(HCOUNTER, DWORD, LPDWORD, PPDH_FMT_COUNTERVALUE);
44   static PDH_STATUS (WINAPI *_PdhEnumObjectItems)(LPCTSTR, LPCTSTR, LPCTSTR, LPTSTR, LPDWORD, LPTSTR, LPDWORD, DWORD, DWORD);
45   static PDH_STATUS (WINAPI *_PdhRemoveCounter)(HCOUNTER);
46   static PDH_STATUS (WINAPI *_PdhLookupPerfNameByIndex)(LPCSTR, DWORD, LPSTR, LPDWORD);
47   static PDH_STATUS (WINAPI *_PdhMakeCounterPath)(PPDH_COUNTER_PATH_ELEMENTS, LPTSTR, LPDWORD, DWORD);
48 
49  public:
50   static PDH_STATUS PdhAddCounter(HQUERY, LPCSTR, DWORD, HCOUNTER*);
51   static PDH_STATUS PdhOpenQuery(LPCWSTR, DWORD, HQUERY*);
52   static DWORD      PdhCloseQuery(HQUERY);
53   static PDH_STATUS PdhCollectQueryData(HQUERY);
54   static DWORD      PdhGetFormattedCounterValue(HCOUNTER, DWORD, LPDWORD, PPDH_FMT_COUNTERVALUE);
55   static PDH_STATUS PdhEnumObjectItems(LPCTSTR, LPCTSTR, LPCTSTR, LPTSTR, LPDWORD, LPTSTR, LPDWORD, DWORD, DWORD);
56   static PDH_STATUS PdhRemoveCounter(HCOUNTER);
57   static PDH_STATUS PdhLookupPerfNameByIndex(LPCSTR, DWORD, LPSTR, LPDWORD);
58   static PDH_STATUS PdhMakeCounterPath(PPDH_COUNTER_PATH_ELEMENTS, LPTSTR, LPDWORD, DWORD);
59   static bool       PdhStatusFail(PDH_STATUS pdhStat);
60   static bool       PdhAttach();
61   static bool       PdhDetach();
62 };
63 
64 #endif // OS_WINDOWS_PDH_INTERFACE_HPP
65