cubefs/vendor/github.com/tecbot/gorocksdb/memory_usage.go
yuxiaobo ac75137295 build: the build script of blobstore is merged into cubefs
1. rocksdb upgrade to 6.3.6
2. optimize the build scripts
3. fix build errors
4. add env variable for blobstore unit test
5. update git ignore file to ignore build and test result
6. modify open files limit for unit test

Signed-off-by: yuxiaobo <yuxiaobo@oppo.com>
Signed-off-by: slasher <shenjie1@oppo.com>
Signed-off-by: Victor1319 <834863182@qq.com>
2023-05-23 15:24:53 +08:00

59 lines
1.8 KiB
Go

package gorocksdb
// #include <stdlib.h>
// #include "rocksdb/c.h"
import "C"
import (
"errors"
"unsafe"
)
// MemoryUsage contains memory usage statistics provided by RocksDB
type MemoryUsage struct {
// MemTableTotal estimates memory usage of all mem-tables
MemTableTotal uint64
// MemTableUnflushed estimates memory usage of unflushed mem-tables
MemTableUnflushed uint64
// MemTableReadersTotal memory usage of table readers (indexes and bloom filters)
MemTableReadersTotal uint64
// CacheTotal memory usage of cache
CacheTotal uint64
}
// GetApproximateMemoryUsageByType returns summary
// memory usage stats for given databases and caches.
func GetApproximateMemoryUsageByType(dbs []*DB, caches []*Cache) (*MemoryUsage, error) {
// register memory consumers
consumers := C.rocksdb_memory_consumers_create()
defer C.rocksdb_memory_consumers_destroy(consumers)
for _, db := range dbs {
if db != nil {
C.rocksdb_memory_consumers_add_db(consumers, db.c)
}
}
for _, cache := range caches {
if cache != nil {
C.rocksdb_memory_consumers_add_cache(consumers, cache.c)
}
}
// obtain memory usage stats
var cErr *C.char
memoryUsage := C.rocksdb_approximate_memory_usage_create(consumers, &cErr)
if cErr != nil {
defer C.rocksdb_free(unsafe.Pointer(cErr))
return nil, errors.New(C.GoString(cErr))
}
defer C.rocksdb_approximate_memory_usage_destroy(memoryUsage)
result := &MemoryUsage{
MemTableTotal: uint64(C.rocksdb_approximate_memory_usage_get_mem_table_total(memoryUsage)),
MemTableUnflushed: uint64(C.rocksdb_approximate_memory_usage_get_mem_table_unflushed(memoryUsage)),
MemTableReadersTotal: uint64(C.rocksdb_approximate_memory_usage_get_mem_table_readers_total(memoryUsage)),
CacheTotal: uint64(C.rocksdb_approximate_memory_usage_get_cache_total(memoryUsage)),
}
return result, nil
}