llvm.org GIT mirror llvm / 728dd9a
[XRay][tools] Support arg1 logging entries in the basic logging mode Summary: The arg1 logging handler changed in compiler-rt to start writing a different type for entries encountered when logging the first argument of XRay-instrumented functions. This change allows the trace loader to support reading these record types as well as prepare for when the basic (naive) mode implementation starts writing down the argument payloads. Without this change, binaries with arg1 logging support enabled start writing unreadable logs for any of the XRay tracing tools. Reviewers: pelikan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D38550 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314967 91177308-0d34-0410-b5e6-96231b3b80d8 Dean Michael Berris 2 years ago
3 changed file(s) with 66 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
8181 for (auto S = Data.drop_front(32); !S.empty(); S = S.drop_front(32)) {
8282 DataExtractor RecordExtractor(S, true, 8);
8383 uint32_t OffsetPtr = 0;
84 Records.emplace_back();
85 auto &Record = Records.back();
86 Record.RecordType = RecordExtractor.getU16(&OffsetPtr);
87 Record.CPU = RecordExtractor.getU8(&OffsetPtr);
88 auto Type = RecordExtractor.getU8(&OffsetPtr);
89 switch (Type) {
90 case 0:
91 Record.Type = RecordTypes::ENTER;
84 switch (auto RecordType = RecordExtractor.getU16(&OffsetPtr)) {
85 case 0: { // Normal records.
86 Records.emplace_back();
87 auto &Record = Records.back();
88 Record.RecordType = RecordType;
89 Record.CPU = RecordExtractor.getU8(&OffsetPtr);
90 auto Type = RecordExtractor.getU8(&OffsetPtr);
91 switch (Type) {
92 case 0:
93 Record.Type = RecordTypes::ENTER;
94 break;
95 case 1:
96 Record.Type = RecordTypes::EXIT;
97 break;
98 case 2:
99 Record.Type = RecordTypes::TAIL_EXIT;
100 break;
101 case 3:
102 Record.Type = RecordTypes::ENTER_ARG;
103 break;
104 default:
105 return make_error(
106 Twine("Unknown record type '") + Twine(int{Type}) + "'",
107 std::make_error_code(std::errc::executable_format_error));
108 }
109 Record.FuncId = RecordExtractor.getSigned(&OffsetPtr, sizeof(int32_t));
110 Record.TSC = RecordExtractor.getU64(&OffsetPtr);
111 Record.TId = RecordExtractor.getU32(&OffsetPtr);
92112 break;
93 case 1:
94 Record.Type = RecordTypes::EXIT;
113 }
114 case 1: { // Arg payload record.
115 auto &Record = Records.back();
116 // Advance two bytes to avoid padding.
117 OffsetPtr += 2;
118 int32_t FuncId = RecordExtractor.getSigned(&OffsetPtr, sizeof(int32_t));
119 auto TId = RecordExtractor.getU32(&OffsetPtr);
120 if (Record.FuncId != FuncId || Record.TId != TId)
121 return make_error(
122 Twine("Corrupted log, found payload following non-matching "
123 "function + thread record. Record for ") +
124 Twine(Record.FuncId) + " != " + Twine(FuncId),
125 std::make_error_code(std::errc::executable_format_error));
126 // Advance another four bytes to avoid padding.
127 OffsetPtr += 4;
128 auto Arg = RecordExtractor.getU64(&OffsetPtr);
129 Record.CallArgs.push_back(Arg);
95130 break;
96 case 2:
97 Record.Type = RecordTypes::TAIL_EXIT;
98 break;
131 }
99132 default:
100133 return make_error(
101 Twine("Unknown record type '") + Twine(int{Type}) + "'",
134 Twine("Unknown record type == ") + Twine(RecordType),
102135 std::make_error_code(std::errc::executable_format_error));
103136 }
104 Record.FuncId = RecordExtractor.getSigned(&OffsetPtr, sizeof(int32_t));
105 Record.TSC = RecordExtractor.getU64(&OffsetPtr);
106 Record.TId = RecordExtractor.getU32(&OffsetPtr);
107137 }
108138 return Error::success();
109139 }
233263 uint32_t DataSize = RecordExtractor.getU32(&OffsetPtr);
234264 uint64_t TSC = RecordExtractor.getU64(&OffsetPtr);
235265
236 // FIXME: Actually represent the record through the API. For now we only skip
237 // through the data.
266 // FIXME: Actually represent the record through the API. For now we only
267 // skip through the data.
238268 (void)TSC;
239269 RecordSize = 16 + DataSize;
240270 return Error::success();
506536 Records.clear();
507537 std::transform(Trace.Records.begin(), Trace.Records.end(),
508538 std::back_inserter(Records), [&](const YAMLXRayRecord &R) {
509 return XRayRecord{R.RecordType, R.CPU, R.Type,
510 R.FuncId, R.TSC, R.TId, R.CallArgs};
539 return XRayRecord{R.RecordType, R.CPU, R.Type, R.FuncId,
540 R.TSC, R.TId, R.CallArgs};
511541 });
512542 return Error::success();
513543 }
0 ; RUN: llvm-xray convert %S/Inputs/naive-with-arg1-entries.xray -f=yaml -o - | FileCheck %s
1
2 ; CHECK: ---
3 ; CHECK-NEXT: header:
4 ; CHECK-NEXT: version: 2
5 ; CHECK-NEXT: type: 0
6 ; CHECK-NEXT: constant-tsc: true
7 ; CHECK-NEXT: nonstop-tsc: true
8 ; CHECK-NEXT: cycle-frequency: 3500000000
9 ; CHECK-NEXT: records:
10 ; CHECK-NEXT: - { type: 0, func-id: 1, function: '1', cpu: 17, thread: 8715, kind: function-enter, tsc: 22555670288232728 }
11 ; CHECK-NEXT: - { type: 0, func-id: 1, function: '1', cpu: 17, thread: 8715, kind: function-exit, tsc: 22555670288334784 }
12 ; CHECK-NEXT: - { type: 0, func-id: 2, function: '2', args: [ 1 ], cpu: 17, thread: 8715, kind: function-enter-arg, tsc: 22555670288335768 }
13 ; CHECK-NEXT: - { type: 0, func-id: 2, function: '2', cpu: 17, thread: 8715, kind: function-exit, tsc: 22555670288365224 }
14 ; CHECK-NEXT: ...