diff options
| author | chrislu <chris.lu@gmail.com> | 2022-01-22 01:35:12 -0800 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2022-01-22 01:35:12 -0800 |
| commit | e71dcfb3a6dc2e450de6ff9dbd68cf905b3a63ff (patch) | |
| tree | 068a7f4c03848c96dac7d4ddb78157415125664c | |
| parent | 9d0f58c3293a82aad258508a4a44e1027424c480 (diff) | |
| download | seaweedfs-e71dcfb3a6dc2e450de6ff9dbd68cf905b3a63ff.tar.xz seaweedfs-e71dcfb3a6dc2e450de6ff9dbd68cf905b3a63ff.zip | |
add logging for memory allocation
| -rw-r--r-- | weed/util/mem/slot_pool.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/weed/util/mem/slot_pool.go b/weed/util/mem/slot_pool.go index e6680d3cb..d5a55f23f 100644 --- a/weed/util/mem/slot_pool.go +++ b/weed/util/mem/slot_pool.go @@ -1,6 +1,10 @@ package mem -import "sync" +import ( + "github.com/chrislusf/seaweedfs/weed/glog" + "sync" + "sync/atomic" +) var pools []*sync.Pool @@ -34,11 +38,17 @@ func getSlotPool(size int) *sync.Pool { return pools[index] } +var total int64 + func Allocate(size int) []byte { + newVal := atomic.AddInt64(&total, 1) + glog.V(4).Infof("++> %d", newVal) slab := *getSlotPool(size).Get().(*[]byte) return slab[:size] } func Free(buf []byte) { + newVal := atomic.AddInt64(&total, -1) + glog.V(4).Infof("--> %d", newVal) getSlotPool(cap(buf)).Put(&buf) } |
