blob: 6fe3f86c3daff57b1cca08b168ce63974406126f [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;
Dean Michael Berris140e76a2018-11-07 11:44:00 +000048 CurrentRecord.Data = R.data();
Dean Michael Berris25f8d202018-11-06 08:51:37 +000049 BuildingRecord = true;
50 }
Dean Michael Berris985c2b92018-09-11 06:45:59 +000051 return Error::success();
52}
53
Dean Michael Berris59439dd2018-11-07 04:37:42 +000054Error TraceExpander::visit(CustomEventRecordV5 &R) {
55 resetCurrentRecord();
56 if (!IgnoringRecords) {
57 BaseTSC += R.delta();
58 CurrentRecord.TSC = BaseTSC;
59 CurrentRecord.CPU = CPUId;
60 CurrentRecord.PId = PID;
61 CurrentRecord.TId = TID;
62 CurrentRecord.Type = RecordTypes::CUSTOM_EVENT;
63 std::copy(R.data().begin(), R.data().end(),
64 std::back_inserter(CurrentRecord.Data));
65 BuildingRecord = true;
66 }
67 return Error::success();
68}
69
70Error TraceExpander::visit(TypedEventRecord &R) {
71 resetCurrentRecord();
72 if (!IgnoringRecords) {
73 BaseTSC += R.delta();
74 CurrentRecord.TSC = BaseTSC;
75 CurrentRecord.CPU = CPUId;
76 CurrentRecord.PId = PID;
77 CurrentRecord.TId = TID;
78 CurrentRecord.RecordType = R.eventType();
79 CurrentRecord.Type = RecordTypes::TYPED_EVENT;
80 std::copy(R.data().begin(), R.data().end(),
81 std::back_inserter(CurrentRecord.Data));
82 BuildingRecord = true;
83 }
84 return Error::success();
85}
86
Dean Michael Berris985c2b92018-09-11 06:45:59 +000087Error TraceExpander::visit(CallArgRecord &R) {
88 CurrentRecord.CallArgs.push_back(R.arg());
89 CurrentRecord.Type = RecordTypes::ENTER_ARG;
90 return Error::success();
91}
92
93Error TraceExpander::visit(PIDRecord &R) {
94 PID = R.pid();
95 return Error::success();
96}
97
98Error TraceExpander::visit(NewBufferRecord &R) {
99 if (IgnoringRecords)
100 IgnoringRecords = false;
101 TID = R.tid();
102 if (LogVersion == 2)
103 PID = R.tid();
104 return Error::success();
105}
106
107Error TraceExpander::visit(EndBufferRecord &) {
108 IgnoringRecords = true;
109 resetCurrentRecord();
110 return Error::success();
111}
112
113Error TraceExpander::visit(FunctionRecord &R) {
114 resetCurrentRecord();
115 if (!IgnoringRecords) {
116 BaseTSC += R.delta();
117 CurrentRecord.Type = R.recordType();
118 CurrentRecord.FuncId = R.functionId();
119 CurrentRecord.TSC = BaseTSC;
120 CurrentRecord.PId = PID;
121 CurrentRecord.TId = TID;
122 CurrentRecord.CPU = CPUId;
Dean Michael Berris25f8d202018-11-06 08:51:37 +0000123 BuildingRecord = true;
Dean Michael Berris985c2b92018-09-11 06:45:59 +0000124 }
125 return Error::success();
126}
127
128Error TraceExpander::flush() {
129 resetCurrentRecord();
130 return Error::success();
131}
132
133} // namespace xray
134} // namespace llvm