Index: include/llvm/XRay/XRayRecord.h =================================================================== --- include/llvm/XRay/XRayRecord.h +++ include/llvm/XRay/XRayRecord.h @@ -14,9 +14,9 @@ #ifndef LLVM_XRAY_XRAY_RECORD_H #define LLVM_XRAY_XRAY_RECORD_H +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" #include -#include -#include namespace llvm { namespace xray { @@ -54,7 +54,7 @@ /// This may or may not correspond to actual record types in the raw trace (as /// the loader implementation may synthesize this information in the process of /// of loading). -enum class RecordTypes { +enum class RecordTypes : uint8_t { ENTER, EXIT, TAIL_EXIT, @@ -73,8 +73,8 @@ /// the RecordType field. uint16_t RecordType; - /// The CPU where the thread is running. We assume number of CPUs <= 65536. - uint16_t CPU; + /// The CPU where the thread is running. We assume number of CPUs <= 255. + uint8_t CPU; /// Identifies the type of record. RecordTypes Type; @@ -92,11 +92,14 @@ uint32_t PId; /// The function call arguments. - std::vector CallArgs; + llvm::SmallVector CallArgs; /// For custom and typed events, we provide the raw data from the trace. - std::string Data; + llvm::SmallString<0> Data; }; +static_assert(sizeof(XRayRecord) <= 56, "XRayRecord should be small"); +static_assert(sizeof(XRayRecord) % alignof(XRayRecord) == 0, + "Should not have any padding between two XRayRecord"); } // namespace xray } // namespace llvm Index: include/llvm/XRay/YAMLXRayRecord.h =================================================================== --- include/llvm/XRay/YAMLXRayRecord.h +++ include/llvm/XRay/YAMLXRayRecord.h @@ -30,7 +30,7 @@ struct YAMLXRayRecord { uint16_t RecordType; - uint16_t CPU; + uint8_t CPU; RecordTypes Type; int32_t FuncId; std::string Function; Index: lib/XRay/Trace.cpp =================================================================== --- lib/XRay/Trace.cpp +++ lib/XRay/Trace.cpp @@ -362,9 +362,16 @@ Records.clear(); std::transform(Trace.Records.begin(), Trace.Records.end(), std::back_inserter(Records), [&](const YAMLXRayRecord &R) { - return XRayRecord{R.RecordType, R.CPU, R.Type, - R.FuncId, R.TSC, R.TId, - R.PId, R.CallArgs, R.Data}; + return XRayRecord{R.RecordType, + R.CPU, + R.Type, + R.FuncId, + R.TSC, + R.TId, + R.PId, + llvm::SmallVector{ + R.CallArgs.begin(), R.CallArgs.end()}, + StringRef(R.Data)}; }); return Error::success(); } Index: tools/llvm-xray/xray-converter.cpp =================================================================== --- tools/llvm-xray/xray-converter.cpp +++ tools/llvm-xray/xray-converter.cpp @@ -87,10 +87,11 @@ FH.CycleFrequency}; Trace.Records.reserve(Records.size()); for (const auto &R : Records) { - Trace.Records.push_back({R.RecordType, R.CPU, R.Type, R.FuncId, - Symbolize ? FuncIdHelper.SymbolOrNumber(R.FuncId) - : llvm::to_string(R.FuncId), - R.TSC, R.TId, R.PId, R.CallArgs, R.Data}); + Trace.Records.emplace_back(YAMLXRayRecord{ + R.RecordType, R.CPU, R.Type, R.FuncId, + Symbolize ? FuncIdHelper.SymbolOrNumber(R.FuncId) + : llvm::to_string(R.FuncId), + R.TSC, R.TId, R.PId, ArrayRef(R.CallArgs), R.Data.str()}); } Output Out(OS, nullptr, 0); Out.setWriteDefaultValues(false);