win32-pdh 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/win32/pdh/constants.rb +286 -0
- data/lib/win32/pdh/counter.rb +146 -0
- data/lib/win32/pdh/query.rb +68 -0
- data/lib/win32/pdh.rb +232 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5243c26326dadf2f4c5f3cbdb3bfab9a531a1992bbc3b3bc438c8169add75603
|
4
|
+
data.tar.gz: 599302bb34ec10951fdc9c2f260378298dff79b745575b8ac28325cbc2892997
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecd4510ff8a655d541b6af78b2a6a2b7f0d9487b1916b232479434de13fd31dbe3881b766b0f3a1e681a054decfe9aa4f1b18e5760b1c852926acbb14a59f941
|
7
|
+
data.tar.gz: 0307ddac4aebe77742b783066afb96064dd7c462637136ae27159efc968be98da0ca65bc2fcdd2f454665961d269597780cbd961b6c1f7c39fde027da1e5fa97
|
@@ -0,0 +1,286 @@
|
|
1
|
+
module Win32
|
2
|
+
module Pdh
|
3
|
+
module Constants
|
4
|
+
|
5
|
+
PDH_FMT_LONG = 0x00000100
|
6
|
+
PDH_FMT_DOUBLE = 0x00000200
|
7
|
+
PDH_FMT_LARGE = 0x00000400
|
8
|
+
PDH_FMT_NOSCALE = 0x00001000
|
9
|
+
PDH_FMT_1000 = 0x00002000
|
10
|
+
PDH_FMT_NOCAP100 = 0x00008000
|
11
|
+
|
12
|
+
PDH_NOEXPANDCOUNTERS = 0x00000001
|
13
|
+
PDH_NOEXPANDINSTANCES = 0x00000002
|
14
|
+
|
15
|
+
PDH_CSTATUS_VALID_DATA = 0x00000000
|
16
|
+
PDH_CSTATUS_NEW_DATA = 0x00000001
|
17
|
+
PDH_CSTATUS_NO_MACHINE = 0x800007D0
|
18
|
+
PDH_CSTATUS_NO_INSTANCE = 0x800007D1
|
19
|
+
PDH_MORE_DATA = 0x800007D2
|
20
|
+
PDH_CSTATUS_ITEM_NOT_VALIDATED = 0x800007D3
|
21
|
+
PDH_RETRY = 0x800007D4
|
22
|
+
PDH_NO_DATA = 0x800007D5
|
23
|
+
PDH_CALC_NEGATIVE_DENOMINATOR = 0x800007D6
|
24
|
+
PDH_CALC_NEGATIVE_TIMEBASE = 0x800007D7
|
25
|
+
PDH_CALC_NEGATIVE_VALUE = 0x800007D8
|
26
|
+
PDH_DIALOG_CANCELLED = 0x800007D9
|
27
|
+
PDH_END_OF_LOG_FILE = 0x800007DA
|
28
|
+
PDH_ASYNC_QUERY_TIMEOUT = 0x800007DB
|
29
|
+
PDH_CANNOT_SET_DEFAULT_REALTIME_DATASOURCE = 0x800007DC
|
30
|
+
PDH_CSTATUS_NO_OBJECT = 0xC0000BB8
|
31
|
+
PDH_CSTATUS_NO_COUNTER = 0xC0000BB9
|
32
|
+
PDH_CSTATUS_INVALID_DATA = 0xC0000BBA
|
33
|
+
PDH_MEMORY_ALLOCATION_FAILURE = 0xC0000BBB
|
34
|
+
PDH_INVALID_HANDLE = 0xC0000BBC
|
35
|
+
PDH_INVALID_ARGUMENT = 0xC0000BBD
|
36
|
+
PDH_FUNCTION_NOT_FOUND = 0xC0000BBE
|
37
|
+
PDH_CSTATUS_NO_COUNTERNAME = 0xC0000BBF
|
38
|
+
PDH_CSTATUS_BAD_COUNTERNAME = 0xC0000BC0
|
39
|
+
PDH_INVALID_BUFFER = 0xC0000BC1
|
40
|
+
PDH_INSUFFICIENT_BUFFER = 0xC0000BC2
|
41
|
+
PDH_CANNOT_CONNECT_MACHINE = 0xC0000BC3
|
42
|
+
PDH_INVALID_PATH = 0xC0000BC4
|
43
|
+
PDH_INVALID_INSTANCE = 0xC0000BC5
|
44
|
+
PDH_INVALID_DATA = 0xC0000BC6
|
45
|
+
PDH_NO_DIALOG_DATA = 0xC0000BC7
|
46
|
+
PDH_CANNOT_READ_NAME_STRINGS = 0xC0000BC8
|
47
|
+
PDH_LOG_FILE_CREATE_ERROR = 0xC0000BC9
|
48
|
+
PDH_LOG_FILE_OPEN_ERROR = 0xC0000BCA
|
49
|
+
PDH_LOG_TYPE_NOT_FOUND = 0xC0000BCB
|
50
|
+
PDH_NO_MORE_DATA = 0xC0000BCC
|
51
|
+
PDH_ENTRY_NOT_IN_LOG_FILE = 0xC0000BCD
|
52
|
+
PDH_DATA_SOURCE_IS_LOG_FILE = 0xC0000BCE
|
53
|
+
PDH_DATA_SOURCE_IS_REAL_TIME = 0xC0000BCF
|
54
|
+
PDH_UNABLE_READ_LOG_HEADER = 0xC0000BD0
|
55
|
+
PDH_FILE_NOT_FOUND = 0xC0000BD1
|
56
|
+
PDH_FILE_ALREADY_EXISTS = 0xC0000BD2
|
57
|
+
PDH_NOT_IMPLEMENTED = 0xC0000BD3
|
58
|
+
PDH_STRING_NOT_FOUND = 0xC0000BD4
|
59
|
+
PDH_UNABLE_MAP_NAME_FILES = 0x80000BD5
|
60
|
+
PDH_UNKNOWN_LOG_FORMAT = 0xC0000BD6
|
61
|
+
PDH_UNKNOWN_LOGSVC_COMMAND = 0xC0000BD7
|
62
|
+
PDH_LOGSVC_QUERY_NOT_FOUND = 0xC0000BD8
|
63
|
+
PDH_LOGSVC_NOT_OPENED = 0xC0000BD9
|
64
|
+
PDH_WBEM_ERROR = 0xC0000BDA
|
65
|
+
PDH_ACCESS_DENIED = 0xC0000BDB
|
66
|
+
PDH_LOG_FILE_TOO_SMALL = 0xC0000BDC
|
67
|
+
PDH_INVALID_DATASOURCE = 0xC0000BDD
|
68
|
+
PDH_INVALID_SQLDB = 0xC0000BDE
|
69
|
+
PDH_NO_COUNTERS = 0xC0000BDF
|
70
|
+
PDH_SQL_ALLOC_FAILED = 0xC0000BE0
|
71
|
+
PDH_SQL_ALLOCCON_FAILED = 0xC0000BE1
|
72
|
+
PDH_SQL_EXEC_DIRECT_FAILED = 0xC0000BE2
|
73
|
+
PDH_SQL_FETCH_FAILED = 0xC0000BE3
|
74
|
+
PDH_SQL_ROWCOUNT_FAILED = 0xC0000BE4
|
75
|
+
PDH_SQL_MORE_RESULTS_FAILED = 0xC0000BE5
|
76
|
+
PDH_SQL_CONNECT_FAILED = 0xC0000BE6
|
77
|
+
PDH_SQL_BIND_FAILED = 0xC0000BE7
|
78
|
+
PDH_CANNOT_CONNECT_WMI_SERVER = 0xC0000BE8
|
79
|
+
PDH_PLA_COLLECTION_ALREADY_RUNNING = 0xC0000BE9
|
80
|
+
PDH_PLA_ERROR_SCHEDULE_OVERLAP = 0xC0000BEA
|
81
|
+
PDH_PLA_COLLECTION_NOT_FOUND = 0xC0000BEB
|
82
|
+
PDH_PLA_ERROR_SCHEDULE_ELAPSED = 0xC0000BEC
|
83
|
+
PDH_PLA_ERROR_NOSTART = 0xC0000BED
|
84
|
+
PDH_PLA_ERROR_ALREADY_EXISTS = 0xC0000BEE
|
85
|
+
PDH_PLA_ERROR_TYPE_MISMATCH = 0xC0000BEF
|
86
|
+
PDH_PLA_ERROR_FILEPATH = 0xC0000BF0
|
87
|
+
PDH_PLA_SERVICE_ERROR = 0xC0000BF1
|
88
|
+
PDH_PLA_VALIDATION_ERROR = 0xC0000BF2
|
89
|
+
PDH_PLA_VALIDATION_WARNING = 0x80000BF3
|
90
|
+
PDH_PLA_ERROR_NAME_TOO_LONG = 0xC0000BF4
|
91
|
+
PDH_INVALID_SQL_LOG_FORMAT = 0xC0000BF5
|
92
|
+
PDH_COUNTER_ALREADY_IN_QUERY = 0xC0000BF6
|
93
|
+
PDH_BINARY_LOG_CORRUPT = 0xC0000BF7
|
94
|
+
PDH_LOG_SAMPLE_TOO_SMALL = 0xC0000BF8
|
95
|
+
PDH_OS_LATER_VERSION = 0xC0000BF9
|
96
|
+
PDH_OS_EARLIER_VERSION = 0xC0000BFA
|
97
|
+
PDH_INCORRECT_APPEND_TIME = 0xC0000BFB
|
98
|
+
PDH_UNMATCHED_APPEND_COUNTER = 0xC0000BFC
|
99
|
+
PDH_SQL_ALTER_DETAIL_FAILED = 0xC0000BFD
|
100
|
+
PDH_QUERY_PERF_DATA_TIMEOUT = 0xC0000BFE
|
101
|
+
PERF_DETAIL_NOVICE = 100
|
102
|
+
PERF_DETAIL_ADVANCED = 200
|
103
|
+
PERF_DETAIL_EXPERT = 300
|
104
|
+
PERF_DETAIL_WIZARD = 400
|
105
|
+
ERROR_SUCCESS = 0x00000000
|
106
|
+
|
107
|
+
NAMES = {
|
108
|
+
0x00000000 => 'PDH_CSTATUS_VALID_DATA'.freeze,
|
109
|
+
0x00000001 => 'PDH_CSTATUS_NEW_DATA'.freeze,
|
110
|
+
0x800007D0 => 'PDH_CSTATUS_NO_MACHINE'.freeze,
|
111
|
+
0x800007D1 => 'PDH_CSTATUS_NO_INSTANCE'.freeze,
|
112
|
+
0x800007D2 => 'PDH_MORE_DATA'.freeze,
|
113
|
+
0x800007D3 => 'PDH_CSTATUS_ITEM_NOT_VALIDATED'.freeze,
|
114
|
+
0x800007D4 => 'PDH_RETRY'.freeze,
|
115
|
+
0x800007D5 => 'PDH_NO_DATA'.freeze,
|
116
|
+
0x800007D6 => 'PDH_CALC_NEGATIVE_DENOMINATOR'.freeze,
|
117
|
+
0x800007D7 => 'PDH_CALC_NEGATIVE_TIMEBASE'.freeze,
|
118
|
+
0x800007D8 => 'PDH_CALC_NEGATIVE_VALUE'.freeze,
|
119
|
+
0x800007D9 => 'PDH_DIALOG_CANCELLED'.freeze,
|
120
|
+
0x800007DA => 'PDH_END_OF_LOG_FILE'.freeze,
|
121
|
+
0x800007DB => 'PDH_ASYNC_QUERY_TIMEOUT'.freeze,
|
122
|
+
0x800007DC => 'PDH_CANNOT_SET_DEFAULT_REALTIME_DATASOURCE'.freeze,
|
123
|
+
0xC0000BB8 => 'PDH_CSTATUS_NO_OBJECT'.freeze,
|
124
|
+
0xC0000BB9 => 'PDH_CSTATUS_NO_COUNTER'.freeze,
|
125
|
+
0xC0000BBA => 'PDH_CSTATUS_INVALID_DATA'.freeze,
|
126
|
+
0xC0000BBB => 'PDH_MEMORY_ALLOCATION_FAILURE'.freeze,
|
127
|
+
0xC0000BBC => 'PDH_INVALID_HANDLE'.freeze,
|
128
|
+
0xC0000BBD => 'PDH_INVALID_ARGUMENT'.freeze,
|
129
|
+
0xC0000BBE => 'PDH_FUNCTION_NOT_FOUND'.freeze,
|
130
|
+
0xC0000BBF => 'PDH_CSTATUS_NO_COUNTERNAME'.freeze,
|
131
|
+
0xC0000BC0 => 'PDH_CSTATUS_BAD_COUNTERNAME'.freeze,
|
132
|
+
0xC0000BC1 => 'PDH_INVALID_BUFFER'.freeze,
|
133
|
+
0xC0000BC2 => 'PDH_INSUFFICIENT_BUFFER'.freeze,
|
134
|
+
0xC0000BC3 => 'PDH_CANNOT_CONNECT_MACHINE'.freeze,
|
135
|
+
0xC0000BC4 => 'PDH_INVALID_PATH'.freeze,
|
136
|
+
0xC0000BC5 => 'PDH_INVALID_INSTANCE'.freeze,
|
137
|
+
0xC0000BC6 => 'PDH_INVALID_DATA'.freeze,
|
138
|
+
0xC0000BC7 => 'PDH_NO_DIALOG_DATA'.freeze,
|
139
|
+
0xC0000BC8 => 'PDH_CANNOT_READ_NAME_STRINGS'.freeze,
|
140
|
+
0xC0000BC9 => 'PDH_LOG_FILE_CREATE_ERROR'.freeze,
|
141
|
+
0xC0000BCA => 'PDH_LOG_FILE_OPEN_ERROR'.freeze,
|
142
|
+
0xC0000BCB => 'PDH_LOG_TYPE_NOT_FOUND'.freeze,
|
143
|
+
0xC0000BCC => 'PDH_NO_MORE_DATA'.freeze,
|
144
|
+
0xC0000BCD => 'PDH_ENTRY_NOT_IN_LOG_FILE'.freeze,
|
145
|
+
0xC0000BCE => 'PDH_DATA_SOURCE_IS_LOG_FILE'.freeze,
|
146
|
+
0xC0000BCF => 'PDH_DATA_SOURCE_IS_REAL_TIME'.freeze,
|
147
|
+
0xC0000BD0 => 'PDH_UNABLE_READ_LOG_HEADER'.freeze,
|
148
|
+
0xC0000BD1 => 'PDH_FILE_NOT_FOUND'.freeze,
|
149
|
+
0xC0000BD2 => 'PDH_FILE_ALREADY_EXISTS'.freeze,
|
150
|
+
0xC0000BD3 => 'PDH_NOT_IMPLEMENTED'.freeze,
|
151
|
+
0xC0000BD4 => 'PDH_STRING_NOT_FOUND'.freeze,
|
152
|
+
0x80000BD5 => 'PDH_UNABLE_MAP_NAME_FILES'.freeze,
|
153
|
+
0xC0000BD6 => 'PDH_UNKNOWN_LOG_FORMAT'.freeze,
|
154
|
+
0xC0000BD7 => 'PDH_UNKNOWN_LOGSVC_COMMAND'.freeze,
|
155
|
+
0xC0000BD8 => 'PDH_LOGSVC_QUERY_NOT_FOUND'.freeze,
|
156
|
+
0xC0000BD9 => 'PDH_LOGSVC_NOT_OPENED'.freeze,
|
157
|
+
0xC0000BDA => 'PDH_WBEM_ERROR'.freeze,
|
158
|
+
0xC0000BDB => 'PDH_ACCESS_DENIED'.freeze,
|
159
|
+
0xC0000BDC => 'PDH_LOG_FILE_TOO_SMALL'.freeze,
|
160
|
+
0xC0000BDD => 'PDH_INVALID_DATASOURCE'.freeze,
|
161
|
+
0xC0000BDE => 'PDH_INVALID_SQLDB'.freeze,
|
162
|
+
0xC0000BDF => 'PDH_NO_COUNTERS'.freeze,
|
163
|
+
0xC0000BE0 => 'PDH_SQL_ALLOC_FAILED'.freeze,
|
164
|
+
0xC0000BE1 => 'PDH_SQL_ALLOCCON_FAILED'.freeze,
|
165
|
+
0xC0000BE2 => 'PDH_SQL_EXEC_DIRECT_FAILED'.freeze,
|
166
|
+
0xC0000BE3 => 'PDH_SQL_FETCH_FAILED'.freeze,
|
167
|
+
0xC0000BE4 => 'PDH_SQL_ROWCOUNT_FAILED'.freeze,
|
168
|
+
0xC0000BE5 => 'PDH_SQL_MORE_RESULTS_FAILED'.freeze,
|
169
|
+
0xC0000BE6 => 'PDH_SQL_CONNECT_FAILED'.freeze,
|
170
|
+
0xC0000BE7 => 'PDH_SQL_BIND_FAILED'.freeze,
|
171
|
+
0xC0000BE8 => 'PDH_CANNOT_CONNECT_WMI_SERVER'.freeze,
|
172
|
+
0xC0000BE9 => 'PDH_PLA_COLLECTION_ALREADY_RUNNING'.freeze,
|
173
|
+
0xC0000BEA => 'PDH_PLA_ERROR_SCHEDULE_OVERLAP'.freeze,
|
174
|
+
0xC0000BEB => 'PDH_PLA_COLLECTION_NOT_FOUND'.freeze,
|
175
|
+
0xC0000BEC => 'PDH_PLA_ERROR_SCHEDULE_ELAPSED'.freeze,
|
176
|
+
0xC0000BED => 'PDH_PLA_ERROR_NOSTART'.freeze,
|
177
|
+
0xC0000BEE => 'PDH_PLA_ERROR_ALREADY_EXISTS'.freeze,
|
178
|
+
0xC0000BEF => 'PDH_PLA_ERROR_TYPE_MISMATCH'.freeze,
|
179
|
+
0xC0000BF0 => 'PDH_PLA_ERROR_FILEPATH'.freeze,
|
180
|
+
0xC0000BF1 => 'PDH_PLA_SERVICE_ERROR'.freeze,
|
181
|
+
0xC0000BF2 => 'PDH_PLA_VALIDATION_ERROR'.freeze,
|
182
|
+
0x80000BF3 => 'PDH_PLA_VALIDATION_WARNING'.freeze,
|
183
|
+
0xC0000BF4 => 'PDH_PLA_ERROR_NAME_TOO_LONG'.freeze,
|
184
|
+
0xC0000BF5 => 'PDH_INVALID_SQL_LOG_FORMAT'.freeze,
|
185
|
+
0xC0000BF6 => 'PDH_COUNTER_ALREADY_IN_QUERY'.freeze,
|
186
|
+
0xC0000BF7 => 'PDH_BINARY_LOG_CORRUPT'.freeze,
|
187
|
+
0xC0000BF8 => 'PDH_LOG_SAMPLE_TOO_SMALL'.freeze,
|
188
|
+
0xC0000BF9 => 'PDH_OS_LATER_VERSION'.freeze,
|
189
|
+
0xC0000BFA => 'PDH_OS_EARLIER_VERSION'.freeze,
|
190
|
+
0xC0000BFB => 'PDH_INCORRECT_APPEND_TIME'.freeze,
|
191
|
+
0xC0000BFC => 'PDH_UNMATCHED_APPEND_COUNTER'.freeze,
|
192
|
+
0xC0000BFD => 'PDH_SQL_ALTER_DETAIL_FAILED'.freeze,
|
193
|
+
0xC0000BFE => 'PDH_QUERY_PERF_DATA_TIMEOUT'.freeze,
|
194
|
+
}.freeze
|
195
|
+
|
196
|
+
MESSAGES = {
|
197
|
+
0x00000000 => 'The returned data is valid.'.freeze,
|
198
|
+
0x00000001 => 'The return data value is valid and different from the last sample.'.freeze,
|
199
|
+
0x800007D0 => 'Unable to connect to the specified computer, or the computer is offline.'.freeze,
|
200
|
+
0x800007D1 => 'The specified instance is not present.'.freeze,
|
201
|
+
0x800007D2 => 'There is more data to return than would fit in the supplied buffer. Allocate a larger buffer and call the function again.'.freeze,
|
202
|
+
0x800007D3 => 'The data item has been added to the query but has not been validated nor accessed. No other status information on this data item is available.'.freeze,
|
203
|
+
0x800007D4 => 'The selected operation should be retried.'.freeze,
|
204
|
+
0x800007D5 => 'No data to return.'.freeze,
|
205
|
+
0x800007D6 => 'A counter with a negative denominator value was detected.'.freeze,
|
206
|
+
0x800007D7 => 'A counter with a negative time base value was detected.'.freeze,
|
207
|
+
0x800007D8 => 'A counter with a negative value was detected.'.freeze,
|
208
|
+
0x800007D9 => 'The user canceled the dialog box.'.freeze,
|
209
|
+
0x800007DA => 'The end of the log file was reached.'.freeze,
|
210
|
+
0x800007DB => 'A time-out occurred while waiting for the asynchronous counter collection thread to end.'.freeze,
|
211
|
+
0x800007DC => 'Cannot change set default real-time data source. There are real-time query sessions collecting counter data.'.freeze,
|
212
|
+
0xC0000BB8 => 'The specified object is not found on the system.'.freeze,
|
213
|
+
0xC0000BB9 => 'The specified counter could not be found.'.freeze,
|
214
|
+
0xC0000BBA => 'The returned data is not valid.'.freeze,
|
215
|
+
0xC0000BBB => 'A PDH function could not allocate enough temporary memory to complete the operation. Close some applications or extend the page file and retry the function.'.freeze,
|
216
|
+
0xC0000BBC => 'The handle is not a valid PDH object.'.freeze,
|
217
|
+
0xC0000BBD => 'A required argument is missing or incorrect.'.freeze,
|
218
|
+
0xC0000BBE => 'Unable to find the specified function.'.freeze,
|
219
|
+
0xC0000BBF => 'No counter was specified.'.freeze,
|
220
|
+
0xC0000BC0 => 'Unable to parse the counter path. Check the format and syntax of the specified path.'.freeze,
|
221
|
+
0xC0000BC1 => 'The buffer passed by the caller is not valid.'.freeze,
|
222
|
+
0xC0000BC2 => 'The requested data is larger than the buffer supplied. Unable to return the requested data.'.freeze,
|
223
|
+
0xC0000BC3 => 'Unable to connect to the requested computer.'.freeze,
|
224
|
+
0xC0000BC4 => 'The specified counter path could not be interpreted.'.freeze,
|
225
|
+
0xC0000BC5 => 'The instance name could not be read from the specified counter path.'.freeze,
|
226
|
+
0xC0000BC6 => 'The data is not valid.'.freeze,
|
227
|
+
0xC0000BC7 => 'The dialog box data block was missing or not valid.'.freeze,
|
228
|
+
0xC0000BC8 => 'Unable to read the counter and/or help text from the specified computer.'.freeze,
|
229
|
+
0xC0000BC9 => 'Unable to create the specified log file.'.freeze,
|
230
|
+
0xC0000BCA => 'Unable to open the specified log file.'.freeze,
|
231
|
+
0xC0000BCB => 'The specified log file type has not been installed on this system.'.freeze,
|
232
|
+
0xC0000BCC => 'No more data is available.'.freeze,
|
233
|
+
0xC0000BCD => 'The specified record was not found in the log file.'.freeze,
|
234
|
+
0xC0000BCE => 'The specified data source is a log file.'.freeze,
|
235
|
+
0xC0000BCF => 'The specified data source is the current activity.'.freeze,
|
236
|
+
0xC0000BD0 => 'The log file header could not be read.'.freeze,
|
237
|
+
0xC0000BD1 => 'Unable to find the specified file.'.freeze,
|
238
|
+
0xC0000BD2 => 'There is already a file with the specified file name.'.freeze,
|
239
|
+
0xC0000BD3 => 'The function referenced has not been implemented.'.freeze,
|
240
|
+
0xC0000BD4 => 'Unable to find the specified string in the list of performance name and help text strings.'.freeze,
|
241
|
+
0x80000BD5 => 'Unable to map to the performance counter name data files. The data will be read from the registry and stored locally.'.freeze,
|
242
|
+
0xC0000BD6 => 'The format of the specified log file is not recognized by the PDH DLL.'.freeze,
|
243
|
+
0xC0000BD7 => 'The specified Log Service command value is not recognized.'.freeze,
|
244
|
+
0xC0000BD8 => 'The specified query from the Log Service could not be found or could not be opened.'.freeze,
|
245
|
+
0xC0000BD9 => 'The Performance Data Log Service key could not be opened. This may be due to insufficient privilege or because the service has not been installed.'.freeze,
|
246
|
+
0xC0000BDA => 'An error occurred while accessing the WBEM data store.'.freeze,
|
247
|
+
0xC0000BDB => 'Unable to access the desired computer or service. Check the permissions and authentication of the log service or the interactive user session against those on the computer or service being monitored.'.freeze,
|
248
|
+
0xC0000BDC => 'The maximum log file size specified is too small to log the selected counters. No data will be recorded in this log file. Specify a smaller set of counters to log or a larger file size and retry this call.'.freeze,
|
249
|
+
0xC0000BDD => 'Cannot connect to ODBC DataSource Name.'.freeze,
|
250
|
+
0xC0000BDE => 'SQL Database does not contain a valid set of tables for Perfmon.'.freeze,
|
251
|
+
0xC0000BDF => 'No counters were found for this Perfmon SQL Log Set.'.freeze,
|
252
|
+
0xC0000BE0 => 'Call to SQLAllocStmt failed with %1.'.freeze,
|
253
|
+
0xC0000BE1 => 'Call to SQLAllocConnect failed with %1.'.freeze,
|
254
|
+
0xC0000BE2 => 'Call to SQLExecDirect failed with %1.'.freeze,
|
255
|
+
0xC0000BE3 => 'Call to SQLFetch failed with %1.'.freeze,
|
256
|
+
0xC0000BE4 => 'Call to SQLRowCount failed with %1.'.freeze,
|
257
|
+
0xC0000BE5 => 'Call to SQLMoreResults failed with %1.'.freeze,
|
258
|
+
0xC0000BE6 => 'Call to SQLConnect failed with %1.'.freeze,
|
259
|
+
0xC0000BE7 => 'Call to SQLBindCol failed with %1.'.freeze,
|
260
|
+
0xC0000BE8 => 'Unable to connect to the WMI server on requested computer.'.freeze,
|
261
|
+
0xC0000BE9 => 'Collection "%1!s!" is already running.'.freeze,
|
262
|
+
0xC0000BEA => 'The specified start time is after the end time.'.freeze,
|
263
|
+
0xC0000BEB => 'Collection "%1!s!" does not exist.'.freeze,
|
264
|
+
0xC0000BEC => 'The specified end time has already elapsed.'.freeze,
|
265
|
+
0xC0000BED => 'Collection "%1!s!" did not start; check the application event log for any errors.'.freeze,
|
266
|
+
0xC0000BEE => 'Collection "%1!s!" already exists.'.freeze,
|
267
|
+
0xC0000BEF => 'There is a mismatch in the settings type.'.freeze,
|
268
|
+
0xC0000BF0 => 'The information specified does not resolve to a valid path name.'.freeze,
|
269
|
+
0xC0000BF1 => 'The "Performance Logs & Alerts" service did not respond.'.freeze,
|
270
|
+
0xC0000BF2 => 'The information passed is not valid.'.freeze,
|
271
|
+
0x80000BF3 => 'The information passed is not valid.'.freeze,
|
272
|
+
0xC0000BF4 => 'The name supplied is too long.'.freeze,
|
273
|
+
0xC0000BF5 => 'SQL log format is incorrect. Correct format is "SQL:<DSN-name>!<LogSet-Name>".'.freeze,
|
274
|
+
0xC0000BF6 => 'Performance counter in PdhAddCounter call has already been added in the performance query. This counter is ignored.'.freeze,
|
275
|
+
0xC0000BF7 => 'Unable to read counter information and data from input binary log files.'.freeze,
|
276
|
+
0xC0000BF8 => 'At least one of the input binary log files contain fewer than two data samples.'.freeze,
|
277
|
+
0xC0000BF9 => 'The version of the operating system on the computer named %1 is later than that on the local computer. This operation is not available from the local computer.'.freeze,
|
278
|
+
0xC0000BFA => '%1 supports %2 or later. Check the operating system version on the computer named %3.'.freeze,
|
279
|
+
0xC0000BFB => 'The output file must contain earlier data than the file to be appended.'.freeze,
|
280
|
+
0xC0000BFC => 'Both files must have identical counters in order to append.'.freeze,
|
281
|
+
0xC0000BFD => 'Cannot alter CounterDetail table layout in SQL database.'.freeze,
|
282
|
+
0xC0000BFE => 'System is busy. A time-out occurred when collecting counter data. Please retry later or increase the CollectTime registry value.'.freeze,
|
283
|
+
}.freeze
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
require 'win32/pdh'
|
4
|
+
require 'win32/pdh/constants'
|
5
|
+
|
6
|
+
module Win32
|
7
|
+
module Pdh
|
8
|
+
class Counter
|
9
|
+
class PDH_COUNTER_PATH_ELEMENTS < FFI::Struct
|
10
|
+
layout(
|
11
|
+
:szMachineName, :pointer,
|
12
|
+
:szObjectName, :pointer,
|
13
|
+
:szInstanceName, :pointer,
|
14
|
+
:szParentInstance, :pointer,
|
15
|
+
:dwInstanceIndex, :uint,
|
16
|
+
:szCounterName, :pointer,
|
17
|
+
)
|
18
|
+
end
|
19
|
+
class PDH_COUNTER_INFO < FFI::Struct
|
20
|
+
layout(
|
21
|
+
:dwLength, :uint,
|
22
|
+
:dwType, :uint,
|
23
|
+
:CVersion, :uint,
|
24
|
+
:CStatus, :uint,
|
25
|
+
:lScale, :uint,
|
26
|
+
:lDefaultScale, :uint,
|
27
|
+
:dwUserData, :pointer,
|
28
|
+
:dwQueryUserData, :pointer,
|
29
|
+
:szFullPath, :pointer,
|
30
|
+
:CounterPath, PDH_COUNTER_PATH_ELEMENTS,
|
31
|
+
:szExplainText, :pointer,
|
32
|
+
:DataBuffer, :uint,
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
class PDH_FMT_COUNTERVALUE_VALUE < FFI::Union
|
37
|
+
layout(
|
38
|
+
:longValue, :int32,
|
39
|
+
:doubleValue, :double,
|
40
|
+
:largeValue, :int64,
|
41
|
+
:AnsiStringValue, :pointer,
|
42
|
+
:WideStringValue, :pointer,
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
class PDH_FMT_COUNTERVALUE < FFI::Struct
|
47
|
+
layout(
|
48
|
+
:CStatus, :uint32,
|
49
|
+
:value, PDH_FMT_COUNTERVALUE_VALUE,
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
attr_accessor :type, :version, :status, :scale, :default_scale, :full_path, :machine_name, :object_name, :instance_name, :instance_index, :counter_name, :explain_text
|
54
|
+
|
55
|
+
def initialize(query:, path:)
|
56
|
+
path = (path + "\0").encode('UTF-16LE')
|
57
|
+
handle_pointer = FFI::MemoryPointer.new(:pointer)
|
58
|
+
status = PdhFFI.PdhAddCounterW(
|
59
|
+
query,
|
60
|
+
path,
|
61
|
+
FFI::Pointer::NULL,
|
62
|
+
handle_pointer,
|
63
|
+
)
|
64
|
+
Pdh.check_status status
|
65
|
+
@handle = handle_pointer.read_pointer
|
66
|
+
load_info
|
67
|
+
end
|
68
|
+
|
69
|
+
def remove
|
70
|
+
# Only allow removing once
|
71
|
+
unless @handle.nil?
|
72
|
+
status = PdhFFI.PdhRemoveCounter(@handle) unless @handle.nil?
|
73
|
+
Pdh.check_status status
|
74
|
+
@handle = nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
alias_method :close, :remove
|
79
|
+
|
80
|
+
def load_info
|
81
|
+
buffersize = FFI::MemoryPointer.new(:uint)
|
82
|
+
buffersize.write_uint(0)
|
83
|
+
buffer = FFI::Pointer::NULL
|
84
|
+
status = nil
|
85
|
+
while status.nil? || status == Constants::PDH_MORE_DATA
|
86
|
+
buffer = FFI::Buffer.new(:uint16, buffersize.read_uint) unless status.nil?
|
87
|
+
status = PdhFFI.PdhGetCounterInfoW(@handle, :false, buffersize, buffer)
|
88
|
+
end
|
89
|
+
Pdh.check_status status
|
90
|
+
|
91
|
+
info = PDH_COUNTER_INFO.new(buffer)
|
92
|
+
@type = info[:dwType]
|
93
|
+
@version = info[:CVersion]
|
94
|
+
@status = info[:CStatus]
|
95
|
+
@scale = info[:lScale]
|
96
|
+
@default_scale = info[:lDefaultScale]
|
97
|
+
@full_path = Pdh.read_cwstr(info[:szFullPath]).freeze
|
98
|
+
counter_path = info[:CounterPath]
|
99
|
+
@machine_name = Pdh.read_cwstr(counter_path[:szMachineName]).freeze
|
100
|
+
@object_name = Pdh.read_cwstr(counter_path[:szObjectName]).freeze
|
101
|
+
@instance_name = Pdh.read_cwstr(counter_path[:szInstanceName]).freeze
|
102
|
+
@instance_index = counter_path[:dwInstanceIndex]
|
103
|
+
@counter_name = Pdh.read_cwstr(counter_path[:szCounterName]).freeze
|
104
|
+
@explain_text = Pdh.read_cwstr(info[:szExplainText]).freeze
|
105
|
+
Pdh.check_status @status
|
106
|
+
end
|
107
|
+
|
108
|
+
def good?
|
109
|
+
@status == Constants::ERROR_SUCCESS
|
110
|
+
end
|
111
|
+
|
112
|
+
# Get the PDH_FMT_COUNTERVALUE_VALUE given the format, checking status and
|
113
|
+
# raising an exception if necessary
|
114
|
+
def get(format)
|
115
|
+
value = PDH_FMT_COUNTERVALUE.new
|
116
|
+
status = PdhFFI.PdhGetFormattedCounterValue(
|
117
|
+
@handle,
|
118
|
+
format,
|
119
|
+
FFI::Pointer::NULL,
|
120
|
+
value,
|
121
|
+
)
|
122
|
+
Pdh.check_status status
|
123
|
+
Pdh.check_status value[:CStatus]
|
124
|
+
value[:value]
|
125
|
+
end
|
126
|
+
|
127
|
+
##
|
128
|
+
# Get value as a double
|
129
|
+
def get_double
|
130
|
+
get(Constants::PDH_FMT_DOUBLE)[:doubleValue]
|
131
|
+
end
|
132
|
+
|
133
|
+
##
|
134
|
+
# Get value as a 64-bit integer
|
135
|
+
def get_large
|
136
|
+
get(Constants::PDH_FMT_LARGE)[:largeValue]
|
137
|
+
end
|
138
|
+
|
139
|
+
##
|
140
|
+
# Get value as a 32-bit integer
|
141
|
+
def get_long
|
142
|
+
get(Constants::PDH_FMT_LONG)[:longValue]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'win32/pdh'
|
2
|
+
require 'win32/pdh/counter'
|
3
|
+
|
4
|
+
module Win32
|
5
|
+
module Pdh
|
6
|
+
class Query
|
7
|
+
def initialize(source=nil)
|
8
|
+
source =
|
9
|
+
if source.nil?
|
10
|
+
FFI::Pointer::NULL
|
11
|
+
else
|
12
|
+
(source + "\0").encode('UTF-16LE')
|
13
|
+
end
|
14
|
+
handle_pointer = FFI::MemoryPointer.new(:pointer)
|
15
|
+
status = PdhFFI.PdhOpenQueryW(source, FFI::Pointer::NULL, handle_pointer)
|
16
|
+
raise PdhError, status unless status == Constants::ERROR_SUCCESS
|
17
|
+
@handle = handle_pointer.read_pointer
|
18
|
+
end
|
19
|
+
|
20
|
+
def close
|
21
|
+
# Only allow closing once
|
22
|
+
unless @handle.nil?
|
23
|
+
status = PdhFFI.PdhCloseQuery(@handle)
|
24
|
+
raise PdhError, status unless status == Constants::ERROR_SUCCESS
|
25
|
+
@handle = nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Simple query opening function. Uses the OpenQuery function and gets a
|
31
|
+
# query, passes it into the block, and then closes it afterward. If no
|
32
|
+
# block is given, it just returns the query, and you are responsible for
|
33
|
+
# closing it. The GC will not close this for you, so you can easily leak
|
34
|
+
# resources. It's strongly recommended to use the block style if at all
|
35
|
+
# possible to ensure resource cleanup.
|
36
|
+
def self.open(source=nil)
|
37
|
+
query = new source
|
38
|
+
if block_given?
|
39
|
+
begin
|
40
|
+
return yield query
|
41
|
+
ensure
|
42
|
+
query.close
|
43
|
+
end
|
44
|
+
else
|
45
|
+
query
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def real_time?
|
50
|
+
PdhFFI.PdhIsRealTimeQuery(@handle) == :true
|
51
|
+
end
|
52
|
+
|
53
|
+
##
|
54
|
+
# Adds a counter to this query and return it as a Counter object.
|
55
|
+
def add_counter(path)
|
56
|
+
Counter.new(
|
57
|
+
query: @handle,
|
58
|
+
path: path,
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
def collect_query_data
|
63
|
+
status = PdhFFI.PdhCollectQueryData(@handle)
|
64
|
+
Pdh.check_status status
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/win32/pdh.rb
CHANGED
@@ -0,0 +1,232 @@
|
|
1
|
+
require 'win32/pdh/constants'
|
2
|
+
|
3
|
+
require 'ffi'
|
4
|
+
|
5
|
+
module Win32
|
6
|
+
module Pdh
|
7
|
+
class PdhError < StandardError
|
8
|
+
def initialize(status)
|
9
|
+
super("PDH error #{Constants::NAMES[status]}: #{Constants::MESSAGES[status]}")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# Simple convenience method that checks the status and raises an exception
|
15
|
+
# unless it's a successful status.
|
16
|
+
def self.check_status(status)
|
17
|
+
raise PdhError, status unless status == Constants::ERROR_SUCCESS
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Takes a pointer to null-terminated utf-16 data and reads it into a utf-8 encoded string.
|
22
|
+
#
|
23
|
+
# If pointer is null, return nil instead of a string.
|
24
|
+
def self.read_cwstr(pointer)
|
25
|
+
return nil if pointer.null?
|
26
|
+
array = []
|
27
|
+
loop do
|
28
|
+
char = pointer.read_uint16
|
29
|
+
break if char == 0
|
30
|
+
|
31
|
+
array << char
|
32
|
+
# Need to proceed 2 bytes
|
33
|
+
pointer += 2
|
34
|
+
end
|
35
|
+
|
36
|
+
array.pack('n*').force_encoding('UTF-16BE').encode('UTF-8')
|
37
|
+
end
|
38
|
+
|
39
|
+
module PdhFFI
|
40
|
+
extend FFI::Library
|
41
|
+
ffi_lib 'Pdh.dll'
|
42
|
+
ffi_convention :stdcall
|
43
|
+
|
44
|
+
typedef :pointer, :pdh_hquery
|
45
|
+
typedef :pointer, :pdh_hcounter
|
46
|
+
typedef :uint, :pdh_status
|
47
|
+
enum :winbool, [:false, 0, :true]
|
48
|
+
|
49
|
+
:pdh_status
|
50
|
+
attach_function :PdhAddCounterW, [:pdh_hquery, :buffer_in, :buffer_in, :buffer_out], :pdh_status
|
51
|
+
attach_function :PdhCalculateCounterFromRawValue, [:pdh_hcounter, :uint, :buffer_in, :buffer_in, :buffer_out], :pdh_status
|
52
|
+
attach_function :PdhCollectQueryData, [:pdh_hquery], :pdh_status
|
53
|
+
attach_function :PdhCloseQuery, [:buffer_in], :pdh_status
|
54
|
+
attach_function :PdhEnumObjectItemsW, [:buffer_in, :buffer_in, :buffer_in, :buffer_out, :buffer_inout, :buffer_out, :buffer_inout, :uint, :uint], :pdh_status
|
55
|
+
attach_function :PdhEnumObjectsW, [:buffer_in, :buffer_in, :buffer_out, :buffer_inout, :uint, :winbool], :pdh_status
|
56
|
+
attach_function :PdhExpandWildCardPathW, [:buffer_in, :buffer_in, :buffer_out, :buffer_inout, :uint], :pdh_status
|
57
|
+
|
58
|
+
# We use Ascii instead of Wide for this because reading null-terminated
|
59
|
+
# utf-16 buffers with Ruby FFI is not easy.
|
60
|
+
attach_function :PdhGetCounterInfoW, [:pdh_hcounter, :winbool, :buffer_inout, :buffer_out], :pdh_status
|
61
|
+
attach_function :PdhGetFormattedCounterArrayW, [:pdh_hcounter, :uint, :buffer_inout, :buffer_out, :buffer_out], :pdh_status
|
62
|
+
attach_function :PdhGetFormattedCounterValue, [:pdh_hcounter, :uint, :buffer_out, :buffer_out], :pdh_status
|
63
|
+
attach_function :PdhGetRawCounterArrayW, [:pdh_hcounter, :buffer_inout, :buffer_out, :buffer_out], :pdh_status
|
64
|
+
attach_function :PdhGetRawCounterValue, [:pdh_hcounter, :buffer_out, :buffer_out], :pdh_status
|
65
|
+
attach_function :PdhIsRealTimeQuery, [:pdh_hquery], :winbool
|
66
|
+
attach_function :PdhOpenQueryW, [:buffer_in, :buffer_in, :buffer_out], :pdh_status
|
67
|
+
attach_function :PdhRemoveCounter, [:pdh_hcounter], :pdh_status
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Uses PdhEnumObjects to enumerate objects at the given target. Returns the
|
72
|
+
# objects as a list.
|
73
|
+
#
|
74
|
+
# Params:
|
75
|
+
# +source+:: The same as szDataSource
|
76
|
+
# +machine+:: The same as szMachineName
|
77
|
+
# +detail+:: Alias for dwDetailLevel, as a symbol. May be :novice, :advanced, :expert, or :wizard. Defaults to :novice.
|
78
|
+
def self.enum_objects(source: nil, machine: nil, detail: :novice)
|
79
|
+
source =
|
80
|
+
if source.nil?
|
81
|
+
FFI::Pointer::NULL
|
82
|
+
else
|
83
|
+
(source + "\0").encode('UTF-16LE')
|
84
|
+
end
|
85
|
+
machine =
|
86
|
+
if machine.nil?
|
87
|
+
FFI::Pointer::NULL
|
88
|
+
else
|
89
|
+
(machine + "\0").encode('UTF-16LE')
|
90
|
+
end
|
91
|
+
detail =
|
92
|
+
case detail
|
93
|
+
when :wizard
|
94
|
+
Constants::PERF_DETAIL_WIZARD
|
95
|
+
when :expert
|
96
|
+
Constants::PERF_DETAIL_EXPERT
|
97
|
+
when :advanced
|
98
|
+
Constants::PERF_DETAIL_ADVANCED
|
99
|
+
else
|
100
|
+
Constants::PERF_DETAIL_NOVICE
|
101
|
+
end
|
102
|
+
|
103
|
+
listsize = FFI::MemoryPointer.new(:uint)
|
104
|
+
listsize.write_uint(0)
|
105
|
+
listbuffer = FFI::Pointer::NULL
|
106
|
+
status = nil
|
107
|
+
while status.nil? || status == Constants::PDH_MORE_DATA
|
108
|
+
listbuffer = FFI::Buffer.new(:uint16, listsize.read_uint) unless status.nil?
|
109
|
+
|
110
|
+
status = PdhFFI.PdhEnumObjectsW(
|
111
|
+
source,
|
112
|
+
machine,
|
113
|
+
listbuffer,
|
114
|
+
listsize,
|
115
|
+
detail,
|
116
|
+
status.nil? ? :true : :false,
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
Pdh.check_status status
|
121
|
+
|
122
|
+
string = listbuffer.read_bytes(listsize.read_uint * 2).force_encoding('UTF-16LE').encode('UTF-8')
|
123
|
+
|
124
|
+
# Split and return objects
|
125
|
+
string.split("\0")
|
126
|
+
end
|
127
|
+
|
128
|
+
ItemEnum = Struct.new('ItemEnum', :instances, :counters)
|
129
|
+
|
130
|
+
##
|
131
|
+
# Enumerates an object's counter and instance names. Returns an ItemEnum
|
132
|
+
# with the results.
|
133
|
+
def self.enum_object_items(object:, source: nil, machine: nil, detail: :novice)
|
134
|
+
object = (object + "\0").encode('UTF-16LE')
|
135
|
+
source =
|
136
|
+
if source.nil?
|
137
|
+
FFI::Pointer::NULL
|
138
|
+
else
|
139
|
+
(source + "\0").encode('UTF-16LE')
|
140
|
+
end
|
141
|
+
machine =
|
142
|
+
if machine.nil?
|
143
|
+
FFI::Pointer::NULL
|
144
|
+
else
|
145
|
+
(machine + "\0").encode('UTF-16LE')
|
146
|
+
end
|
147
|
+
detail =
|
148
|
+
case detail
|
149
|
+
when :wizard
|
150
|
+
Constants::PERF_DETAIL_WIZARD
|
151
|
+
when :expert
|
152
|
+
Constants::PERF_DETAIL_EXPERT
|
153
|
+
when :advanced
|
154
|
+
Constants::PERF_DETAIL_ADVANCED
|
155
|
+
else
|
156
|
+
Constants::PERF_DETAIL_NOVICE
|
157
|
+
end
|
158
|
+
|
159
|
+
countersize = FFI::MemoryPointer.new(:uint)
|
160
|
+
instancesize = FFI::MemoryPointer.new(:uint)
|
161
|
+
countersize.write_uint(0)
|
162
|
+
instancesize.write_uint(0)
|
163
|
+
counterbuffer = FFI::Pointer::NULL
|
164
|
+
instancebuffer = FFI::Pointer::NULL
|
165
|
+
status = nil
|
166
|
+
while status.nil? || status == Constants::PDH_MORE_DATA
|
167
|
+
unless status.nil?
|
168
|
+
counterbuffer = FFI::Buffer.new(:uint16, countersize.read_uint)
|
169
|
+
instancebuffer = FFI::Buffer.new(:uint16, instancesize.read_uint)
|
170
|
+
end
|
171
|
+
status = PdhFFI.PdhEnumObjectItemsW(
|
172
|
+
source,
|
173
|
+
machine,
|
174
|
+
object,
|
175
|
+
counterbuffer,
|
176
|
+
countersize,
|
177
|
+
instancebuffer,
|
178
|
+
instancesize,
|
179
|
+
detail,
|
180
|
+
0,
|
181
|
+
)
|
182
|
+
end
|
183
|
+
|
184
|
+
Pdh.check_status status
|
185
|
+
|
186
|
+
counterstring = counterbuffer.read_bytes(countersize.read_uint * 2).force_encoding('UTF-16LE').encode('UTF-8')
|
187
|
+
instancestring = instancebuffer.read_bytes(instancesize.read_uint * 2).force_encoding('UTF-16LE').encode('UTF-8')
|
188
|
+
|
189
|
+
enum = ItemEnum.new
|
190
|
+
enum.counters = counterstring.split("\0").map(&:freeze).freeze
|
191
|
+
enum.instances = instancestring.split("\0").map(&:freeze).freeze
|
192
|
+
enum.freeze
|
193
|
+
end
|
194
|
+
|
195
|
+
##
|
196
|
+
# Expands a wildcard path into all matching counter paths.
|
197
|
+
def self.expand_wildcards(path:, source: nil, expand_counters: true, expand_instances: true)
|
198
|
+
path = (path + "\0").encode('UTF-16LE')
|
199
|
+
source =
|
200
|
+
if source.nil?
|
201
|
+
FFI::Pointer::NULL
|
202
|
+
else
|
203
|
+
(source + "\0").encode('UTF-16LE')
|
204
|
+
end
|
205
|
+
|
206
|
+
flags = 0
|
207
|
+
flags |= PDH_NOEXPANDCOUNTERS unless expand_counters
|
208
|
+
flags |= PDH_NOEXPANDINSTANCES unless expand_instances
|
209
|
+
|
210
|
+
listsize = FFI::MemoryPointer.new(:uint)
|
211
|
+
listsize.write_uint(0)
|
212
|
+
listbuffer = FFI::Pointer::NULL
|
213
|
+
status = nil
|
214
|
+
while status.nil? || status == Constants::PDH_MORE_DATA
|
215
|
+
listbuffer = FFI::Buffer.new(:uint16, listsize.read_uint) unless status.nil?
|
216
|
+
status = PdhFFI.PdhExpandWildCardPathW(
|
217
|
+
source,
|
218
|
+
path,
|
219
|
+
listbuffer,
|
220
|
+
listsize,
|
221
|
+
flags,
|
222
|
+
)
|
223
|
+
end
|
224
|
+
|
225
|
+
Pdh.check_status status
|
226
|
+
|
227
|
+
liststring = listbuffer.read_bytes(listsize.read_uint * 2).force_encoding('UTF-16LE').encode('UTF-8')
|
228
|
+
|
229
|
+
liststring.split("\0").map(&:freeze).freeze
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win32-pdh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor C. Richberger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -31,6 +31,9 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
33
|
- lib/win32/pdh.rb
|
34
|
+
- lib/win32/pdh/constants.rb
|
35
|
+
- lib/win32/pdh/counter.rb
|
36
|
+
- lib/win32/pdh/query.rb
|
34
37
|
homepage: http://github.com/absperf/win32-pdh
|
35
38
|
licenses:
|
36
39
|
- MIT
|