Skip to content

Commit

Permalink
local store locking update
Browse files Browse the repository at this point in the history
  • Loading branch information
1pkg committed Dec 8, 2020
1 parent 3d6d71c commit 670dc9f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/1pkg/gotcha
go 1.15

require (
github.com/1pkg/golocal v0.7.0
github.com/1pkg/golocal v0.8.0
github.com/1pkg/gomonkey v1.0.5
github.com/stretchr/testify v1.6.1
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/1pkg/golocal v0.7.0 h1:wHjXW0Cmja4CuTnl4spIv4MrKB3CaBjPdldAlHZJHjI=
github.com/1pkg/golocal v0.7.0/go.mod h1:darSWWpnYPb3rdz5WsiCA1ucgFzVuTlVG6sLKlrWokg=
github.com/1pkg/golocal v0.8.0 h1:4sIPTYrYYBpWE697oF2ZMT1lhZ4+zloTaKbE9lDMbxk=
github.com/1pkg/golocal v0.8.0/go.mod h1:darSWWpnYPb3rdz5WsiCA1ucgFzVuTlVG6sLKlrWokg=
github.com/1pkg/gomonkey v1.0.5 h1:vtzc5Vx699CZYjAk83Ac7NRJ+gH0xiLEYXJ/Vp+CqjY=
github.com/1pkg/gomonkey v1.0.5/go.mod h1:fYSRBs8LM1seoFsRvlswGy9KCkxvsEBByqtUz54GOqQ=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
Expand Down
26 changes: 12 additions & 14 deletions malloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,20 @@ func init() {
ls := golocal.LStore(maxTracers)
// patch malloc with permanent decorator
gomonkey.PermanentDecorate(mallocgc, func(size uintptr, tp *tp, needzero bool) unsafe.Pointer {
// unfortunately we can't use local store get here
// unfortunately we can't use local store direct calls here
// as it causes `unknown caller pc` stack fatal error.
if !ls.Locked() {
ls.Lock()
gctx, ok := ls.Store[golocal.ID()]
ls.Unlock()
if ok {
// trace allocations for caller tracer goroutine.
bytes := int64(size)
objs := int64(1)
if tp != nil {
bytes = int64(tp.size)
objs = int64(size) / bytes
}
(*gotchactx)(unsafe.Pointer(gctx)).Add(bytes, objs, 1)
id := ls.RLock()
gctxPtr, ok := ls.Store[id]
ls.RUnlock()
if ok {
// trace allocations for caller tracer goroutine.
bytes := int64(size)
objs := int64(1)
if tp != nil {
bytes = int64(tp.size)
objs = int64(size) / bytes
}
(*gotchactx)(unsafe.Pointer(gctxPtr)).Add(bytes, objs, 1)
}
return nil
}, 24, 53, []byte{
Expand Down

0 comments on commit 670dc9f

Please sign in to comment.