github.com/scottcagno/storage@v1.8.0/pkg/lsmt/stats.go (about)

     1  package lsmt
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"strings"
     7  )
     8  
     9  type LSMTreeStats struct {
    10  	Config    *LSMConfig `json:"config,omitempty"`
    11  	MtEntries int        `json:"mt_entries,omitempty"`
    12  	MtSize    int64      `json:"mt_size,omitempty"`
    13  	BfEntries int        `json:"bf_entries,omitempty"`
    14  	BfSize    int64      `json:"bf_size,omitempty"`
    15  }
    16  
    17  func (s *LSMTreeStats) String() string {
    18  	var ss []string
    19  	ss = append(ss, fmt.Sprintf("%T", s))
    20  	ss = append(ss, fmt.Sprintf("\tConfig: %v", s.Config))
    21  	ss = append(ss, fmt.Sprintf("\tMtEntries: %v", s.MtEntries))
    22  	ss = append(ss, fmt.Sprintf("\tMtSize: %v", s.MtSize))
    23  	ss = append(ss, fmt.Sprintf("\tBfEntries: %v", s.BfEntries))
    24  	ss = append(ss, fmt.Sprintf("\tBfSize: %v", s.BfSize))
    25  	return strings.Join(ss, "\n")
    26  }
    27  
    28  func (s *LSMTreeStats) JSON() (string, error) {
    29  	dat, err := json.MarshalIndent(s, "", "\t")
    30  	if err != nil {
    31  		return "", err
    32  	}
    33  	return string(dat), nil
    34  }