package wazevoapi
import (
"fmt"
"os"
"strconv"
"sync"
)
var PerfMap *Perfmap
func init() {
if PerfMapEnabled {
pid := os .Getpid ()
filename := "/tmp/perf-" + strconv .Itoa (pid ) + ".map"
fh , err := os .OpenFile (filename , os .O_APPEND |os .O_RDWR |os .O_CREATE , 0o644 )
if err != nil {
panic (err )
}
PerfMap = &Perfmap {fh : fh }
}
}
type Perfmap struct {
entries []entry
mux sync .Mutex
fh *os .File
}
type entry struct {
index int
offset int64
size uint64
name string
}
func (f *Perfmap ) Lock () {
f .mux .Lock ()
}
func (f *Perfmap ) Unlock () {
f .mux .Unlock ()
}
func (f *Perfmap ) AddModuleEntry (index int , offset int64 , size uint64 , name string ) {
e := entry {index : index , offset : offset , size : size , name : name }
if f .entries == nil {
f .entries = []entry {e }
return
}
f .entries = append (f .entries , e )
}
func (f *Perfmap ) Flush (addr uintptr , functionOffsets []int ) {
defer func () {
_ = f .fh .Sync ()
}()
for _ , e := range f .entries {
if _ , err := f .fh .WriteString (fmt .Sprintf ("%x %s %s\n" ,
uintptr (e .offset )+addr +uintptr (functionOffsets [e .index ]),
strconv .FormatUint (e .size , 16 ),
e .name ,
)); err != nil {
panic (err )
}
}
f .entries = f .entries [:0 ]
}
func (f *Perfmap ) Clear () {
f .entries = f .entries [:0 ]
}
func (f *Perfmap ) AddEntry (addr uintptr , size uint64 , name string ) {
_ , err := f .fh .WriteString (fmt .Sprintf ("%x %s %s\n" ,
addr ,
strconv .FormatUint (size , 16 ),
name ,
))
if err != nil {
panic (err )
}
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .