LLVM  5.0.0
Classes | Typedefs | Functions
Trace.cpp File Reference
#include "llvm/XRay/Trace.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/XRay/YAMLXRayRecord.h"
Include dependency graph for Trace.cpp:

Go to the source code of this file.

Classes

struct  FDRState
 When reading from a Flight Data Recorder mode log, metadata records are sparse compared to packed function records, so we must maintain state as we read through the sequence of entries. More...
 

Typedefs

using XRayRecordStorage = std::aligned_storage< sizeof(XRayRecord), alignof(XRayRecord)>::type
 

Functions

Error readBinaryFormatHeader (StringRef Data, XRayFileHeader &FileHeader)
 
Error loadNaiveFormatLog (StringRef Data, XRayFileHeader &FileHeader, std::vector< XRayRecord > &Records)
 
Twine fdrStateToTwine (const FDRState::Token &state)
 
Error processFDRNewBufferRecord (FDRState &State, uint8_t RecordFirstByte, DataExtractor &RecordExtractor)
 State transition when a NewBufferRecord is encountered. More...
 
Error processFDREndOfBufferRecord (FDRState &State, uint8_t RecordFirstByte, DataExtractor &RecordExtractor)
 State transition when an EndOfBufferRecord is encountered. More...
 
Error processFDRNewCPUIdRecord (FDRState &State, uint8_t RecordFirstByte, DataExtractor &RecordExtractor)
 State transition when a NewCPUIdRecord is encountered. More...
 
Error processFDRTSCWrapRecord (FDRState &State, uint8_t RecordFirstByte, DataExtractor &RecordExtractor)
 State transition when a TSCWrapRecord (overflow detection) is encountered. More...
 
Error processFDRWallTimeRecord (FDRState &State, uint8_t RecordFirstByte, DataExtractor &RecordExtractor)
 State transition when a WallTimeMarkerRecord is encountered. More...
 
Error processCustomEventMarker (FDRState &State, uint8_t RecordFirstByte, DataExtractor &RecordExtractor, size_t &RecordSize)
 State transition when a CustomEventMarker is encountered. More...
 
Error processFDRMetadataRecord (FDRState &State, uint8_t RecordFirstByte, DataExtractor &RecordExtractor, size_t &RecordSize)
 Advances the state machine for reading the FDR record type by reading one Metadata Record and updating the State appropriately based on the kind of record encountered. More...
 
Error processFDRFunctionRecord (FDRState &State, uint8_t RecordFirstByte, DataExtractor &RecordExtractor, std::vector< XRayRecord > &Records)
 Reads a function record from an FDR format log, appending a new XRayRecord to the vector being populated and updating the State with a new value reference value to interpret TSC deltas. More...
 
Error loadFDRLog (StringRef Data, XRayFileHeader &FileHeader, std::vector< XRayRecord > &Records)
 Reads a log in FDR mode for version 1 of this binary format. More...
 
Error loadYAMLLog (StringRef Data, XRayFileHeader &FileHeader, std::vector< XRayRecord > &Records)
 

Typedef Documentation

using XRayRecordStorage = std::aligned_storage<sizeof(XRayRecord), alignof(XRayRecord)>::type

Definition at line 25 of file Trace.cpp.

Function Documentation

Twine fdrStateToTwine ( const FDRState::Token &  state)
Error loadFDRLog ( StringRef  Data,
XRayFileHeader &  FileHeader,
std::vector< XRayRecord > &  Records 
)

Reads a log in FDR mode for version 1 of this binary format.

FDR mode is defined as part of the compiler-rt project in xray_fdr_logging.h, and such a log consists of the familiar 32 bit XRayHeader, followed by sequences of of interspersed 16 byte Metadata Records and 8 byte Function Records.

The following is an attempt to document the grammar of the format, which is parsed by this function for little-endian machines. Since the format makes use of BitFields, when we support big-Endian architectures, we will need to adjust not only the endianness parameter to llvm's RecordExtractor, but also the bit twiddling logic, which is consistent with the little-endian convention that BitFields within a struct will first be packed into the least significant bits the address they belong to.

We expect a format complying with the grammar in the following pseudo-EBNF.

FDRLog: XRayFileHeader ThreadBuffer* XRayFileHeader: 32 bits to identify the log as FDR with machine metadata. ThreadBuffer: BufSize NewBuffer WallClockTime NewCPUId FunctionSequence EOB BufSize: 8 byte unsigned integer indicating how large the buffer is. NewBuffer: 16 byte metadata record with Thread Id. WallClockTime: 16 byte metadata record with human readable time. NewCPUId: 16 byte metadata record with CPUId and a 64 bit TSC reading. EOB: 16 byte record in a thread buffer plus mem garbage to fill BufSize. FunctionSequence: NewCPUId | TSCWrap | FunctionRecord TSCWrap: 16 byte metadata record with a full 64 bit TSC reading. FunctionRecord: 8 byte record with FunctionId, entry/exit, and TSC delta.

Definition at line 382 of file Trace.cpp.

References llvm::StringRef::drop_front(), E, llvm::StringRef::empty(), fdrStateToTwine(), llvm::xray::XRayFileHeader::FreeFormData, llvm::DataExtractor::getU64(), llvm::DataExtractor::getU8(), llvm::make_error_code(), FDRState::NEW_BUFFER_RECORD_OR_EOF, processFDRFunctionRecord(), processFDRMetadataRecord(), readBinaryFormatHeader(), FDRState::SCAN_TO_END_OF_THREAD_BUF, llvm::StringRef::size(), and llvm::Error::success().

Referenced by llvm::xray::loadTraceFile().

Error loadNaiveFormatLog ( StringRef  Data,
XRayFileHeader &  FileHeader,
std::vector< XRayRecord > &  Records 
)
Error loadYAMLLog ( StringRef  Data,
XRayFileHeader &  FileHeader,
std::vector< XRayRecord > &  Records 
)
Error processCustomEventMarker ( FDRState &  State,
uint8_t  RecordFirstByte,
DataExtractor &  RecordExtractor,
size_t &  RecordSize 
)

State transition when a CustomEventMarker is encountered.

Definition at line 221 of file Trace.cpp.

References llvm::DataExtractor::getU32(), llvm::DataExtractor::getU64(), and llvm::Error::success().

Referenced by processFDRMetadataRecord().

Error processFDREndOfBufferRecord ( FDRState &  State,
uint8_t  RecordFirstByte,
DataExtractor &  RecordExtractor 
)

State transition when an EndOfBufferRecord is encountered.

Definition at line 170 of file Trace.cpp.

References FDRState::Expects, llvm::make_error_code(), FDRState::NEW_BUFFER_RECORD_OR_EOF, FDRState::SCAN_TO_END_OF_THREAD_BUF, and llvm::Error::success().

Referenced by processFDRMetadataRecord().

Error processFDRFunctionRecord ( FDRState &  State,
uint8_t  RecordFirstByte,
DataExtractor &  RecordExtractor,
std::vector< XRayRecord > &  Records 
)

Reads a function record from an FDR format log, appending a new XRayRecord to the vector being populated and updating the State with a new value reference value to interpret TSC deltas.

The XRayRecord constructed includes information from the function record processed here as well as Thread ID and CPU ID formerly extracted into State.

Definition at line 296 of file Trace.cpp.

References FDRState::BaseTSC, llvm::Twine::concat(), FDRState::CPUId, llvm::xray::ENTER, llvm::xray::EXIT, FDRState::Expects, llvm::DataExtractor::getU32(), llvm::make_error_code(), FDRState::NEW_BUFFER_RECORD_OR_EOF, FDRState::NEW_CPU_ID_RECORD, llvm::Error::success(), FDRState::ThreadId, and FDRState::WALLCLOCK_RECORD.

Referenced by loadFDRLog().

Error processFDRMetadataRecord ( FDRState &  State,
uint8_t  RecordFirstByte,
DataExtractor &  RecordExtractor,
size_t &  RecordSize 
)

Advances the state machine for reading the FDR record type by reading one Metadata Record and updating the State appropriately based on the kind of record encountered.

The RecordKind is encoded in the first byte of the Record, which the caller should pass in because they have already read it to determine that this is a metadata record as opposed to a function record.

Definition at line 243 of file Trace.cpp.

References llvm::Twine::concat(), E, llvm::make_error_code(), processCustomEventMarker(), processFDREndOfBufferRecord(), processFDRNewBufferRecord(), processFDRNewCPUIdRecord(), processFDRTSCWrapRecord(), processFDRWallTimeRecord(), and llvm::Error::success().

Referenced by loadFDRLog().

Error processFDRNewBufferRecord ( FDRState &  State,
uint8_t  RecordFirstByte,
DataExtractor &  RecordExtractor 
)
Error processFDRNewCPUIdRecord ( FDRState &  State,
uint8_t  RecordFirstByte,
DataExtractor &  RecordExtractor 
)
Error processFDRTSCWrapRecord ( FDRState &  State,
uint8_t  RecordFirstByte,
DataExtractor &  RecordExtractor 
)

State transition when a TSCWrapRecord (overflow detection) is encountered.

Definition at line 196 of file Trace.cpp.

References FDRState::BaseTSC, FDRState::Expects, FDRState::FUNCTION_SEQUENCE, llvm::DataExtractor::getU64(), llvm::make_error_code(), and llvm::Error::success().

Referenced by processFDRMetadataRecord().

Error processFDRWallTimeRecord ( FDRState &  State,
uint8_t  RecordFirstByte,
DataExtractor &  RecordExtractor 
)

State transition when a WallTimeMarkerRecord is encountered.

Definition at line 208 of file Trace.cpp.

References FDRState::Expects, llvm::make_error_code(), FDRState::NEW_CPU_ID_RECORD, llvm::Error::success(), and FDRState::WALLCLOCK_RECORD.

Referenced by processFDRMetadataRecord().

Error readBinaryFormatHeader ( StringRef  Data,
XRayFileHeader &  FileHeader 
)