|
12 | 12 | // |
13 | 13 | //===----------------------------------------------------------------------===// |
14 | 14 |
|
15 | | -#include "llvm/ADT/DenseMap.h" |
16 | | -#include "llvm/ADT/MapVector.h" |
17 | | -#include "llvm/ADT/StringRef.h" |
18 | | -#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h" |
19 | | -#include "llvm/DebugInfo/Symbolize/Symbolize.h" |
20 | | -#include "llvm/Object/Binary.h" |
21 | | -#include "llvm/Object/ObjectFile.h" |
22 | | -#include "llvm/ProfileData/InstrProfReader.h" |
23 | | -#include "llvm/ProfileData/MemProf.h" |
24 | | -#include "llvm/ProfileData/MemProfData.inc" |
25 | 15 | #include "llvm/Support/Error.h" |
26 | 16 | #include "llvm/Support/MemoryBuffer.h" |
27 | 17 |
|
28 | | -#include <cstddef> |
29 | | - |
30 | 18 | namespace llvm { |
31 | 19 | namespace memprof { |
32 | 20 |
|
33 | | -// Map from id (recorded from sanitizer stack depot) to virtual addresses for |
34 | | -// each program counter address in the callstack. |
35 | | -using CallStackMap = llvm::DenseMap<uint64_t, llvm::SmallVector<uint64_t, 32>>; |
36 | | - |
37 | 21 | class RawMemProfReader { |
38 | 22 | public: |
39 | 23 | RawMemProfReader(std::unique_ptr<MemoryBuffer> DataBuffer) |
40 | 24 | : DataBuffer(std::move(DataBuffer)) {} |
41 | | - RawMemProfReader(const RawMemProfReader &) = delete; |
42 | | - RawMemProfReader &operator=(const RawMemProfReader &) = delete; |
43 | | - |
44 | 25 | // Prints the contents of the profile in YAML format. |
45 | 26 | void printYAML(raw_ostream &OS); |
46 | 27 |
|
47 | 28 | // Return true if the \p DataBuffer starts with magic bytes indicating it is |
48 | 29 | // a raw binary memprof profile. |
49 | 30 | static bool hasFormat(const MemoryBuffer &DataBuffer); |
50 | | - // Return true if the file at \p Path starts with magic bytes indicating it is |
51 | | - // a raw binary memprof profile. |
52 | | - static bool hasFormat(const StringRef Path); |
53 | 31 |
|
54 | 32 | // Create a RawMemProfReader after sanity checking the contents of the file at |
55 | | - // \p Path. The binary from which the profile has been collected is specified |
56 | | - // via a path in \p ProfiledBinary. |
57 | | - static Expected<std::unique_ptr<RawMemProfReader>> |
58 | | - create(const Twine &Path, const StringRef ProfiledBinary); |
59 | | - |
60 | | - Error readNextRecord(MemProfRecord &Record); |
61 | | - |
62 | | - using Iterator = InstrProfIterator<MemProfRecord, RawMemProfReader>; |
63 | | - Iterator end() { return Iterator(); } |
64 | | - Iterator begin() { |
65 | | - Iter = ProfileData.begin(); |
66 | | - return Iterator(this); |
67 | | - } |
68 | | - |
69 | | - // Constructor for unittests only. |
70 | | - RawMemProfReader(std::unique_ptr<llvm::symbolize::SymbolizableModule> Sym, |
71 | | - llvm::SmallVectorImpl<SegmentEntry> &Seg, |
72 | | - llvm::MapVector<uint64_t, MemInfoBlock> &Prof, |
73 | | - CallStackMap &SM) |
74 | | - : Symbolizer(std::move(Sym)), SegmentInfo(Seg.begin(), Seg.end()), |
75 | | - ProfileData(Prof), StackMap(SM) {} |
| 33 | + // \p Path. |
| 34 | + static Expected<std::unique_ptr<RawMemProfReader>> create(const Twine &Path); |
76 | 35 |
|
77 | 36 | private: |
78 | | - RawMemProfReader(std::unique_ptr<MemoryBuffer> DataBuffer, |
79 | | - object::OwningBinary<object::Binary> &&Bin) |
80 | | - : DataBuffer(std::move(DataBuffer)), Binary(std::move(Bin)) {} |
81 | | - Error initialize(); |
82 | | - Error readRawProfile(); |
83 | | - |
84 | | - object::SectionedAddress getModuleOffset(uint64_t VirtualAddress); |
85 | | - Error fillRecord(const uint64_t Id, const MemInfoBlock &MIB, |
86 | | - MemProfRecord &Record); |
87 | 37 | // Prints aggregate counts for each raw profile parsed from the DataBuffer in |
88 | 38 | // YAML format. |
89 | 39 | void printSummaries(raw_ostream &OS) const; |
90 | 40 |
|
91 | 41 | std::unique_ptr<MemoryBuffer> DataBuffer; |
92 | | - object::OwningBinary<object::Binary> Binary; |
93 | | - std::unique_ptr<llvm::symbolize::SymbolizableModule> Symbolizer; |
94 | | - |
95 | | - // The contents of the raw profile. |
96 | | - llvm::SmallVector<SegmentEntry, 16> SegmentInfo; |
97 | | - // A map from callstack id (same as key in CallStackMap below) to the heap |
98 | | - // information recorded for that allocation context. |
99 | | - llvm::MapVector<uint64_t, MemInfoBlock> ProfileData; |
100 | | - CallStackMap StackMap; |
101 | | - |
102 | | - // Iterator to read from the ProfileData MapVector. |
103 | | - llvm::MapVector<uint64_t, MemInfoBlock>::iterator Iter = ProfileData.end(); |
104 | 42 | }; |
105 | 43 |
|
106 | 44 | } // namespace memprof |
|
0 commit comments