Dean Michael Berris | 935f117 | 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 | b92b0b8 | 2018-11-06 08:51:37 +0000 | [diff] [blame] | 15 | if (BuildingRecord) |
Dean Michael Berris | 935f117 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 16 | C(CurrentRecord); |
Dean Michael Berris | b92b0b8 | 2018-11-06 08:51:37 +0000 | [diff] [blame] | 17 | BuildingRecord = false; |
Dean Michael Berris | 935f117 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 18 | CurrentRecord.CallArgs.clear(); |
Dean Michael Berris | b92b0b8 | 2018-11-06 08:51:37 +0000 | [diff] [blame] | 19 | CurrentRecord.Data.clear(); |
Dean Michael Berris | 935f117 | 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 | b92b0b8 | 2018-11-06 08:51:37 +0000 | [diff] [blame] | 40 | Error TraceExpander::visit(CustomEventRecord &R) { |
Dean Michael Berris | 935f117 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 41 | resetCurrentRecord(); |
Dean Michael Berris | b92b0b8 | 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; |
Dean Michael Berris | 20a6832 | 2018-11-07 11:44:00 +0000 | [diff] [blame] | 48 | CurrentRecord.Data = R.data(); |
Dean Michael Berris | b92b0b8 | 2018-11-06 08:51:37 +0000 | [diff] [blame] | 49 | BuildingRecord = true; |
| 50 | } |
Dean Michael Berris | 935f117 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 51 | return Error::success(); |
| 52 | } |
| 53 | |
Dean Michael Berris | 8fa10fd | 2018-11-07 04:37:42 +0000 | [diff] [blame] | 54 | Error 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 Berris | b44657a | 2018-11-07 11:52:22 +0000 | [diff] [blame] | 63 | CurrentRecord.Data = R.data(); |
Dean Michael Berris | 8fa10fd | 2018-11-07 04:37:42 +0000 | [diff] [blame] | 64 | BuildingRecord = true; |
| 65 | } |
| 66 | return Error::success(); |
| 67 | } |
| 68 | |
| 69 | Error 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 Berris | b44657a | 2018-11-07 11:52:22 +0000 | [diff] [blame] | 79 | CurrentRecord.Data = R.data(); |
Dean Michael Berris | 8fa10fd | 2018-11-07 04:37:42 +0000 | [diff] [blame] | 80 | BuildingRecord = true; |
| 81 | } |
| 82 | return Error::success(); |
| 83 | } |
| 84 | |
Dean Michael Berris | 935f117 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 85 | Error TraceExpander::visit(CallArgRecord &R) { |
| 86 | CurrentRecord.CallArgs.push_back(R.arg()); |
| 87 | CurrentRecord.Type = RecordTypes::ENTER_ARG; |
| 88 | return Error::success(); |
| 89 | } |
| 90 | |
| 91 | Error TraceExpander::visit(PIDRecord &R) { |
| 92 | PID = R.pid(); |
| 93 | return Error::success(); |
| 94 | } |
| 95 | |
| 96 | Error 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 | |
| 105 | Error TraceExpander::visit(EndBufferRecord &) { |
| 106 | IgnoringRecords = true; |
| 107 | resetCurrentRecord(); |
| 108 | return Error::success(); |
| 109 | } |
| 110 | |
| 111 | Error 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 Berris | b92b0b8 | 2018-11-06 08:51:37 +0000 | [diff] [blame] | 121 | BuildingRecord = true; |
Dean Michael Berris | 935f117 | 2018-09-11 06:45:59 +0000 | [diff] [blame] | 122 | } |
| 123 | return Error::success(); |
| 124 | } |
| 125 | |
| 126 | Error TraceExpander::flush() { |
| 127 | resetCurrentRecord(); |
| 128 | return Error::success(); |
| 129 | } |
| 130 | |
| 131 | } // namespace xray |
| 132 | } // namespace llvm |