reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
//===- FDRTraceExpander.cpp -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "llvm/XRay/FDRTraceExpander.h"

namespace llvm {
namespace xray {

void TraceExpander::resetCurrentRecord() {
  if (BuildingRecord)
    C(CurrentRecord);
  BuildingRecord = false;
  CurrentRecord.CallArgs.clear();
  CurrentRecord.Data.clear();
}

Error TraceExpander::visit(BufferExtents &) {
  resetCurrentRecord();
  return Error::success();
}

Error TraceExpander::visit(WallclockRecord &) { return Error::success(); }

Error TraceExpander::visit(NewCPUIDRecord &R) {
  CPUId = R.cpuid();
  BaseTSC = R.tsc();
  return Error::success();
}

Error TraceExpander::visit(TSCWrapRecord &R) {
  BaseTSC = R.tsc();
  return Error::success();
}

Error TraceExpander::visit(CustomEventRecord &R) {
  resetCurrentRecord();
  if (!IgnoringRecords) {
    CurrentRecord.TSC = R.tsc();
    CurrentRecord.CPU = R.cpu();
    CurrentRecord.PId = PID;
    CurrentRecord.TId = TID;
    CurrentRecord.Type = RecordTypes::CUSTOM_EVENT;
    CurrentRecord.Data = R.data();
    BuildingRecord = true;
  }
  return Error::success();
}

Error TraceExpander::visit(CustomEventRecordV5 &R) {
  resetCurrentRecord();
  if (!IgnoringRecords) {
    BaseTSC += R.delta();
    CurrentRecord.TSC = BaseTSC;
    CurrentRecord.CPU = CPUId;
    CurrentRecord.PId = PID;
    CurrentRecord.TId = TID;
    CurrentRecord.Type = RecordTypes::CUSTOM_EVENT;
    CurrentRecord.Data = R.data();
    BuildingRecord = true;
  }
  return Error::success();
}

Error TraceExpander::visit(TypedEventRecord &R) {
  resetCurrentRecord();
  if (!IgnoringRecords) {
    BaseTSC += R.delta();
    CurrentRecord.TSC = BaseTSC;
    CurrentRecord.CPU = CPUId;
    CurrentRecord.PId = PID;
    CurrentRecord.TId = TID;
    CurrentRecord.RecordType = R.eventType();
    CurrentRecord.Type = RecordTypes::TYPED_EVENT;
    CurrentRecord.Data = R.data();
    BuildingRecord = true;
  }
  return Error::success();
}

Error TraceExpander::visit(CallArgRecord &R) {
  CurrentRecord.CallArgs.push_back(R.arg());
  CurrentRecord.Type = RecordTypes::ENTER_ARG;
  return Error::success();
}

Error TraceExpander::visit(PIDRecord &R) {
  PID = R.pid();
  return Error::success();
}

Error TraceExpander::visit(NewBufferRecord &R) {
  if (IgnoringRecords)
    IgnoringRecords = false;
  TID = R.tid();
  if (LogVersion == 2)
    PID = R.tid();
  return Error::success();
}

Error TraceExpander::visit(EndBufferRecord &) {
  IgnoringRecords = true;
  resetCurrentRecord();
  return Error::success();
}

Error TraceExpander::visit(FunctionRecord &R) {
  resetCurrentRecord();
  if (!IgnoringRecords) {
    BaseTSC += R.delta();
    CurrentRecord.Type = R.recordType();
    CurrentRecord.FuncId = R.functionId();
    CurrentRecord.TSC = BaseTSC;
    CurrentRecord.PId = PID;
    CurrentRecord.TId = TID;
    CurrentRecord.CPU = CPUId;
    BuildingRecord = true;
  }
  return Error::success();
}

Error TraceExpander::flush() {
  resetCurrentRecord();
  return Error::success();
}

} // namespace xray
} // namespace llvm