| 1320 | |
| 1321 | #if defined(_WIN32) |
| 1322 | std::vector<std::string> expandWildcardPath(const char* wildcardPath) { |
| 1323 | PDH_STATUS Status; |
| 1324 | char* EndOfPaths; |
| 1325 | char* Paths = nullptr; |
| 1326 | DWORD BufferSize = 0; |
| 1327 | std::vector<std::string> results; |
| 1328 | |
| 1329 | Status = PdhExpandCounterPath(wildcardPath, Paths, &BufferSize); |
| 1330 | if (Status != PDH_MORE_DATA) { |
| 1331 | TraceEvent(SevWarn, "PdhExpandCounterPathError") |
| 1332 | .detail("Reason", "Expand Path call made no sense") |
| 1333 | .detail("Status", Status); |
| 1334 | goto Cleanup; |
| 1335 | } |
| 1336 | |
| 1337 | Paths = (char*)malloc(BufferSize); |
| 1338 | Status = PdhExpandCounterPath(wildcardPath, Paths, &BufferSize); |
| 1339 | |
| 1340 | if (Status != ERROR_SUCCESS) { |
| 1341 | TraceEvent(SevWarn, "PdhExpandCounterPathError") |
| 1342 | .detail("Reason", "Expand Path call failed") |
| 1343 | .detail("Status", Status); |
| 1344 | goto Cleanup; |
| 1345 | } |
| 1346 | |
| 1347 | if (Paths == nullptr) { |
| 1348 | TraceEvent("WindowsPdhExpandCounterPathError").detail("Reason", "Path could not be expanded"); |
| 1349 | goto Cleanup; |
| 1350 | } |
| 1351 | |
| 1352 | EndOfPaths = Paths + BufferSize; |
| 1353 | |
| 1354 | for (char* p = Paths; ((p != EndOfPaths) && (*p != '\0')); p += strlen(p) + 1) { |
| 1355 | results.push_back(p); |
| 1356 | // printf("Counter: %s\n", p); |
| 1357 | } |
| 1358 | |
| 1359 | Cleanup: |
| 1360 | if (Paths) { |
| 1361 | free(Paths); |
| 1362 | } |
| 1363 | return results; |
| 1364 | } |
| 1365 | |
| 1366 | std::vector<HCOUNTER> addCounters(HQUERY Query, const char* path) { |
| 1367 | std::vector<HCOUNTER> counters; |
no test coverage detected