blob: adddb550ecd8ab938f5fb1b15b7b65c702c54873 [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
55Error TraceExpander::visit(CallArgRecord &R) {
56 CurrentRecord.CallArgs.push_back(R.arg());
57 CurrentRecord.Type = RecordTypes::ENTER_ARG;
58 return Error::success();
59}
60
61Error TraceExpander::visit(PIDRecord &R) {
62 PID = R.pid();
63 return Error::success();
64}
65
66Error TraceExpander::visit(NewBufferRecord &R) {
67 if (IgnoringRecords)
68 IgnoringRecords = false;
69 TID = R.tid();
70 if (LogVersion == 2)
71 PID = R.tid();
72 return Error::success();
73}
74
75Error TraceExpander::visit(EndBufferRecord &) {
76 IgnoringRecords = true;
77 resetCurrentRecord();
78 return Error::success();
79}
80
81Error TraceExpander::visit(FunctionRecord &R) {
82 resetCurrentRecord();
83 if (!IgnoringRecords) {
84 BaseTSC += R.delta();
85 CurrentRecord.Type = R.recordType();
86 CurrentRecord.FuncId = R.functionId();
87 CurrentRecord.TSC = BaseTSC;
88 CurrentRecord.PId = PID;
89 CurrentRecord.TId = TID;
90 CurrentRecord.CPU = CPUId;
Dean Michael Berris25f8d202018-11-06 08:51:37 +000091 BuildingRecord = true;
Dean Michael Berris985c2b92018-09-11 06:45:59 +000092 }
93 return Error::success();
94}
95
96Error TraceExpander::flush() {
97 resetCurrentRecord();
98 return Error::success();
99}
100
101} // namespace xray
102} // namespace llvm