Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[XRay] Define the library for XRay trace logs
Summary: In this change we move the definition of the log reading routines from the tools directory in LLVM to {include/llvm,lib}/XRay. We improve the documentation a little bit for the publicly accessible headers, and adjust the top-matter. This also leads to some refactoring and cleanup in the tooling code. In particular, we do the following: - Rename the class from LogReader to Trace, as it better represents the logical set of records as opposed to a log. - Use file type detection instead of asking the user to say what format the input file is. This allows us to keep the interface simple and encapsulate the logic of loading the data appropriately. In future changes we increase the API surface and write dedicated unit tests for the XRay library. Depends on D24376. Reviewers: dblaikie, echristo Subscribers: mehdi_amini, mgorny, llvm-commits, varno Differential Revision: https://reviews.llvm.org/D28345 llvm-svn: 291652
- Loading branch information
1 parent
410eaeb
commit d6c1865
Showing
12 changed files
with
272 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//===- Trace.h - XRay Trace Abstraction -----------------------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Defines the XRay Trace class representing records in an XRay trace file. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef LLVM_XRAY_TRACE_H | ||
#define LLVM_XRAY_TRACE_H | ||
|
||
#include <cstdint> | ||
#include <vector> | ||
|
||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/Support/Error.h" | ||
#include "llvm/Support/FileSystem.h" | ||
#include "llvm/XRay/XRayRecord.h" | ||
|
||
namespace llvm { | ||
namespace xray { | ||
|
||
/// A Trace object represents the records that have been loaded from XRay | ||
/// log files generated by instrumented binaries. We encapsulate the logic of | ||
/// reading the traces in factory functions that populate the Trace object | ||
/// appropriately. | ||
/// | ||
/// Trace objects provide an accessor to an XRayFileHeader which says more about | ||
/// details of the file from which the XRay trace was loaded from. | ||
/// | ||
/// Usage: | ||
/// | ||
/// if (auto TraceOrErr = loadTraceFile("xray-log.something.xray")) { | ||
/// auto& T = *TraceOrErr; | ||
/// // T.getFileHeader() will provide information from the trace header. | ||
/// for (const XRayRecord &R : T) { | ||
/// // ... do something with R here. | ||
/// } | ||
/// } else { | ||
/// // Handle the error here. | ||
/// } | ||
/// | ||
class Trace { | ||
XRayFileHeader FileHeader; | ||
std::vector<XRayRecord> Records; | ||
|
||
typedef std::vector<XRayRecord>::const_iterator citerator; | ||
|
||
friend Expected<Trace> loadTraceFile(StringRef, bool); | ||
|
||
public: | ||
/// Provides access to the loaded XRay trace file header. | ||
const XRayFileHeader &getFileHeader() const { return FileHeader; } | ||
|
||
citerator begin() const { return Records.begin(); } | ||
citerator end() const { return Records.end(); } | ||
size_t size() const { return Records.size(); } | ||
}; | ||
|
||
/// This function will attempt to load XRay trace records from the provided | ||
/// |Filename|. | ||
Expected<Trace> loadTraceFile(StringRef Filename, bool Sort = false); | ||
|
||
} // namespace xray | ||
} // namespace llvm | ||
|
||
#endif // LLVM_XRAY_TRACE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//===- XRayRecord.h - XRay Trace Record -----------------------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file replicates the record definition for XRay log entries. This should | ||
// follow the evolution of the log record versions supported in the compiler-rt | ||
// xray project. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef LLVM_XRAY_XRAY_RECORD_H | ||
#define LLVM_XRAY_XRAY_RECORD_H | ||
|
||
#include <cstdint> | ||
|
||
namespace llvm { | ||
namespace xray { | ||
|
||
/// XRay traces all have a header providing some top-matter information useful | ||
/// to help tools determine how to interpret the information available in the | ||
/// trace. | ||
struct XRayFileHeader { | ||
/// Version of the XRay implementation that produced this file. | ||
uint16_t Version = 0; | ||
|
||
/// A numeric identifier for the type of file this is. Best used in | ||
/// combination with Version. | ||
uint16_t Type = 0; | ||
|
||
/// Whether the CPU that produced the timestamp counters (TSC) move at a | ||
/// constant rate. | ||
bool ConstantTSC; | ||
|
||
/// Whether the CPU that produced the timestamp counters (TSC) do not stop. | ||
bool NonstopTSC; | ||
|
||
/// The number of cycles per second for the CPU that produced the timestamp | ||
/// counter (TSC) values. Useful for estimating the amount of time that | ||
/// elapsed between two TSCs on some platforms. | ||
uint64_t CycleFrequency = 0; | ||
}; | ||
|
||
/// Determines the supported types of records that could be seen in XRay traces. | ||
/// 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 { ENTER, EXIT }; | ||
|
||
struct XRayRecord { | ||
/// The type of record. | ||
uint16_t RecordType; | ||
|
||
/// The CPU where the thread is running. We assume number of CPUs <= 256. | ||
uint8_t CPU; | ||
|
||
/// Identifies the type of record. | ||
RecordTypes Type; | ||
|
||
/// The function ID for the record. | ||
int32_t FuncId; | ||
|
||
/// Get the full 8 bytes of the TSC when we get the log record. | ||
uint64_t TSC; | ||
|
||
/// The thread ID for the currently running thread. | ||
uint32_t TId; | ||
}; | ||
|
||
} // namespace xray | ||
} // namespace llvm | ||
|
||
#endif // LLVM_XRAY_XRAY_RECORD_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
add_llvm_library(LLVMXRay | ||
Trace.cpp | ||
|
||
ADDITIONAL_HEADER_DIRS | ||
${LLVM_MAIN_INCLUDE_DIR}/llvm/ADT | ||
${LLVM_MAIN_INCLUDE_DIR}/llvm/XRay | ||
|
||
DEPENDS | ||
LLVMSupport | ||
|
||
LINK_LIBS | ||
LLVMSupport | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.