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() { |
| 15 | if (BuildingFunction) |
| 16 | C(CurrentRecord); |
| 17 | BuildingFunction = false; |
| 18 | CurrentRecord.CallArgs.clear(); |
| 19 | } |
| 20 | |
| 21 | Error TraceExpander::visit(BufferExtents &) { |
| 22 | resetCurrentRecord(); |
| 23 | return Error::success(); |
| 24 | } |
| 25 | |
| 26 | Error TraceExpander::visit(WallclockRecord &) { return Error::success(); } |
| 27 | |
| 28 | Error TraceExpander::visit(NewCPUIDRecord &R) { |
| 29 | CPUId = R.cpuid(); |
| 30 | BaseTSC = R.tsc(); |
| 31 | return Error::success(); |
| 32 | } |
| 33 | |
| 34 | Error TraceExpander::visit(TSCWrapRecord &R) { |
| 35 | BaseTSC = R.tsc(); |
| 36 | return Error::success(); |
| 37 | } |
| 38 | |
| 39 | Error TraceExpander::visit(CustomEventRecord &) { |
| 40 | // TODO: Support custom event records in the future. |
| 41 | resetCurrentRecord(); |
| 42 | return Error::success(); |
| 43 | } |
| 44 | |
| 45 | Error TraceExpander::visit(CallArgRecord &R) { |
| 46 | CurrentRecord.CallArgs.push_back(R.arg()); |
| 47 | CurrentRecord.Type = RecordTypes::ENTER_ARG; |
| 48 | return Error::success(); |
| 49 | } |
| 50 | |
| 51 | Error TraceExpander::visit(PIDRecord &R) { |
| 52 | PID = R.pid(); |
| 53 | return Error::success(); |
| 54 | } |
| 55 | |
| 56 | Error TraceExpander::visit(NewBufferRecord &R) { |
| 57 | if (IgnoringRecords) |
| 58 | IgnoringRecords = false; |
| 59 | TID = R.tid(); |
| 60 | if (LogVersion == 2) |
| 61 | PID = R.tid(); |
| 62 | return Error::success(); |
| 63 | } |
| 64 | |
| 65 | Error TraceExpander::visit(EndBufferRecord &) { |
| 66 | IgnoringRecords = true; |
| 67 | resetCurrentRecord(); |
| 68 | return Error::success(); |
| 69 | } |
| 70 | |
| 71 | Error TraceExpander::visit(FunctionRecord &R) { |
| 72 | resetCurrentRecord(); |
| 73 | if (!IgnoringRecords) { |
| 74 | BaseTSC += R.delta(); |
| 75 | CurrentRecord.Type = R.recordType(); |
| 76 | CurrentRecord.FuncId = R.functionId(); |
| 77 | CurrentRecord.TSC = BaseTSC; |
| 78 | CurrentRecord.PId = PID; |
| 79 | CurrentRecord.TId = TID; |
| 80 | CurrentRecord.CPU = CPUId; |
| 81 | BuildingFunction = true; |
| 82 | } |
| 83 | return Error::success(); |
| 84 | } |
| 85 | |
| 86 | Error TraceExpander::flush() { |
| 87 | resetCurrentRecord(); |
| 88 | return Error::success(); |
| 89 | } |
| 90 | |
| 91 | } // namespace xray |
| 92 | } // namespace llvm |