github.com/Rookout/GoSDK@v0.1.48/pkg/services/collection/variable/variables_cache.go (about) 1 package variable 2 3 import ( 4 "sync" 5 6 "github.com/Rookout/GoSDK/pkg/services/collection/memory" 7 "github.com/Rookout/GoSDK/pkg/services/instrumentation/dwarf/godwarf" 8 ) 9 10 type variablesCacheKey struct { 11 addr uint64 12 typ string 13 memID string 14 } 15 type VariablesCache struct { 16 m map[variablesCacheKey]*internalVariable 17 lock sync.RWMutex 18 } 19 20 func NewVariablesCache() *VariablesCache { 21 return &VariablesCache{m: make(map[variablesCacheKey]*internalVariable)} 22 } 23 24 func (v *VariablesCache) get(addr uint64, typ godwarf.Type, mem memory.MemoryReader) (*internalVariable, bool) { 25 v.lock.RLock() 26 defer v.lock.RUnlock() 27 defer recover() 28 29 iv, ok := v.m[variablesCacheKey{addr, typ.String(), mem.ID()}] 30 return iv, ok 31 } 32 33 func (v *VariablesCache) set(iv *internalVariable) { 34 v.lock.Lock() 35 defer v.lock.Unlock() 36 37 v.m[variablesCacheKey{iv.Addr, iv.DwarfType.String(), iv.Mem.ID()}] = iv 38 } 39 40 41 func (v *VariablesCache) Len() int { 42 return len(v.m) 43 }