(db *badger.DB)
| 895 | } |
| 896 | |
| 897 | func printSummary(db *badger.DB) { |
| 898 | nsFromKey := func(key []byte) uint64 { |
| 899 | pk, err := x.Parse(key) |
| 900 | if err != nil { |
| 901 | // Some of the keys are badger's internal and couldn't be parsed. |
| 902 | // Hence, the error is expected in that case. |
| 903 | fmt.Printf("Unable to parse key: %#x\n", key) |
| 904 | return x.RootNamespace |
| 905 | } |
| 906 | return x.ParseNamespace(pk.Attr) |
| 907 | } |
| 908 | banned := db.BannedNamespaces() |
| 909 | bannedNs := make(map[uint64]struct{}) |
| 910 | for _, ns := range banned { |
| 911 | bannedNs[ns] = struct{}{} |
| 912 | } |
| 913 | |
| 914 | tables := db.Tables() |
| 915 | levelSizes := make([]uint64, len(db.Levels())) |
| 916 | nsSize := make(map[uint64]uint64) |
| 917 | for _, tab := range tables { |
| 918 | levelSizes[tab.Level] += uint64(tab.OnDiskSize) |
| 919 | if nsFromKey(tab.Left) == nsFromKey(tab.Right) { |
| 920 | nsSize[nsFromKey(tab.Left)] += uint64(tab.OnDiskSize) |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | fmt.Println("[SUMMARY]") |
| 925 | totalSize := uint64(0) |
| 926 | for i, sz := range levelSizes { |
| 927 | fmt.Printf("Level %d size: %12s\n", i, humanize.IBytes(sz)) |
| 928 | totalSize += sz |
| 929 | } |
| 930 | fmt.Printf("Total SST size: %12s\n", humanize.IBytes(totalSize)) |
| 931 | fmt.Println() |
| 932 | for ns, sz := range nsSize { |
| 933 | fmt.Printf("Namespace %#x size: %12s", ns, humanize.IBytes(sz)) |
| 934 | if _, ok := bannedNs[ns]; ok { |
| 935 | fmt.Printf(" (banned)") |
| 936 | } |
| 937 | fmt.Println() |
| 938 | } |
| 939 | fmt.Println() |
| 940 | } |
| 941 | |
| 942 | func run() { |
| 943 | go func() { |
no test coverage detected