| 126 | } |
| 127 | |
| 128 | static bool getInstancesAndCountersOfObject(const std::wstring& wsObject, |
| 129 | std::vector<std::wstring>& vecInstances, std::vector<std::wstring>& vecCounters) |
| 130 | { |
| 131 | DWORD dwCounterListLength = 0, dwInstanceListLength = 0; |
| 132 | |
| 133 | if (PdhEnumObjectItems(NULL, NULL, wsObject.c_str(), |
| 134 | NULL, &dwCounterListLength, NULL, |
| 135 | &dwInstanceListLength, PERF_DETAIL_WIZARD, 0) != PDH_MORE_DATA) |
| 136 | return false; |
| 137 | |
| 138 | std::vector<WCHAR> mszCounterList(dwCounterListLength + 1); |
| 139 | std::vector<WCHAR> mszInstanceList(dwInstanceListLength + 1); |
| 140 | |
| 141 | if (FAILED(PdhEnumObjectItems(NULL, NULL, wsObject.c_str(), |
| 142 | mszCounterList.data(), &dwCounterListLength, mszInstanceList.data(), |
| 143 | &dwInstanceListLength, PERF_DETAIL_WIZARD, 0))) { |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | if (dwInstanceListLength) { |
| 148 | std::wstringstream wssInstanceName; |
| 149 | |
| 150 | // XXX: is the "- 1" correct? |
| 151 | for (DWORD c = 0; c < dwInstanceListLength - 1; ++c) { |
| 152 | if (mszInstanceList[c]) |
| 153 | wssInstanceName << mszInstanceList[c]; |
| 154 | else { |
| 155 | vecInstances.push_back(wssInstanceName.str()); |
| 156 | wssInstanceName.str(L""); |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | if (dwCounterListLength) { |
| 162 | std::wstringstream wssCounterName; |
| 163 | |
| 164 | // XXX: is the "- 1" correct? |
| 165 | for (DWORD c = 0; c < dwCounterListLength - 1; ++c) { |
| 166 | if (mszCounterList[c]) |
| 167 | wssCounterName << mszCounterList[c]; |
| 168 | else { |
| 169 | vecCounters.push_back(wssCounterName.str()); |
| 170 | wssCounterName.str(L""); |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | return true; |
| 176 | } |
| 177 | |
| 178 | static void printPDHError(PDH_STATUS status) |
| 179 | { |
no test coverage detected