Documentation
¶
Overview ¶
Package lidia implements a custom binary format for efficient symbolization of Go profiles.
Lidia provides functionality to create, read, and query symbol tables stored in the lidia binary format. This format is optimized for fast symbol lookups by address, which is useful for symbolizing profiles collected from Go programs.
Creating Lidia Files ¶
There are two main ways to create a lidia file:
// From an executable file err := lidia.CreateLidia("path/to/executable", "output.lidia", lidia.WithCRC(), lidia.WithLines(), lidia.WithFiles()) if err != nil { // handle error } // From an already opened ELF file elfFile, err := elf.Open("path/to/executable") if err != nil { // handle error } defer elfFile.Close() output, err := os.Create("output.lidia") if err != nil { // handle error } defer output.Close() err = lidia.CreateLidiaFromELF(elfFile, output, lidia.WithCRC(), lidia.WithLines(), lidia.WithFiles()) if err != nil { // handle error }
Reading and Querying Lidia Files ¶
// Read a lidia file into memory data, err := os.ReadFile("path/to/file.lidia") if err != nil { // handle error } // Create a reader from the data var reader lidia.ReaderAtCloser = &MyReaderAtCloser{data, 0} // Open the lidia table table, err := lidia.OpenReader(reader, lidia.WithCRC()) if err != nil { // handle error } defer table.Close() // Look up a function symbol by address frames, err := table.Lookup(0x408ed0) if err != nil { // handle error } // Use the symbolization results for _, frame := range frames { fmt.Println(frame.FunctionName) }
Available Options ¶
The following options can be used when creating or opening lidia files:
- WithCRC(): Enables CRC32C checksums for data integrity
- WithFiles(): Includes source file information
- WithLines(): Includes line number information
When creating a lidia file with WithCRC(), the same option must be used when opening the file, or an error will be returned.
Package lidia implements a custom binary format for efficient symbolization of Go profiles.
Lidia provides a compact binary representation of symbol information extracted from ELF files, optimized for fast lookup by memory address. This is particularly useful for symbolizing profile data collected from Go applications.
options.go
Index ¶
- func CreateLidia(executablePath, outputPath string, opts ...Option) error
- func CreateLidiaFromELF(elfFile *elf.File, output io.WriteSeeker, opts ...Option) error
- type LineTable
- type LineTableEntry
- type Option
- type Range
- type ReaderAtCloser
- type SourceInfoFrame
- type Table
- func (st *Table) CheckCRC() error
- func (st *Table) CheckCRCFields() error
- func (st *Table) CheckCRCLineTables() error
- func (st *Table) CheckCRCStrings() error
- func (st *Table) CheckCRCVA() error
- func (st *Table) Close()
- func (st *Table) Lookup(dst []SourceInfoFrame, addr uint64) ([]SourceInfoFrame, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateLidia ¶
CreateLidia generates a lidia format file from an ELF executable. It extracts symbol information and writes it to the output file.
func CreateLidiaFromELF ¶
CreateLidiaFromELF generates a lidia format file from an already opened ELF file. This allows more control over the ELF file handling.
Types ¶
type LineTable ¶
type LineTable []LineTableEntry
LineTable represents source line number information.
type LineTableEntry ¶
LineTableEntry maps an offset to a line number.
type Option ¶
type Option func(*options)
Option configures a Table or file creation process.
type Range ¶
type Range struct { VA uint64 Length uint32 Function string File string CallFile string CallLine uint32 Depth uint32 LineTable LineTable }
Range represents a function range to be added to a lidia file.
type ReaderAtCloser ¶
type ReaderAtCloser interface { io.ReadCloser io.ReaderAt }
type SourceInfoFrame ¶
SourceInfoFrame represents a single frame of symbolized profiling information. It contains the name of the function, the source file path, and the line number at which the profiling sample was taken.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table represents a lidia symbol table that can be queried for lookups.
func OpenReader ¶
func OpenReader(f ReaderAtCloser, opt ...Option) (*Table, error)
OpenReader creates a new Table from the provided ReaderAtCloser. It reads the header, validates the format, and prepares the table for lookups. The caller is responsible for closing the returned Table.
func (*Table) CheckCRCFields ¶
func (*Table) CheckCRCLineTables ¶
func (*Table) CheckCRCStrings ¶
func (*Table) CheckCRCVA ¶
func (*Table) Lookup ¶
func (st *Table) Lookup(dst []SourceInfoFrame, addr uint64) ([]SourceInfoFrame, error)
Lookup performs a symbol lookup by memory address. It accepts a destination slice 'dst' to store the results, allowing memory reuse between calls. The function returns a slice of SourceInfoFrame representing the symbolization result for the given address. The returned slice may be the same as the input slice 'dst' with updated contents, or a new slice if 'dst' needed to grow. If 'dst' is nil, a new slice will be allocated.