22#define LLVM_PROFILEDATA_MEMPROFYAML_H_
33
44#include " llvm/ADT/SmallVector.h"
5- #include " llvm/ProfileData/DataAccessProf.h"
65#include " llvm/ProfileData/MemProf.h"
76#include " llvm/Support/Format.h"
87#include " llvm/Support/YAMLTraits.h"
@@ -21,24 +20,9 @@ struct GUIDMemProfRecordPair {
2120 MemProfRecord Record;
2221};
2322
24- // Helper struct to yamlify memprof::DataAccessProfData. The struct
25- // members use owned strings. This is for simplicity and assumes that most real
26- // world use cases do look-ups and regression test scale is small.
27- struct YamlDataAccessProfData {
28- std::vector<memprof::DataAccessProfRecord> Records;
29- std::vector<uint64_t > KnownColdStrHashes;
30- std::vector<std::string> KnownColdSymbols;
31-
32- bool isEmpty () const {
33- return Records.empty () && KnownColdStrHashes.empty () &&
34- KnownColdSymbols.empty ();
35- }
36- };
37-
3823// The top-level data structure, only used with YAML for now.
3924struct AllMemProfData {
4025 std::vector<GUIDMemProfRecordPair> HeapProfileRecords;
41- YamlDataAccessProfData YamlifiedDataAccessProfiles;
4226};
4327} // namespace memprof
4428
@@ -222,52 +206,9 @@ template <> struct MappingTraits<memprof::GUIDMemProfRecordPair> {
222206 }
223207};
224208
225- template <> struct MappingTraits <memprof::SourceLocation> {
226- static void mapping (IO &Io, memprof::SourceLocation &Loc) {
227- Io.mapOptional (" FileName" , Loc.FileName );
228- Io.mapOptional (" Line" , Loc.Line );
229- }
230- };
231-
232- template <> struct MappingTraits <memprof::DataAccessProfRecord> {
233- static void mapping (IO &Io, memprof::DataAccessProfRecord &Rec) {
234- if (Io.outputting ()) {
235- if (std::holds_alternative<std::string>(Rec.SymHandle )) {
236- Io.mapOptional (" Symbol" , std::get<std::string>(Rec.SymHandle ));
237- } else {
238- Io.mapOptional (" Hash" , std::get<uint64_t >(Rec.SymHandle ));
239- }
240- } else {
241- std::string SymName;
242- uint64_t Hash = 0 ;
243- Io.mapOptional (" Symbol" , SymName);
244- Io.mapOptional (" Hash" , Hash);
245- if (!SymName.empty ()) {
246- Rec.SymHandle = SymName;
247- } else {
248- Rec.SymHandle = Hash;
249- }
250- }
251-
252- Io.mapOptional (" Locations" , Rec.Locations );
253- }
254- };
255-
256- template <> struct MappingTraits <memprof::YamlDataAccessProfData> {
257- static void mapping (IO &Io, memprof::YamlDataAccessProfData &Data) {
258- Io.mapOptional (" SampledRecords" , Data.Records );
259- Io.mapOptional (" KnownColdSymbols" , Data.KnownColdSymbols );
260- Io.mapOptional (" KnownColdStrHashes" , Data.KnownColdStrHashes );
261- }
262- };
263-
264209template <> struct MappingTraits <memprof::AllMemProfData> {
265210 static void mapping (IO &Io, memprof::AllMemProfData &Data) {
266211 Io.mapRequired (" HeapProfileRecords" , Data.HeapProfileRecords );
267- // Map data access profiles if reading input, or if writing output &&
268- // the struct is populated.
269- if (!Io.outputting () || !Data.YamlifiedDataAccessProfiles .isEmpty ())
270- Io.mapOptional (" DataAccessProfiles" , Data.YamlifiedDataAccessProfiles );
271212 }
272213};
273214
@@ -293,7 +234,5 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::AllocationInfo)
293234LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::CallSiteInfo)
294235LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::GUIDMemProfRecordPair)
295236LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::GUIDHex64) // Used for CalleeGuids
296- LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::DataAccessProfRecord)
297- LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::SourceLocation)
298237
299238#endif // LLVM_PROFILEDATA_MEMPROFYAML_H_
0 commit comments