blob: 8e15db52ce6ce9347516729ff2ae64b34acbfff5 [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() {
15 if (BuildingFunction)
16 C(CurrentRecord);
17 BuildingFunction = false;
18 CurrentRecord.CallArgs.clear();
19}
20
21Error TraceExpander::visit(BufferExtents &) {
22 resetCurrentRecord();
23 return Error::success();
24}
25
26Error TraceExpander::visit(WallclockRecord &) { return Error::success(); }
27
28Error TraceExpander::visit(NewCPUIDRecord &R) {
29 CPUId = R.cpuid();
30 BaseTSC = R.tsc();
31 return Error::success();
32}
33
34Error TraceExpander::visit(TSCWrapRecord &R) {
35 BaseTSC = R.tsc();
36 return Error::success();
37}
38
39Error TraceExpander::visit(CustomEventRecord &) {
40 // TODO: Support custom event records in the future.
41 resetCurrentRecord();
42 return Error::success();
43}
44
45Error TraceExpander::visit(CallArgRecord &R) {
46 CurrentRecord.CallArgs.push_back(R.arg());
47 CurrentRecord.Type = RecordTypes::ENTER_ARG;
48 return Error::success();
49}
50
51Error TraceExpander::visit(PIDRecord &R) {
52 PID = R.pid();
53 return Error::success();
54}
55
56Error 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
65Error TraceExpander::visit(EndBufferRecord &) {
66 IgnoringRecords = true;
67 resetCurrentRecord();
68 return Error::success();
69}
70
71Error 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
86Error TraceExpander::flush() {
87 resetCurrentRecord();
88 return Error::success();
89}
90
91} // namespace xray
92} // namespace llvm