| 283 | }; |
| 284 | |
| 285 | void EnumerateSystemEvents(GUID const& providerGuid, std::vector<Event>* events, std::wstring* outProviderName) |
| 286 | { |
| 287 | ULONG bufferSize = 0; |
| 288 | auto status = TdhEnumerateManifestProviderEvents((LPGUID) &providerGuid, nullptr, &bufferSize); |
| 289 | switch (status) { |
| 290 | case ERROR_EMPTY: return; |
| 291 | case ERROR_INSUFFICIENT_BUFFER: break; |
| 292 | default: |
| 293 | fprintf(stderr, "error: could not enumerate events ("); |
| 294 | switch (status) { |
| 295 | case ERROR_INVALID_DATA: fprintf(stderr, "ERROR_INVALID_DATA"); break; |
| 296 | case ERROR_FILE_NOT_FOUND: fprintf(stderr, "provider meta data not found"); break; |
| 297 | case ERROR_RESOURCE_TYPE_NOT_FOUND: fprintf(stderr, "ERROR_RESOURCE_TYPE_NOT_FOUND"); break; |
| 298 | case ERROR_NOT_FOUND: fprintf(stderr, "provider schema information not found"); break; |
| 299 | default: fprintf(stderr, "error=%u", status); |
| 300 | } |
| 301 | fprintf(stderr, ").\n"); |
| 302 | exit(1); |
| 303 | } |
| 304 | |
| 305 | auto enumInfo = (PROVIDER_EVENT_INFO*) malloc(bufferSize); |
| 306 | if (enumInfo == nullptr) { |
| 307 | fprintf(stderr, "error: could not allocate memory for events (%u bytes).\n", bufferSize); |
| 308 | exit(1); |
| 309 | } |
| 310 | |
| 311 | status = TdhEnumerateManifestProviderEvents((LPGUID) &providerGuid, enumInfo, &bufferSize); |
| 312 | if (status != ERROR_SUCCESS) { |
| 313 | fprintf(stderr, "error: could not enumerate events (error=%u).\n", status); |
| 314 | free(enumInfo); |
| 315 | exit(1); |
| 316 | } |
| 317 | |
| 318 | auto eventCount = enumInfo->NumberOfEvents; |
| 319 | events->reserve(events->size() + eventCount); |
| 320 | for (ULONG eventIndex = 0; eventIndex < eventCount; ++eventIndex) { |
| 321 | auto desc = &enumInfo->EventDescriptorsArray[eventIndex]; |
| 322 | |
| 323 | bufferSize = 0; |
| 324 | status = TdhGetManifestEventInformation((LPGUID) &providerGuid, desc, nullptr, &bufferSize); |
| 325 | if (status != ERROR_INSUFFICIENT_BUFFER) { |
| 326 | fprintf(stderr, "error: could not get manifest event information (error=%u).\n", status); |
| 327 | exit(1); |
| 328 | } |
| 329 | |
| 330 | auto eventInfo = (TRACE_EVENT_INFO*) malloc(bufferSize); |
| 331 | if (eventInfo == nullptr) { |
| 332 | fprintf(stderr, "error: could not allocate memory for event information (%u bytes).\n", bufferSize); |
| 333 | exit(1); |
| 334 | } |
| 335 | |
| 336 | status = TdhGetManifestEventInformation((LPGUID) &providerGuid, desc, eventInfo, &bufferSize); |
| 337 | if (status != ERROR_SUCCESS) { |
| 338 | fprintf(stderr, "error: could not get manifest event information (error=%u).\n", status); |
| 339 | free(eventInfo); |
| 340 | exit(1); |
| 341 | } |
| 342 |
no test coverage detected