diff --git a/unmaintained/see_dat/see_dat.go b/unmaintained/see_dat/see_dat.go index efc58e751..f86936364 100644 --- a/unmaintained/see_dat/see_dat.go +++ b/unmaintained/see_dat/see_dat.go @@ -2,6 +2,7 @@ package main import ( "flag" + master_ui "github.com/chrislusf/seaweedfs/weed/server/volume_server_ui" "time" "github.com/chrislusf/seaweedfs/weed/glog" @@ -25,13 +26,17 @@ func (scanner *VolumeFileScanner4SeeDat) VisitSuperBlock(superBlock super_block. return nil } -func (scanner *VolumeFileScanner4SeeDat) ReadNeedleBody() bool { - return true -} +func (scanner *VolumeFileScanner4SeeDat) ReadNeedleBody() bool { return true } func (scanner *VolumeFileScanner4SeeDat) VisitNeedle(n *needle.Needle, offset int64, needleHeader, needleBody []byte) error { t := time.Unix(int64(n.AppendAtNs)/int64(time.Second), int64(n.AppendAtNs)%int64(time.Second)) - glog.V(0).Infof("%d,%s%x offset %d size %d cookie %x appendedAt %v", *volumeId, n.Id, n.Cookie, offset, n.Size, n.Cookie, t) + + if readable, ok := master_ui.BytesToHumanReadable(uint64(n.Size)); ok { + glog.V(0).Infof("%d,%s%x offset %d size %d (%s) cookie %x appendedAt %v", *volumeId, n.Id, n.Cookie, offset, n.Size, readable, n.Cookie, t) + } else { + glog.V(0).Infof("%d,%s%x offset %d size %d cookie %x appendedAt %v", *volumeId, n.Id, n.Cookie, offset, n.Size, n.Cookie, t) + } + return nil } diff --git a/unmaintained/see_idx/see_idx.go b/unmaintained/see_idx/see_idx.go index 777af1821..095e2c5e3 100644 --- a/unmaintained/see_idx/see_idx.go +++ b/unmaintained/see_idx/see_idx.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + master_ui "github.com/chrislusf/seaweedfs/weed/server/volume_server_ui" "os" "path" "strconv" @@ -36,8 +37,11 @@ func main() { defer indexFile.Close() idx.WalkIndexFile(indexFile, func(key types.NeedleId, offset types.Offset, size uint32) error { - fmt.Printf("key:%v offset:%v size:%v\n", key, offset, size) + if readable, ok := master_ui.BytesToHumanReadable(uint64(size)); ok { + fmt.Printf("key:%v offset:%v size:%v (%s)\n", key, offset, size, readable) + } else { + fmt.Printf("key:%v offset:%v size:%v\n", key, offset, size) + } return nil }) - } diff --git a/weed/server/volume_server_ui/templates.go b/weed/server/volume_server_ui/templates.go index a3175e9ca..d703518cc 100644 --- a/weed/server/volume_server_ui/templates.go +++ b/weed/server/volume_server_ui/templates.go @@ -7,8 +7,16 @@ import ( "strings" ) +const unit = 1024 + +// BytesToHumanReadable exposes the bytesToHumanReadble. +// It returns the converted human readable representation of the bytes +// and the conversion state that true for conversion realy occurred or false for no conversion. +func BytesToHumanReadable(b uint64) (string, bool) { + return bytesToHumanReadble(b), b >= unit +} + func bytesToHumanReadble(b uint64) string { - const unit = 1024 if b < unit { return fmt.Sprintf("%d B", b) }