blob: a6e1521da87f340a1e8a82bc85fd8e5de09b0f72 [file] [log] [blame]
Dean Michael Berris935f1172018-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 Berrisb92b0b82018-11-06 08:51:37 +000015 if (BuildingRecord)
Dean Michael Berris935f1172018-09-11 06:45:59 +000016 C(CurrentRecord);
Dean Michael Berrisb92b0b82018-11-06 08:51:37 +000017 BuildingRecord = false;
Dean Michael Berris935f1172018-09-11 06:45:59 +000018 CurrentRecord.CallArgs.clear();
Dean Michael Berrisb92b0b82018-11-06 08:51:37 +000019 CurrentRecord.Data.clear();
Dean Michael Berris935f1172018-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 Berrisb92b0b82018-11-06 08:51:37 +000040Error TraceExpander::visit(CustomEventRecord &R) {
Dean Michael Berris935f1172018-09-11 06:45:59 +000041 resetCurrentRecord();
Dean Michael Berrisb92b0b82018-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 Berris20a68322018-11-07 11:44:00 +000048 CurrentRecord.Data = R.data();
Dean Michael Berrisb92b0b82018-11-06 08:51:37 +000049 BuildingRecord = true;
50 }
Dean Michael Berris935f1172018-09-11 06:45:59 +000051 return Error::success();
52}
53
Dean Michael Berris8fa10fd2018-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;
Dean Michael Berrisb44657a2018-11-07 11:52:22 +000063 CurrentRecord.Data = R.data();
Dean Michael Berris8fa10fd2018-11-07 04:37:42 +000064 BuildingRecord = true;
65 }
66 return Error::success();
67}
68
69Error TraceExpander::visit(TypedEventRecord &R) {
70 resetCurrentRecord();
71 if (!IgnoringRecords) {
72 BaseTSC += R.delta();
73 CurrentRecord.TSC = BaseTSC;
74 CurrentRecord.CPU = CPUId;
75 CurrentRecord.PId = PID;
76 CurrentRecord.TId = TID;
77 CurrentRecord.RecordType = R.eventType();
78 CurrentRecord.Type = RecordTypes::TYPED_EVENT;
Dean Michael Berrisb44657a2018-11-07 11:52:22 +000079 CurrentRecord.Data = R.data();
Dean Michael Berris8fa10fd2018-11-07 04:37:42 +000080 BuildingRecord = true;
81 }
82 return Error::success();
83}
84
Dean Michael Berris935f1172018-09-11 06:45:59 +000085Error TraceExpander::visit(CallArgRecord &R) {
86 CurrentRecord.CallArgs.push_back(R.arg());
87 CurrentRecord.Type = RecordTypes::ENTER_ARG;
88 return Error::success();
89}
90
91Error TraceExpander::visit(PIDRecord &R) {
92 PID = R.pid();
93 return Error::success();
94}
95
96Error TraceExpander::visit(NewBufferRecord &R) {
97 if (IgnoringRecords)
98 IgnoringRecords = false;
99 TID = R.tid();
100 if (LogVersion == 2)
101 PID = R.tid();
102 return Error::success();
103}
104
105Error TraceExpander::visit(EndBufferRecord &) {
106 IgnoringRecords = true;
107 resetCurrentRecord();
108 return Error::success();
109}
110
111Error TraceExpander::visit(FunctionRecord &R) {
112 resetCurrentRecord();
113 if (!IgnoringRecords) {
114 BaseTSC += R.delta();
115 CurrentRecord.Type = R.recordType();
116 CurrentRecord.FuncId = R.functionId();
117 CurrentRecord.TSC = BaseTSC;
118 CurrentRecord.PId = PID;
119 CurrentRecord.TId = TID;
120 CurrentRecord.CPU = CPUId;
Dean Michael Berrisb92b0b82018-11-06 08:51:37 +0000121 BuildingRecord = true;
Dean Michael Berris935f1172018-09-11 06:45:59 +0000122 }
123 return Error::success();
124}
125
126Error TraceExpander::flush() {
127 resetCurrentRecord();
128 return Error::success();
129}
130
131} // namespace xray
132} // namespace llvm