llvm.org GIT mirror llvm / 022fc8e
[XRay][lib] Support and temporarily skip over CustomEvent records Summary: In D30630 we will start writing custom event records. To avoid breaking the tools that read the FDR mode records, we skip over these records. To support these custom event records more effectively, we will have to expose them in the trace loading API. Those changes will be forthcoming. Reviewers: kpw, pelikan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D33032 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302856 91177308-0d34-0410-b5e6-96231b3b80d8 Dean Michael Berris 3 years ago
1 changed file(s) with 32 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
114114 uint16_t CPUId;
115115 uint16_t ThreadId;
116116 uint64_t BaseTSC;
117
117118 /// Encode some of the state transitions for the FDR log reader as explicit
118119 /// checks. These are expectations for the next Record in the stream.
119120 enum class Token {
122123 NEW_CPU_ID_RECORD,
123124 FUNCTION_SEQUENCE,
124125 SCAN_TO_END_OF_THREAD_BUF,
126 CUSTOM_EVENT_DATA,
125127 };
126128 Token Expects;
129
127130 // Each threads buffer may have trailing garbage to scan over, so we track our
128131 // progress.
129132 uint64_t CurrentBufferSize;
142145 return "FUNCTION_SEQUENCE";
143146 case FDRState::Token::SCAN_TO_END_OF_THREAD_BUF:
144147 return "SCAN_TO_END_OF_THREAD_BUF";
148 case FDRState::Token::CUSTOM_EVENT_DATA:
149 return "CUSTOM_EVENT_DATA";
145150 }
146151 return "UNKNOWN";
147152 }
208213 // We don't encode the wall time into any of the records.
209214 // XRayRecords are concerned with the TSC instead.
210215 State.Expects = FDRState::Token::NEW_CPU_ID_RECORD;
216 return Error::success();
217 }
218
219 /// State transition when a CustomEventMarker is encountered.
220 Error processCustomEventMarker(FDRState &State, uint8_t RecordFirstByte,
221 DataExtractor &RecordExtractor,
222 size_t &RecordSize) {
223 // We can encounter a CustomEventMarker anywhere in the log, so we can handle
224 // it regardless of the expectation. However, we do se the expectation to read
225 // a set number of fixed bytes, as described in the metadata.
226 uint32_t OffsetPtr = 1; // Read after the first byte.
227 uint32_t DataSize = RecordExtractor.getU32(&OffsetPtr);
228 uint64_t TSC = RecordExtractor.getU64(&OffsetPtr);
229
230 // FIXME: Actually represent the record through the API. For now we only skip
231 // through the data.
232 (void)TSC;
233 RecordSize = 16 + DataSize;
211234 return Error::success();
212235 }
213236
217240 /// Record, which the caller should pass in because they have already read it
218241 /// to determine that this is a metadata record as opposed to a function record.
219242 Error processFDRMetadataRecord(FDRState &State, uint8_t RecordFirstByte,
220 DataExtractor &RecordExtractor) {
243 DataExtractor &RecordExtractor,
244 size_t &RecordSize) {
221245 // The remaining 7 bits are the RecordKind enum.
222246 uint8_t RecordKind = RecordFirstByte >> 1;
223247 switch (RecordKind) {
244268 case 4: // WallTimeMarker
245269 if (auto E =
246270 processFDRWallTimeRecord(State, RecordFirstByte, RecordExtractor))
271 return E;
272 break;
273 case 5: // CustomEventMarker
274 if (auto E = processCustomEventMarker(State, RecordFirstByte,
275 RecordExtractor, RecordSize))
247276 return E;
248277 break;
249278 default:
399428 bool isMetadataRecord = BitField & 0x01uL;
400429 if (isMetadataRecord) {
401430 RecordSize = 16;
402 if (auto E = processFDRMetadataRecord(State, BitField, RecordExtractor))
431 if (auto E = processFDRMetadataRecord(State, BitField, RecordExtractor,
432 RecordSize))
403433 return E;
404434 State.CurrentBufferConsumed += RecordSize;
405435 } else { // Process Function Record