22#define  LLVM_PROFILEDATA_MEMPROFYAML_H_ 
33
44#include  " llvm/ADT/SmallVector.h" 
5+ #include  " llvm/ProfileData/DataAccessProf.h" 
56#include  " llvm/ProfileData/MemProf.h" 
67#include  " llvm/Support/Format.h" 
78#include  " llvm/Support/YAMLTraits.h" 
@@ -12,6 +13,9 @@ namespace memprof {
1213//  serialized and deserialized in YAML.
1314LLVM_YAML_STRONG_TYPEDEF (uint64_t , GUIDHex64)
1415
16+ LLVM_YAML_STRONG_TYPEDEF (uint64_t , SymbolContentHash)
17+ LLVM_YAML_STRONG_TYPEDEF (std::string, OwnedSymbolName)
18+ 
1519//  Helper struct for AllMemProfData.  In YAML, we treat the GUID and the fields
1620//  within MemProfRecord at the same level as if the GUID were part of
1721//  MemProfRecord.
@@ -20,9 +24,25 @@ struct GUIDMemProfRecordPair {
2024  MemProfRecord Record;
2125};
2226
27+ //  Helper struct to yamlify data_access_prof::DataAccessProfData. The struct
28+ //  members use owned strings. This is for simplicity and assumes that most real
29+ //  world use cases do look-ups and regression test scale is small, so string
30+ //  efficiency is not a priority.
31+ struct  YamlDataAccessProfData  {
32+   std::vector<data_access_prof::DataAccessProfRecord> Records;
33+   std::vector<uint64_t > KnownColdHashes;
34+   std::vector<std::string> KnownColdSymbols;
35+ 
36+   bool  isEmpty () const  {
37+     return  Records.empty () && KnownColdHashes.empty () &&
38+            KnownColdSymbols.empty ();
39+   }
40+ };
41+ 
2342//  The top-level data structure, only used with YAML for now.
2443struct  AllMemProfData  {
2544  std::vector<GUIDMemProfRecordPair> HeapProfileRecords;
45+   YamlDataAccessProfData YamlifiedDataAccessProfiles;
2646};
2747} //  namespace memprof
2848
@@ -206,9 +226,50 @@ template <> struct MappingTraits<memprof::GUIDMemProfRecordPair> {
206226  }
207227};
208228
229+ template  <> struct  MappingTraits <data_access_prof::SourceLocation> {
230+   static  void  mapping (IO &Io, data_access_prof::SourceLocation &Loc) {
231+     Io.mapOptional (" FileName"  , Loc.FileName );
232+     Io.mapOptional (" Line"  , Loc.Line );
233+   }
234+ };
235+ 
236+ template  <> struct  MappingTraits <data_access_prof::DataAccessProfRecord> {
237+   static  void  mapping (IO &Io, data_access_prof::DataAccessProfRecord &Rec) {
238+     if  (Io.outputting ()) {
239+       if  (std::holds_alternative<std::string>(Rec.SymHandle )) {
240+         Io.mapOptional (" Symbol"  , std::get<std::string>(Rec.SymHandle ));
241+       } else  {
242+         Io.mapOptional (" Hash"  , std::get<uint64_t >(Rec.SymHandle ));
243+       }
244+     } else  {
245+       std::string SymName;
246+       uint64_t  Hash = 0 ;
247+       Io.mapOptional (" Symbol"  , SymName);
248+       Io.mapOptional (" Hash"  , Hash);
249+       if  (!SymName.empty ()) {
250+         Rec.SymHandle  = SymName;
251+       } else  {
252+         Rec.SymHandle  = Hash;
253+       }
254+     }
255+ 
256+     Io.mapOptional (" Locations"  , Rec.Locations );
257+   }
258+ };
259+ 
260+ template  <> struct  MappingTraits <memprof::YamlDataAccessProfData> {
261+   static  void  mapping (IO &Io, memprof::YamlDataAccessProfData &Data) {
262+     Io.mapOptional (" SampledRecords"  , Data.Records );
263+     Io.mapOptional (" KnownColdSymbols"  , Data.KnownColdSymbols );
264+     Io.mapOptional (" KnownColdHashes"  , Data.KnownColdHashes );
265+   }
266+ };
267+ 
209268template  <> struct  MappingTraits <memprof::AllMemProfData> {
210269  static  void  mapping (IO &Io, memprof::AllMemProfData &Data) {
211270    Io.mapRequired (" HeapProfileRecords"  , Data.HeapProfileRecords );
271+ 
272+     Io.mapOptional (" DataAccessProfiles"  , Data.YamlifiedDataAccessProfiles );
212273  }
213274};
214275
@@ -234,5 +295,9 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::AllocationInfo)
234295LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::CallSiteInfo)
235296LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::GUIDMemProfRecordPair)
236297LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::GUIDHex64) //  Used for CalleeGuids
298+ LLVM_YAML_IS_SEQUENCE_VECTOR(data_access_prof::DataAccessProfRecord)
299+ LLVM_YAML_IS_SEQUENCE_VECTOR(data_access_prof::SourceLocation)
300+ LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::SymbolContentHash)
301+ LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::OwnedSymbolName)
237302
238303#endif //  LLVM_PROFILEDATA_MEMPROFYAML_H_
0 commit comments