github.com/grafana/pyroscope@v1.18.0/pkg/phlaredb/schemas/v1/functions.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 functionsSchema = parquet.SchemaOf(new(profilev1.Function))
    10  
    11  type FunctionPersister struct{}
    12  
    13  func (FunctionPersister) Name() string { return "functions" }
    14  
    15  func (FunctionPersister) Schema() *parquet.Schema { return functionsSchema }
    16  
    17  func (FunctionPersister) Deconstruct(row parquet.Row, fn InMemoryFunction) parquet.Row {
    18  	if cap(row) < 5 {
    19  		row = make(parquet.Row, 0, 5)
    20  	}
    21  	row = row[:0]
    22  	row = append(row, parquet.Int64Value(int64(fn.Id)).Level(0, 0, 0))
    23  	row = append(row, parquet.Int32Value(int32(fn.Name)).Level(0, 0, 1))
    24  	row = append(row, parquet.Int32Value(int32(fn.SystemName)).Level(0, 0, 2))
    25  	row = append(row, parquet.Int32Value(int32(fn.Filename)).Level(0, 0, 3))
    26  	row = append(row, parquet.Int32Value(int32(fn.StartLine)).Level(0, 0, 4))
    27  	return row
    28  }
    29  
    30  func (FunctionPersister) Reconstruct(row parquet.Row) (InMemoryFunction, error) {
    31  	loc := InMemoryFunction{
    32  		Id:         row[0].Uint64(),
    33  		Name:       row[1].Uint32(),
    34  		SystemName: row[2].Uint32(),
    35  		Filename:   row[3].Uint32(),
    36  		StartLine:  row[4].Uint32(),
    37  	}
    38  	return loc, nil
    39  }
    40  
    41  type InMemoryFunction struct {
    42  	// Unique nonzero id for the function.
    43  	Id uint64
    44  	// Name of the function, in human-readable form if available.
    45  	Name uint32
    46  	// Name of the function, as identified by the system.
    47  	// For instance, it can be a C++ mangled name.
    48  	SystemName uint32
    49  	// Source file containing the function.
    50  	Filename uint32
    51  	// Line number in source file.
    52  	StartLine uint32
    53  }
    54  
    55  func (f InMemoryFunction) Clone() InMemoryFunction {
    56  	return f
    57  }