2
2
#define LLVM_PROFILEDATA_MEMPROFYAML_H_
3
3
4
4
#include " llvm/ADT/SmallVector.h"
5
+ #include " llvm/ProfileData/DataAccessProf.h"
5
6
#include " llvm/ProfileData/MemProf.h"
6
7
#include " llvm/Support/Format.h"
7
8
#include " llvm/Support/YAMLTraits.h"
@@ -12,6 +13,9 @@ namespace memprof {
12
13
// serialized and deserialized in YAML.
13
14
LLVM_YAML_STRONG_TYPEDEF (uint64_t , GUIDHex64)
14
15
16
+ LLVM_YAML_STRONG_TYPEDEF (uint64_t , SymbolContentHash)
17
+ LLVM_YAML_STRONG_TYPEDEF (std::string, OwnedSymbolName)
18
+
15
19
// Helper struct for AllMemProfData. In YAML, we treat the GUID and the fields
16
20
// within MemProfRecord at the same level as if the GUID were part of
17
21
// MemProfRecord.
@@ -20,9 +24,25 @@ struct GUIDMemProfRecordPair {
20
24
MemProfRecord Record;
21
25
};
22
26
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
+
23
42
// The top-level data structure, only used with YAML for now.
24
43
struct AllMemProfData {
25
44
std::vector<GUIDMemProfRecordPair> HeapProfileRecords;
45
+ YamlDataAccessProfData YamlifiedDataAccessProfiles;
26
46
};
27
47
} // namespace memprof
28
48
@@ -206,9 +226,50 @@ template <> struct MappingTraits<memprof::GUIDMemProfRecordPair> {
206
226
}
207
227
};
208
228
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
+
209
268
template <> struct MappingTraits <memprof::AllMemProfData> {
210
269
static void mapping (IO &Io, memprof::AllMemProfData &Data) {
211
270
Io.mapRequired (" HeapProfileRecords" , Data.HeapProfileRecords );
271
+
272
+ Io.mapOptional (" DataAccessProfiles" , Data.YamlifiedDataAccessProfiles );
212
273
}
213
274
};
214
275
@@ -234,5 +295,9 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::AllocationInfo)
234
295
LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::CallSiteInfo)
235
296
LLVM_YAML_IS_SEQUENCE_VECTOR(memprof::GUIDMemProfRecordPair)
236
297
LLVM_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)
237
302
238
303
#endif // LLVM_PROFILEDATA_MEMPROFYAML_H_
0 commit comments