blob: e67f4b5d89f38429a8c751640ce930417661392b [file] [log] [blame]
Dean Michael Berris985c2b92018-09-11 06:45:59 +00001//===- FDRTraceExpander.cpp -----------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9#include "llvm/XRay/FDRTraceExpander.h"
10
11namespace llvm {
12namespace xray {
13
14void TraceExpander::resetCurrentRecord() {
Dean Michael Berris25f8d202018-11-06 08:51:37 +000015 if (BuildingRecord)
Dean Michael Berris985c2b92018-09-11 06:45:59 +000016 C(CurrentRecord);
Dean Michael Berris25f8d202018-11-06 08:51:37 +000017 BuildingRecord = false;
Dean Michael Berris985c2b92018-09-11 06:45:59 +000018 CurrentRecord.CallArgs.clear();
Dean Michael Berris25f8d202018-11-06 08:51:37 +000019 CurrentRecord.Data.clear();
Dean Michael Berris985c2b92018-09-11 06:45:59 +000020}
21
22Error TraceExpander::visit(BufferExtents &) {
23 resetCurrentRecord();
24 return Error::success();
25}
26
27Error TraceExpander::visit(WallclockRecord &) { return Error::success(); }
28
29Error TraceExpander::visit(NewCPUIDRecord &R) {
30 CPUId = R.cpuid();
31 BaseTSC = R.tsc();
32 return Error::success();
33}
34
35Error TraceExpander::visit(TSCWrapRecord &R) {
36 BaseTSC = R.tsc();
37 return Error::success();
38}
39
Dean Michael Berris25f8d202018-11-06 08:51:37 +000040Error TraceExpander::visit(CustomEventRecord &R) {
Dean Michael Berris985c2b92018-09-11 06:45:59 +000041 resetCurrentRecord();
Dean Michael Berris25f8d202018-11-06 08:51:37 +000042 if (!IgnoringRecords) {
43 CurrentRecord.TSC = R.tsc();
44 CurrentRecord.CPU = R.cpu();
45 CurrentRecord.PId = PID;
46 CurrentRecord.TId = TID;
47 CurrentRecord.Type = RecordTypes::CUSTOM_EVENT;
48 std::copy(R.data().begin(), R.data().end(),
49 std::back_inserter(CurrentRecord.Data));
50 BuildingRecord = true;
51 }
Dean Michael Berris985c2b92018-09-11 06:45:59 +000052 return Error::success();
53}
54
Dean Michael Berris59439dd2018-11-07 04:37:42 +000055Error TraceExpander::visit(CustomEventRecordV5 &R) {
56 resetCurrentRecord();
57 if (!IgnoringRecords) {
58 BaseTSC += R.delta();
59 CurrentRecord.TSC = BaseTSC;
60 CurrentRecord.CPU = CPUId;
61 CurrentRecord.PId = PID;
62 CurrentRecord.TId = TID;
63 CurrentRecord.Type = RecordTypes::CUSTOM_EVENT;
64 std::copy(R.data().begin(), R.data().end(),
65 std::back_inserter(CurrentRecord.Data));
66 BuildingRecord = true;
67 }
68 return Error::success();
69}
70
71Error TraceExpander::visit(TypedEventRecord &R) {
72 resetCurrentRecord();
73 if (!IgnoringRecords) {
74 BaseTSC += R.delta();
75 CurrentRecord.TSC = BaseTSC;
76 CurrentRecord.CPU = CPUId;
77 CurrentRecord.PId = PID;
78 CurrentRecord.TId = TID;
79 CurrentRecord.RecordType = R.eventType();
80 CurrentRecord.Type = RecordTypes::TYPED_EVENT;
81 std::copy(R.data().begin(), R.data().end(),
82 std::back_inserter(CurrentRecord.Data));
83 BuildingRecord = true;
84 }
85 return Error::success();
86}
87
Dean Michael Berris985c2b92018-09-11 06:45:59 +000088Error TraceExpander::visit(CallArgRecord &R) {
89 CurrentRecord.CallArgs.push_back(R.arg());
90 CurrentRecord.Type = RecordTypes::ENTER_ARG;
91 return Error::success();
92}
93
94Error TraceExpander::visit(PIDRecord &R) {
95 PID = R.pid();
96 return Error::success();
97}
98
99Error TraceExpander::visit(NewBufferRecord &R) {
100 if (IgnoringRecords)
101 IgnoringRecords = false;
102 TID = R.tid();
103 if (LogVersion == 2)
104 PID = R.tid();
105 return Error::success();
106}
107
108Error TraceExpander::visit(EndBufferRecord &) {
109 IgnoringRecords = true;
110 resetCurrentRecord();
111 return Error::success();
112}
113
114Error TraceExpander::visit(FunctionRecord &R) {
115 resetCurrentRecord();
116 if (!IgnoringRecords) {
117 BaseTSC += R.delta();
118 CurrentRecord.Type = R.recordType();
119 CurrentRecord.FuncId = R.functionId();
120 CurrentRecord.TSC = BaseTSC;
121 CurrentRecord.PId = PID;
122 CurrentRecord.TId = TID;
123 CurrentRecord.CPU = CPUId;
Dean Michael Berris25f8d202018-11-06 08:51:37 +0000124 BuildingRecord = true;
Dean Michael Berris985c2b92018-09-11 06:45:59 +0000125 }
126 return Error::success();
127}
128
129Error TraceExpander::flush() {
130 resetCurrentRecord();
131 return Error::success();
132}
133
134} // namespace xray
135} // namespace llvm