github.com/grafana/pyroscope@v1.18.0/pkg/phlaredb/schemas/v1/mappings.go (about) 1 package v1 2 3 import ( 4 "github.com/parquet-go/parquet-go" 5 6 profilev1 "github.com/grafana/pyroscope/api/gen/proto/go/google/v1" 7 ) 8 9 var mappingsSchema = parquet.SchemaOf(new(profilev1.Mapping)) 10 11 type MappingPersister struct{} 12 13 func (MappingPersister) Name() string { return "mappings" } 14 15 func (MappingPersister) Schema() *parquet.Schema { return mappingsSchema } 16 17 func (MappingPersister) Deconstruct(row parquet.Row, m InMemoryMapping) parquet.Row { 18 if cap(row) < 10 { 19 row = make(parquet.Row, 0, 10) 20 } 21 row = row[:0] 22 row = append(row, parquet.Int64Value(int64(m.Id)).Level(0, 0, 0)) 23 row = append(row, parquet.Int64Value(int64(m.MemoryStart)).Level(0, 0, 1)) 24 row = append(row, parquet.Int64Value(int64(m.MemoryLimit)).Level(0, 0, 2)) 25 row = append(row, parquet.Int64Value(int64(m.FileOffset)).Level(0, 0, 3)) 26 row = append(row, parquet.Int32Value(int32(m.Filename)).Level(0, 0, 4)) 27 row = append(row, parquet.Int32Value(int32(m.BuildId)).Level(0, 0, 5)) 28 row = append(row, parquet.BooleanValue(m.HasFunctions).Level(0, 0, 6)) 29 row = append(row, parquet.BooleanValue(m.HasFilenames).Level(0, 0, 7)) 30 row = append(row, parquet.BooleanValue(m.HasLineNumbers).Level(0, 0, 8)) 31 row = append(row, parquet.BooleanValue(m.HasInlineFrames).Level(0, 0, 9)) 32 return row 33 } 34 35 func (MappingPersister) Reconstruct(row parquet.Row) (InMemoryMapping, error) { 36 mapping := InMemoryMapping{ 37 Id: row[0].Uint64(), 38 MemoryStart: row[1].Uint64(), 39 MemoryLimit: row[2].Uint64(), 40 FileOffset: row[3].Uint64(), 41 Filename: row[4].Uint32(), 42 BuildId: row[5].Uint32(), 43 HasFunctions: row[6].Boolean(), 44 HasFilenames: row[7].Boolean(), 45 HasLineNumbers: row[8].Boolean(), 46 HasInlineFrames: row[9].Boolean(), 47 } 48 return mapping, nil 49 } 50 51 type InMemoryMapping struct { 52 // Unique nonzero id for the mapping. 53 Id uint64 54 // Address at which the binary (or DLL) is loaded into memory. 55 MemoryStart uint64 56 // The limit of the address range occupied by this mapping. 57 MemoryLimit uint64 58 // Offset in the binary that corresponds to the first mapped address. 59 FileOffset uint64 60 // The object this entry is loaded from. This can be a filename on 61 // disk for the main binary and shared libraries, or virtual 62 // abstractions like "[vdso]". 63 Filename uint32 64 // A string that uniquely identifies a particular program version 65 // with high probability. E.g., for binaries generated by GNU tools, 66 // it could be the contents of the .note.gnu.build-id field. 67 BuildId uint32 68 // The following fields indicate the resolution of symbolic info. 69 HasFunctions bool 70 HasFilenames bool 71 HasLineNumbers bool 72 HasInlineFrames bool 73 } 74 75 func (m InMemoryMapping) Clone() InMemoryMapping { 76 return m 77 }