Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 62b2611

Browse files
author
Martin Pelikan
committed
[XRay] convert FDR arg1 log entries
Summary: A new FDR metadata record will support logging a function call argument; appending multiple metadata records will represent a sequence of arguments meaning that "holes" are not representable by the buffer format. Each call argument is currently a 64-bit value (useful for "this" pointers and synchronization objects). If present, we put this argument to the function call "entry" record it belongs to, and alter its type to notify the user of its presence. Reviewers: dberris Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32840 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314269 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 342e0df commit 62b2611

File tree

8 files changed

+63
-6
lines changed

8 files changed

+63
-6
lines changed

include/llvm/XRay/XRayRecord.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct XRayFileHeader {
5353
/// This may or may not correspond to actual record types in the raw trace (as
5454
/// the loader implementation may synthesize this information in the process of
5555
/// of loading).
56-
enum class RecordTypes { ENTER, EXIT, TAIL_EXIT };
56+
enum class RecordTypes { ENTER, EXIT, TAIL_EXIT, ENTER_ARG };
5757

5858
struct XRayRecord {
5959
/// The type of record.
@@ -73,6 +73,9 @@ struct XRayRecord {
7373

7474
/// The thread ID for the currently running thread.
7575
uint32_t TId;
76+
77+
/// The function call arguments.
78+
std::vector<uint64_t> CallArgs;
7679
};
7780

7881
} // namespace xray

include/llvm/XRay/YAMLXRayRecord.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct YAMLXRayRecord {
3737
std::string Function;
3838
uint64_t TSC;
3939
uint32_t TId;
40+
std::vector<uint64_t> CallArgs;
4041
};
4142

4243
struct YAMLXRayTrace {
@@ -55,6 +56,7 @@ template <> struct ScalarEnumerationTraits<xray::RecordTypes> {
5556
IO.enumCase(Type, "function-enter", xray::RecordTypes::ENTER);
5657
IO.enumCase(Type, "function-exit", xray::RecordTypes::EXIT);
5758
IO.enumCase(Type, "function-tail-exit", xray::RecordTypes::TAIL_EXIT);
59+
IO.enumCase(Type, "function-enter-arg", xray::RecordTypes::ENTER_ARG);
5860
}
5961
};
6062

@@ -74,6 +76,7 @@ template <> struct MappingTraits<xray::YAMLXRayRecord> {
7476
IO.mapRequired("type", Record.RecordType);
7577
IO.mapRequired("func-id", Record.FuncId);
7678
IO.mapOptional("function", Record.Function);
79+
IO.mapOptional("args", Record.CallArgs);
7780
IO.mapRequired("cpu", Record.CPU);
7881
IO.mapRequired("thread", Record.TId);
7982
IO.mapRequired("kind", Record.Type);
@@ -83,6 +86,16 @@ template <> struct MappingTraits<xray::YAMLXRayRecord> {
8386
static constexpr bool flow = true;
8487
};
8588

89+
template <> struct SequenceTraits<std::vector<uint64_t>> {
90+
static constexpr bool flow = true;
91+
static size_t size(IO &IO, std::vector<uint64_t> &V) { return V.size(); }
92+
static uint64_t &element(IO &IO, std::vector<uint64_t> &V, size_t Index) {
93+
if (Index >= V.size())
94+
V.resize(Index + 1);
95+
return V[Index];
96+
}
97+
};
98+
8699
template <> struct MappingTraits<xray::YAMLXRayTrace> {
87100
static void mapping(IO &IO, xray::YAMLXRayTrace &Trace) {
88101
// A trace file contains two parts, the header and the list of all the

lib/XRay/Trace.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ struct FDRState {
128128
FUNCTION_SEQUENCE,
129129
SCAN_TO_END_OF_THREAD_BUF,
130130
CUSTOM_EVENT_DATA,
131+
CALL_ARGUMENT,
131132
};
132133
Token Expects;
133134

@@ -151,6 +152,8 @@ const char *fdrStateToTwine(const FDRState::Token &state) {
151152
return "SCAN_TO_END_OF_THREAD_BUF";
152153
case FDRState::Token::CUSTOM_EVENT_DATA:
153154
return "CUSTOM_EVENT_DATA";
155+
case FDRState::Token::CALL_ARGUMENT:
156+
return "CALL_ARGUMENT";
154157
}
155158
return "UNKNOWN";
156159
}
@@ -238,14 +241,31 @@ Error processCustomEventMarker(FDRState &State, uint8_t RecordFirstByte,
238241
return Error::success();
239242
}
240243

244+
/// State transition when a CallArgumentRecord is encountered.
245+
Error processFDRCallArgumentRecord(FDRState &State, uint8_t RecordFirstByte,
246+
DataExtractor &RecordExtractor,
247+
std::vector<XRayRecord> &Records) {
248+
uint32_t OffsetPtr = 1; // Read starting after the first byte.
249+
auto &Enter = Records.back();
250+
251+
if (Enter.Type != RecordTypes::ENTER)
252+
return make_error<StringError>(
253+
"CallArgument needs to be right after a function entry",
254+
std::make_error_code(std::errc::executable_format_error));
255+
Enter.Type = RecordTypes::ENTER_ARG;
256+
Enter.CallArgs.emplace_back(RecordExtractor.getU64(&OffsetPtr));
257+
return Error::success();
258+
}
259+
241260
/// Advances the state machine for reading the FDR record type by reading one
242261
/// Metadata Record and updating the State appropriately based on the kind of
243262
/// record encountered. The RecordKind is encoded in the first byte of the
244263
/// Record, which the caller should pass in because they have already read it
245264
/// to determine that this is a metadata record as opposed to a function record.
246265
Error processFDRMetadataRecord(FDRState &State, uint8_t RecordFirstByte,
247266
DataExtractor &RecordExtractor,
248-
size_t &RecordSize) {
267+
size_t &RecordSize,
268+
std::vector<XRayRecord> &Records) {
249269
// The remaining 7 bits are the RecordKind enum.
250270
uint8_t RecordKind = RecordFirstByte >> 1;
251271
switch (RecordKind) {
@@ -279,6 +299,11 @@ Error processFDRMetadataRecord(FDRState &State, uint8_t RecordFirstByte,
279299
RecordExtractor, RecordSize))
280300
return E;
281301
break;
302+
case 6: // CallArgument
303+
if (auto E = processFDRCallArgumentRecord(State, RecordFirstByte,
304+
RecordExtractor, Records))
305+
return E;
306+
break;
282307
default:
283308
// Widen the record type to uint16_t to prevent conversion to char.
284309
return make_error<StringError>(
@@ -434,7 +459,7 @@ Error loadFDRLog(StringRef Data, XRayFileHeader &FileHeader,
434459
if (isMetadataRecord) {
435460
RecordSize = 16;
436461
if (auto E = processFDRMetadataRecord(State, BitField, RecordExtractor,
437-
RecordSize))
462+
RecordSize, Records))
438463
return E;
439464
} else { // Process Function Record
440465
RecordSize = 8;
288 Bytes
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; RUN: llvm-xray convert %S/Inputs/fdr-log-arg1.xray -f=yaml -o - | FileCheck %s
2+
3+
; CHECK: ---
4+
; CHECK-NEXT: header:
5+
; CHECK-NEXT: version: 1
6+
; CHECK-NEXT: type: 1
7+
; CHECK-NEXT: constant-tsc: true
8+
; CHECK-NEXT: nonstop-tsc: true
9+
; CHECK-NEXT: cycle-frequency: 3500000000
10+
; CHECK-NEXT: records:
11+
; CHECK-NEXT: - { type: 0, func-id: 1, function: '1', args: [ 1 ], cpu: 49, thread: 14648, kind: function-enter-arg, tsc: 18828908666543318 }
12+
; CHECK-NEXT: - { type: 0, func-id: 1, function: '1', cpu: 49, thread: 14648, kind: function-exit, tsc: 18828908666595604 }
13+
; CHECK-NEXT: ...

tools/llvm-xray/xray-account.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ bool LatencyAccountant::accountRecord(const XRayRecord &Record) {
146146

147147
auto &ThreadStack = PerThreadFunctionStack[Record.TId];
148148
switch (Record.Type) {
149-
case RecordTypes::ENTER: {
149+
case RecordTypes::ENTER:
150+
case RecordTypes::ENTER_ARG: {
150151
ThreadStack.emplace_back(Record.FuncId, Record.TSC);
151152
break;
152153
}

tools/llvm-xray/xray-converter.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void TraceConverter::exportAsYAML(const Trace &Records, raw_ostream &OS) {
8686
Trace.Records.push_back({R.RecordType, R.CPU, R.Type, R.FuncId,
8787
Symbolize ? FuncIdHelper.SymbolOrNumber(R.FuncId)
8888
: llvm::to_string(R.FuncId),
89-
R.TSC, R.TId});
89+
R.TSC, R.TId, R.CallArgs});
9090
}
9191
Output Out(OS, nullptr, 0);
9292
Out << Trace;
@@ -123,6 +123,7 @@ void TraceConverter::exportAsRAWv1(const Trace &Records, raw_ostream &OS) {
123123
Writer.write(static_cast<uint8_t>(R.CPU));
124124
switch (R.Type) {
125125
case RecordTypes::ENTER:
126+
case RecordTypes::ENTER_ARG:
126127
Writer.write(uint8_t{0});
127128
break;
128129
case RecordTypes::EXIT:

tools/llvm-xray/xray-graph.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ Error GraphRenderer::accountRecord(const XRayRecord &Record) {
208208

209209
auto &ThreadStack = PerThreadFunctionStack[Record.TId];
210210
switch (Record.Type) {
211-
case RecordTypes::ENTER: {
211+
case RecordTypes::ENTER:
212+
case RecordTypes::ENTER_ARG: {
212213
if (Record.FuncId != 0 && G.count(Record.FuncId) == 0)
213214
G[Record.FuncId].SymbolName = FuncIdHelper.SymbolOrNumber(Record.FuncId);
214215
ThreadStack.push_back({Record.FuncId, Record.TSC});

0 commit comments

Comments
 (0)