feat: enhance garbage collection logging with total GC time and improved stat formatting
All checks were successful
Release Tag / release (push) Successful in 9s
All checks were successful
Release Tag / release (push) Successful in 9s
This commit is contained in:
@@ -145,7 +145,7 @@ func (sc *SteamCache) LogStats() {
|
|||||||
if sc.dirty {
|
if sc.dirty {
|
||||||
|
|
||||||
if sc.memory != nil { // only log memory if memory is enabled
|
if sc.memory != nil { // only log memory if memory is enabled
|
||||||
lifetimeBytes, lifetimeFiles, reclaimedBytes, deletedFiles := sc.memorygc.Stats()
|
lifetimeBytes, lifetimeFiles, reclaimedBytes, deletedFiles, gcTime := sc.memorygc.Stats()
|
||||||
|
|
||||||
logger.Logger.Info().
|
logger.Logger.Info().
|
||||||
Str("size", units.HumanSize(float64(sc.memory.Size()))).
|
Str("size", units.HumanSize(float64(sc.memory.Size()))).
|
||||||
@@ -154,15 +154,16 @@ func (sc *SteamCache) LogStats() {
|
|||||||
Msg("memory")
|
Msg("memory")
|
||||||
|
|
||||||
logger.Logger.Info().
|
logger.Logger.Info().
|
||||||
Str("lifetime", units.HumanSize(float64(lifetimeBytes))).
|
Str("data_total", units.HumanSize(float64(lifetimeBytes))).
|
||||||
Uint("lifetime_files", lifetimeFiles).
|
Uint("files_total", lifetimeFiles).
|
||||||
Str("reclaimed", units.HumanSize(float64(reclaimedBytes))).
|
Str("data", units.HumanSize(float64(reclaimedBytes))).
|
||||||
Uint("deleted_files", deletedFiles).
|
Uint("files", deletedFiles).
|
||||||
|
Str("gc_time", gcTime.String()).
|
||||||
Msg("memory_gc")
|
Msg("memory_gc")
|
||||||
}
|
}
|
||||||
|
|
||||||
if sc.disk != nil { // only log disk if disk is enabled
|
if sc.disk != nil { // only log disk if disk is enabled
|
||||||
lifetimeBytes, lifetimeFiles, reclaimedBytes, deletedFiles := sc.diskgc.Stats()
|
lifetimeBytes, lifetimeFiles, reclaimedBytes, deletedFiles, gcTime := sc.diskgc.Stats()
|
||||||
|
|
||||||
logger.Logger.Info().
|
logger.Logger.Info().
|
||||||
Str("size", units.HumanSize(float64(sc.disk.Size()))).
|
Str("size", units.HumanSize(float64(sc.disk.Size()))).
|
||||||
@@ -171,10 +172,11 @@ func (sc *SteamCache) LogStats() {
|
|||||||
Msg("disk")
|
Msg("disk")
|
||||||
|
|
||||||
logger.Logger.Info().
|
logger.Logger.Info().
|
||||||
Str("lifetime", units.HumanSize(float64(lifetimeBytes))).
|
Str("data_total", units.HumanSize(float64(lifetimeBytes))).
|
||||||
Uint("lifetime_files", lifetimeFiles).
|
Uint("files_total", lifetimeFiles).
|
||||||
Str("reclaimed", units.HumanSize(float64(reclaimedBytes))).
|
Str("data", units.HumanSize(float64(reclaimedBytes))).
|
||||||
Uint("deleted_files", deletedFiles).
|
Uint("files", deletedFiles).
|
||||||
|
Str("gc_time", gcTime.String()).
|
||||||
Msg("disk_gc")
|
Msg("disk_gc")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,12 @@ func (d *DiskFS) init() {
|
|||||||
d.walk(d.root)
|
d.walk(d.root)
|
||||||
d.sg.Wait()
|
d.sg.Wait()
|
||||||
|
|
||||||
logger.Logger.Info().Str("name", d.Name()).Str("root", d.root).Str("capacity", units.HumanSize(float64(d.capacity))).Str("duration", time.Since(tstart).String()).Msg("init")
|
logger.Logger.Info().
|
||||||
|
Str("name", d.Name()).
|
||||||
|
Str("root", d.root).
|
||||||
|
Str("capacity", units.HumanSize(float64(d.capacity))).
|
||||||
|
Str("duration", time.Since(tstart).String()).
|
||||||
|
Msg("init")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DiskFS) walk(path string) {
|
func (d *DiskFS) walk(path string) {
|
||||||
|
|||||||
13
vfs/gc/gc.go
13
vfs/gc/gc.go
@@ -5,6 +5,7 @@ import (
|
|||||||
"s1d3sw1ped/SteamCache2/vfs"
|
"s1d3sw1ped/SteamCache2/vfs"
|
||||||
"s1d3sw1ped/SteamCache2/vfs/vfserror"
|
"s1d3sw1ped/SteamCache2/vfs/vfserror"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Ensure GCFS implements VFS.
|
// Ensure GCFS implements VFS.
|
||||||
@@ -19,6 +20,7 @@ type GCFS struct {
|
|||||||
gcHanderFunc GCHandlerFunc
|
gcHanderFunc GCHandlerFunc
|
||||||
lifetimeBytes, lifetimeFiles uint
|
lifetimeBytes, lifetimeFiles uint
|
||||||
reclaimedBytes, deletedFiles uint
|
reclaimedBytes, deletedFiles uint
|
||||||
|
gcTime time.Duration
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,9 +40,10 @@ func New(vfs vfs.VFS, multiplier int, gcHandlerFunc GCHandlerFunc) *GCFS {
|
|||||||
|
|
||||||
// Stats returns the lifetime bytes, lifetime files, reclaimed bytes and deleted files.
|
// Stats returns the lifetime bytes, lifetime files, reclaimed bytes and deleted files.
|
||||||
// The lifetime bytes and lifetime files are the total bytes and files that have been freed up by the GC handler.
|
// The lifetime bytes and lifetime files are the total bytes and files that have been freed up by the GC handler.
|
||||||
// The reclaimed bytes and deleted files are the bytes and files that have been freed up by the GC handler since the last execution.
|
// The reclaimed bytes and deleted files are the bytes and files that have been freed up by the GC handler since last call to Stats.
|
||||||
// The reclaimed bytes and deleted files are reset to 0 after the call to Stats.
|
// The gc time is the total time spent in the GC handler since last call to Stats.
|
||||||
func (g *GCFS) Stats() (lifetimeBytes, lifetimeFiles, reclaimedBytes, deletedFiles uint) {
|
// The reclaimed bytes and deleted files and gc time are reset to 0 after the call to Stats.
|
||||||
|
func (g *GCFS) Stats() (lifetimeBytes, lifetimeFiles, reclaimedBytes, deletedFiles uint, gcTime time.Duration) {
|
||||||
g.mu.Lock()
|
g.mu.Lock()
|
||||||
defer g.mu.Unlock()
|
defer g.mu.Unlock()
|
||||||
|
|
||||||
@@ -51,9 +54,11 @@ func (g *GCFS) Stats() (lifetimeBytes, lifetimeFiles, reclaimedBytes, deletedFil
|
|||||||
lifetimeFiles = g.lifetimeFiles
|
lifetimeFiles = g.lifetimeFiles
|
||||||
reclaimedBytes = g.reclaimedBytes
|
reclaimedBytes = g.reclaimedBytes
|
||||||
deletedFiles = g.deletedFiles
|
deletedFiles = g.deletedFiles
|
||||||
|
gcTime = g.gcTime
|
||||||
|
|
||||||
g.reclaimedBytes = 0
|
g.reclaimedBytes = 0
|
||||||
g.deletedFiles = 0
|
g.deletedFiles = 0
|
||||||
|
g.gcTime = time.Duration(0)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -65,7 +70,9 @@ func (g *GCFS) Set(key string, src []byte) error {
|
|||||||
err := g.VFS.Set(key, src) // try to set the key and src
|
err := g.VFS.Set(key, src) // try to set the key and src
|
||||||
|
|
||||||
if err == vfserror.ErrDiskFull && g.gcHanderFunc != nil { // if the error is disk full and there is a GC handler
|
if err == vfserror.ErrDiskFull && g.gcHanderFunc != nil { // if the error is disk full and there is a GC handler
|
||||||
|
tstart := time.Now()
|
||||||
reclaimedBytes, deletedFiles := g.gcHanderFunc(g.VFS, uint(len(src)*g.multiplier)) // call the GC handler
|
reclaimedBytes, deletedFiles := g.gcHanderFunc(g.VFS, uint(len(src)*g.multiplier)) // call the GC handler
|
||||||
|
g.gcTime += time.Since(tstart)
|
||||||
g.reclaimedBytes += reclaimedBytes
|
g.reclaimedBytes += reclaimedBytes
|
||||||
g.deletedFiles += deletedFiles
|
g.deletedFiles += deletedFiles
|
||||||
err = g.VFS.Set(key, src) // try again after GC if it still fails return the error
|
err = g.VFS.Set(key, src) // try again after GC if it still fails return the error
|
||||||
|
|||||||
Reference in New Issue
Block a user