Dean Michael Berris | 985c2b9 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 1 | //===- 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 | |
| 11 | namespace llvm { |
| 12 | namespace xray { |
| 13 | |
| 14 | void TraceExpander::resetCurrentRecord() { |
Dean Michael Berris | 25f8d20 | 2018-11-06 08:51:37 +0000 | [diff] [blame] | 15 | if (BuildingRecord) |
Dean Michael Berris | 985c2b9 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 16 | C(CurrentRecord); |
Dean Michael Berris | 25f8d20 | 2018-11-06 08:51:37 +0000 | [diff] [blame] | 17 | BuildingRecord = false; |
Dean Michael Berris | 985c2b9 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 18 | CurrentRecord.CallArgs.clear(); |
Dean Michael Berris | 25f8d20 | 2018-11-06 08:51:37 +0000 | [diff] [blame] | 19 | CurrentRecord.Data.clear(); |
Dean Michael Berris | 985c2b9 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | Error TraceExpander::visit(BufferExtents &) { |
| 23 | resetCurrentRecord(); |
| 24 | return Error::success(); |
| 25 | } |
| 26 | |
| 27 | Error TraceExpander::visit(WallclockRecord &) { return Error::success(); } |
| 28 | |
| 29 | Error TraceExpander::visit(NewCPUIDRecord &R) { |
| 30 | CPUId = R.cpuid(); |
| 31 | BaseTSC = R.tsc(); |
| 32 | return Error::success(); |
| 33 | } |
| 34 | |
| 35 | Error TraceExpander::visit(TSCWrapRecord &R) { |
| 36 | BaseTSC = R.tsc(); |
| 37 | return Error::success(); |
| 38 | } |
| 39 | |
Dean Michael Berris | 25f8d20 | 2018-11-06 08:51:37 +0000 | [diff] [blame] | 40 | Error TraceExpander::visit(CustomEventRecord &R) { |
Dean Michael Berris | 985c2b9 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 41 | resetCurrentRecord(); |
Dean Michael Berris | 25f8d20 | 2018-11-06 08:51:37 +0000 | [diff] [blame] | 42 | 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 Berris | 985c2b9 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 52 | return Error::success(); |
| 53 | } |
| 54 | |
Dean Michael Berris | 59439dd | 2018-11-07 04:37:42 +0000 | [diff] [blame^] | 55 | Error 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 | |
| 71 | Error 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 Berris | 985c2b9 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 88 | Error TraceExpander::visit(CallArgRecord &R) { |
| 89 | CurrentRecord.CallArgs.push_back(R.arg()); |
| 90 | CurrentRecord.Type = RecordTypes::ENTER_ARG; |
| 91 | return Error::success(); |
| 92 | } |
| 93 | |
| 94 | Error TraceExpander::visit(PIDRecord &R) { |
| 95 | PID = R.pid(); |
| 96 | return Error::success(); |
| 97 | } |
| 98 | |
| 99 | Error 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 | |
| 108 | Error TraceExpander::visit(EndBufferRecord &) { |
| 109 | IgnoringRecords = true; |
| 110 | resetCurrentRecord(); |
| 111 | return Error::success(); |
| 112 | } |
| 113 | |
| 114 | Error 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 Berris | 25f8d20 | 2018-11-06 08:51:37 +0000 | [diff] [blame] | 124 | BuildingRecord = true; |
Dean Michael Berris | 985c2b9 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 125 | } |
| 126 | return Error::success(); |
| 127 | } |
| 128 | |
| 129 | Error TraceExpander::flush() { |
| 130 | resetCurrentRecord(); |
| 131 | return Error::success(); |
| 132 | } |
| 133 | |
| 134 | } // namespace xray |
| 135 | } // namespace llvm |