Skip to content

Commit

Permalink
Merge pull request #83 from sei-protocol/yzang/add-count
Browse files Browse the repository at this point in the history
Add num of keys for state dump
  • Loading branch information
yzang2019 authored Jan 24, 2025
2 parents 77c7807 + 7930272 commit b91cba5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/cmd/seidb/operations/state_size.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func PrintStateSize(module string, db *memiavl.DB) error {
fmt.Printf("Calculating for module: %s \n", moduleName)
keySizeByPrefix := map[string]int64{}
valueSizeByPrefix := map[string]int64{}
numKeysByPrefix := map[string]int64{}
tree.ScanPostOrder(func(node memiavl.Node) bool {
if node.IsLeaf() {
totalNumKeys++
Expand All @@ -81,6 +82,7 @@ func PrintStateSize(module string, db *memiavl.DB) error {
prefix = prefix[:2]
keySizeByPrefix[prefix] += int64(keySize)
valueSizeByPrefix[prefix] += int64(valueSize)
numKeysByPrefix[prefix]++
}
return true
})
Expand All @@ -89,6 +91,8 @@ func PrintStateSize(module string, db *memiavl.DB) error {
fmt.Printf("Module %s prefix key size breakdown (bytes): %s \n", moduleName, prefixKeyResult)
prefixValueResult, _ := json.MarshalIndent(valueSizeByPrefix, "", " ")
fmt.Printf("Module %s prefix value size breakdown (bytes): %s \n", moduleName, prefixValueResult)
numKeysResult, _ := json.MarshalIndent(numKeysByPrefix, "", " ")
fmt.Printf("Module %s prefix num of keys breakdown: %s \n", moduleName, numKeysResult)

// Print top 20 contracts by total size
numToShow := 20
Expand Down

0 comments on commit b91cba5

Please sign in to comment.