LLVM  4.0.0
XRay/Trace.h
Go to the documentation of this file.
1 //===- Trace.h - XRay Trace Abstraction -----------------------------------===//
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 //
10 // Defines the XRay Trace class representing records in an XRay trace file.
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_XRAY_TRACE_H
14 #define LLVM_XRAY_TRACE_H
15 
16 #include <cstdint>
17 #include <vector>
18 
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/Error.h"
22 #include "llvm/XRay/XRayRecord.h"
23 
24 namespace llvm {
25 namespace 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 ///
47 class Trace {
48  XRayFileHeader FileHeader;
49  std::vector<XRayRecord> Records;
50 
51  typedef std::vector<XRayRecord>::const_iterator citerator;
52 
54 
55 public:
56  /// Provides access to the loaded XRay trace file header.
57  const XRayFileHeader &getFileHeader() const { return FileHeader; }
58 
59  citerator begin() const { return Records.begin(); }
60  citerator end() const { return Records.end(); }
61  size_t size() const { return Records.size(); }
62 };
63 
64 /// This function will attempt to load XRay trace records from the provided
65 /// |Filename|.
66 Expected<Trace> loadTraceFile(StringRef Filename, bool Sort = false);
67 
68 } // namespace xray
69 } // namespace llvm
70 
71 #endif // LLVM_XRAY_TRACE_H
Expected< Trace > loadTraceFile(StringRef Filename, bool Sort=false)
This function will attempt to load XRay trace records from the provided |Filename|.
Definition: XRay/Trace.cpp:131
Tagged union holding either a T or a Error.
friend Expected< Trace > loadTraceFile(StringRef, bool)
This function will attempt to load XRay trace records from the provided |Filename|.
A Trace object represents the records that have been loaded from XRay log files generated by instrume...
Definition: XRay/Trace.h:47
size_t size() const
Definition: XRay/Trace.h:61
const XRayFileHeader & getFileHeader() const
Provides access to the loaded XRay trace file header.
Definition: XRay/Trace.h:57
citerator end() const
Definition: XRay/Trace.h:60
XRay traces all have a header providing some top-matter information useful to help tools determine ho...
Definition: XRayRecord.h:26
citerator begin() const
Definition: XRay/Trace.h:59
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47