From 79562f9cd0e515bca5964a0f8f0e592a7e2859ef Mon Sep 17 00:00:00 2001 From: clinx Date: Wed, 26 Mar 2025 17:01:38 +0800 Subject: [PATCH] feat(client): print cache size in stat file #23068759 Signed-off-by: clinx --- client/fs/super.go | 6 +++++- sdk/meta/meta.go | 4 ++++ util/stat/statistic.go | 8 +++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/client/fs/super.go b/client/fs/super.go index 78e7e01f9..75bc83f54 100644 --- a/client/fs/super.go +++ b/client/fs/super.go @@ -15,6 +15,7 @@ package fs import ( + "bufio" "context" "fmt" "net/http" @@ -39,6 +40,7 @@ import ( "github.com/cubefs/cubefs/util/auditlog" "github.com/cubefs/cubefs/util/errors" "github.com/cubefs/cubefs/util/log" + "github.com/cubefs/cubefs/util/stat" "github.com/cubefs/cubefs/util/ump" ) @@ -320,7 +322,9 @@ func NewSuper(opt *proto.MountOptions) (s *Super, err error) { log.LogInfof("NewSuper: cluster(%v) volname(%v) icacheExpiration(%v) LookupValidDuration(%v) AttrValidDuration(%v) state(%v) cacheDpStorageClass(%v)", s.cluster, s.volname, inodeExpiration, LookupValidDuration, AttrValidDuration, s.state, s.cacheDpStorageClass) - + stat.PrintModuleStat = func(writer *bufio.Writer) { + fmt.Fprintf(writer, "ic:%d dc:%d nodecache:%d dircache:%d", s.ic.lruList.Len(), s.dc.lruList.Len(), len(s.nodeCache), s.mw.DirCacheLen()) + } go s.loopSyncMeta() return s, nil diff --git a/sdk/meta/meta.go b/sdk/meta/meta.go index 8bf9b36b7..c5d049530 100644 --- a/sdk/meta/meta.go +++ b/sdk/meta/meta.go @@ -338,6 +338,10 @@ func (mw *MetaWrapper) Owner() string { return mw.owner } +func (mw *MetaWrapper) DirCacheLen() int { + return len(mw.dirCache) +} + func (mw *MetaWrapper) enableTx(mask proto.TxOpMask) bool { return mw.EnableTransaction != proto.TxPause && mw.EnableTransaction&mask > 0 } diff --git a/util/stat/statistic.go b/util/stat/statistic.go index 8d226307f..1a5ee2859 100644 --- a/util/stat/statistic.go +++ b/util/stat/statistic.go @@ -53,6 +53,10 @@ var re = regexp.MustCompile(`\([0-9]*\)`) type ShiftedFile []os.FileInfo +type ModuleGlobalStat func(*bufio.Writer) + +var PrintModuleStat ModuleGlobalStat + func (f ShiftedFile) Less(i, j int) bool { return f[i].ModTime().Before(f[j].ModTime()) } @@ -250,7 +254,9 @@ func WriteStat() error { } else { fmt.Fprintf(ioStream, "Mem Allocated(kB): VIRT %-10d RES %-10d\n", virt, res) } - + if PrintModuleStat != nil { + PrintModuleStat(ioStream) + } fmt.Fprintf(ioStream, "%-42s|%10s|%8s|%8s|%8s|%8s|%8s|%8s|%8s|\n", "", "TOTAL", "FAILED", "AVG(ms)", "MAX(ms)", "MIN(ms)", ">"+strconv.Itoa(int(gSt.timeOutUs[0])/1000)+"ms",