LLVM 22.0.0git
Trace.h
Go to the documentation of this file.
1//===- Trace.h - XRay Trace Abstraction -----------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Defines the XRay Trace class representing records in an XRay trace file.
10//
11//===----------------------------------------------------------------------===//
12#ifndef LLVM_XRAY_TRACE_H
13#define LLVM_XRAY_TRACE_H
14
15#include <cstdint>
16#include <vector>
17
18#include "llvm/ADT/StringRef.h"
21#include "llvm/Support/Error.h"
23
24namespace llvm {
25namespace xray {
26
27/// A Trace object represents the records that have been loaded from XRay
28/// log files generated by instrumented binaries. We encapsulate the logic of
29/// reading the traces in factory functions that populate the Trace object
30/// appropriately.
31///
32/// Trace objects provide an accessor to an XRayFileHeader which says more about
33/// details of the file from which the XRay trace was loaded from.
34///
35/// Usage:
36///
37/// if (auto TraceOrErr = loadTraceFile("xray-log.something.xray")) {
38/// auto& T = *TraceOrErr;
39/// // T.getFileHeader() will provide information from the trace header.
40/// for (const XRayRecord &R : T) {
41/// // ... do something with R here.
42/// }
43/// } else {
44/// // Handle the error here.
45/// }
46///
47class Trace {
48 XRayFileHeader FileHeader;
49 using RecordVector = std::vector<XRayRecord>;
50 RecordVector Records;
51
52 typedef std::vector<XRayRecord>::const_iterator citerator;
53
55
56public:
57 using size_type = RecordVector::size_type;
58 using value_type = RecordVector::value_type;
59 using const_iterator = RecordVector::const_iterator;
60
61 /// Provides access to the loaded XRay trace file header.
62 const XRayFileHeader &getFileHeader() const { return FileHeader; }
63
64 const_iterator begin() const { return Records.begin(); }
65 const_iterator end() const { return Records.end(); }
66 bool empty() const { return Records.empty(); }
67 size_type size() const { return Records.size(); }
68};
69
70/// This function will attempt to load XRay trace records from the provided
71/// |Filename|.
72LLVM_ABI Expected<Trace> loadTraceFile(StringRef Filename, bool Sort = false);
73
74/// This function will attempt to load XRay trace records from the provided
75/// DataExtractor.
77 bool Sort = false);
78
79} // namespace xray
80} // namespace llvm
81
82#endif // LLVM_XRAY_TRACE_H
#define LLVM_ABI
Definition Compiler.h:213
Tagged union holding either a T or a Error.
Definition Error.h:485
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
A Trace object represents the records that have been loaded from XRay log files generated by instrume...
Definition Trace.h:47
RecordVector::size_type size_type
Definition Trace.h:57
const_iterator end() const
Definition Trace.h:65
RecordVector::const_iterator const_iterator
Definition Trace.h:59
LLVM_ABI friend Expected< Trace > loadTrace(const DataExtractor &, bool)
This function will attempt to load XRay trace records from the provided DataExtractor.
const XRayFileHeader & getFileHeader() const
Provides access to the loaded XRay trace file header.
Definition Trace.h:62
size_type size() const
Definition Trace.h:67
RecordVector::value_type value_type
Definition Trace.h:58
bool empty() const
Definition Trace.h:66
const_iterator begin() const
Definition Trace.h:64
LLVM_ABI Expected< Trace > loadTrace(const DataExtractor &Extractor, bool Sort=false)
This function will attempt to load XRay trace records from the provided DataExtractor.
Definition Trace.cpp:420
LLVM_ABI Expected< Trace > loadTraceFile(StringRef Filename, bool Sort=false)
This function will attempt to load XRay trace records from the provided |Filename|.
Definition Trace.cpp:381
This is an optimization pass for GlobalISel generic memory operations.
XRay traces all have a header providing some top-matter information useful to help tools determine ho...
Definition XRayRecord.h:27