| 205 | } |
| 206 | |
| 207 | uint32_t EventMetadata::GetEventDataWithCount(EVENT_RECORD* eventRecord, EventDataDesc* desc, uint32_t descCount) |
| 208 | { |
| 209 | // Look up stored metadata. If not found, look up metadata using TDH and |
| 210 | // cache it for future events. |
| 211 | EventMetadataKey key; |
| 212 | key.guid_ = eventRecord->EventHeader.ProviderId; |
| 213 | key.desc_ = eventRecord->EventHeader.EventDescriptor; |
| 214 | auto ii = metadata_.find(key); |
| 215 | if (ii == metadata_.end()) { |
| 216 | ULONG bufferSize = 0; |
| 217 | auto status = TdhGetEventInformation(eventRecord, 0, nullptr, nullptr, &bufferSize); |
| 218 | if (status == ERROR_INSUFFICIENT_BUFFER) { |
| 219 | ii = metadata_.emplace(key, std::vector<uint8_t>(bufferSize, 0)).first; |
| 220 | |
| 221 | status = TdhGetEventInformation(eventRecord, 0, nullptr, (TRACE_EVENT_INFO*) ii->second.data(), &bufferSize); |
| 222 | assert(status == ERROR_SUCCESS); |
| 223 | } else { |
| 224 | // No schema registered with system, nor ETL-embedded metadata. |
| 225 | ii = metadata_.emplace(key, std::vector<uint8_t>(sizeof(TRACE_EVENT_INFO), 0)).first; |
| 226 | assert(false); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | auto tei = (TRACE_EVENT_INFO*) ii->second.data(); |
| 231 | |
| 232 | // Lookup properties in metadata |
| 233 | uint32_t foundCount = 0; |
| 234 | |
| 235 | #if 0 /* Helper to see all property names while debugging */ |
| 236 | std::vector<wchar_t const*> props(tei->TopLevelPropertyCount, nullptr); |
| 237 | for (uint32_t i = 0; i < tei->TopLevelPropertyCount; ++i) { |
| 238 | props[i] = TEI_PROPERTY_NAME(tei, &tei->EventPropertyInfoArray[i]); |
| 239 | } |
| 240 | #endif |
| 241 | |
| 242 | for (uint32_t i = 0, offset = 0; i < tei->TopLevelPropertyCount; ++i) { |
| 243 | auto info = GetPropertyInfo(*tei, *eventRecord, i, offset); |
| 244 | |
| 245 | auto propName = TEI_PROPERTY_NAME(tei, &tei->EventPropertyInfoArray[i]); |
| 246 | if (propName != nullptr) { |
| 247 | for (uint32_t j = 0; j < descCount; ++j) { |
| 248 | if (desc[j].status_ == PROP_STATUS_NOT_FOUND && wcscmp(propName, desc[j].name_) == 0) { |
| 249 | desc[j].data_ = (void*) ((uintptr_t) eventRecord->UserData + offset); |
| 250 | desc[j].size_ = info.size_; |
| 251 | desc[j].count_ = info.count_; |
| 252 | desc[j].status_ = info.status_ | PROP_STATUS_FOUND; |
| 253 | |
| 254 | foundCount += 1; |
| 255 | if (foundCount == descCount) { |
| 256 | return foundCount; |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | offset += info.size_ * info.count_; |
| 263 | } |
| 264 |
nothing calls this directly
no test coverage detected