1
0
mirror of https://github.com/DataDog/go-profiler-notes.git synced 2025-07-15 23:54:16 +02:00

fix pclntab example

This commit is contained in:
Felix Geisendörfer
2022-08-19 22:07:20 +02:00
parent 027b8dabc8
commit ea39719244
3 changed files with 56 additions and 48 deletions

View File

@ -1,7 +1,6 @@
package main
import (
"debug/gosym"
"fmt"
"os"
"runtime"
@ -15,22 +14,15 @@ func main() {
}
func run() error {
data, err := gopclntab()
symTable, err := goSymTable()
if err != nil {
return fmt.Errorf("gopclntab: %w", err)
return err
}
return debugSymtab(data)
}
type StackTrace struct {
Frames []StackFrame
}
type StackFrame struct {
PC int
Function string
File string
Line int
for _, pc := range callers() {
file, line, fn := symTable.PCToLine(uint64(pc))
fmt.Printf("%x: %s() %s:%d\n", pc, fn.Name, file, line)
}
return nil
}
func callers() []uintptr {
@ -39,16 +31,3 @@ func callers() []uintptr {
pcs = pcs[0:n]
return pcs
}
func debugSymtab(gopclntab []byte) error {
table, err := gosym.NewTable(nil, gosym.NewLineTable(gopclntab, 0))
if err != nil {
return fmt.Errorf("gosym.NewTable: %w", err)
}
for _, pc := range callers() {
file, line, fn := table.PCToLine(uint64(pc))
fmt.Printf("%x: %s() %s:%d\n", pc, fn.Name, file, line)
}
return nil
}