From 5f4dd076a57acff61560c32a9e3e64196a6dc221 Mon Sep 17 00:00:00 2001 From: yzang2019 Date: Thu, 19 Dec 2024 14:45:49 -0800 Subject: [PATCH] Add key and value size breakdown --- tools/cmd/seidb/operations/state_size.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/cmd/seidb/operations/state_size.go b/tools/cmd/seidb/operations/state_size.go index 7afd8a6..c89ea3e 100644 --- a/tools/cmd/seidb/operations/state_size.go +++ b/tools/cmd/seidb/operations/state_size.go @@ -65,22 +65,28 @@ func PrintStateSize(module string, db *memiavl.DB) error { fmt.Printf("Tree does not exist for module %s \n", moduleName) } else { fmt.Printf("Calculating for module: %s \n", moduleName) - sizeByPrefix := map[string]int{} + keySizeByPrefix := map[string]int{} + valueSizeByPrefix := map[string]int{} tree.ScanPostOrder(func(node memiavl.Node) bool { if node.IsLeaf() { totalNumKeys++ - totalKeySize += len(node.Key()) - totalValueSize += len(node.Value()) - totalSize += len(node.Key()) + len(node.Value()) + keySize := len(node.Key()) + valueSize := len(node.Value()) + totalKeySize += keySize + totalValueSize += valueSize + totalSize += keySize + valueSize prefix := fmt.Sprintf("%X", node.Key()) prefix = prefix[:2] - sizeByPrefix[prefix] += len(node.Value()) + keySizeByPrefix[prefix] += keySize + valueSizeByPrefix[prefix] += valueSize } return true }) fmt.Printf("Module %s total numKeys:%d, total keySize:%d, total valueSize:%d, totalSize: %d \n", moduleName, totalNumKeys, totalKeySize, totalValueSize, totalSize) - result, _ := json.MarshalIndent(sizeByPrefix, "", " ") - fmt.Printf("Module %s prefix breakdown: %s \n", moduleName, result) + prefixKeyResult, _ := json.MarshalIndent(keySizeByPrefix, "", " ") + 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) } } return nil