feat: implement enhanced garbage collection statistics logging
All checks were successful
Release Tag / release (push) Successful in 12s

This commit is contained in:
2025-01-22 20:27:12 -06:00
parent 4a23eecae0
commit 550948951e
4 changed files with 97 additions and 91 deletions

View File

@@ -6,7 +6,6 @@ import (
"s1d3sw1ped/SteamCache2/vfs/memory"
"sort"
"testing"
"time"
"golang.org/x/exp/rand"
)
@@ -15,13 +14,11 @@ func TestGCSmallRandom(t *testing.T) {
t.Parallel()
m := memory.New(1024 * 1024 * 16)
gc := New(m, 10, func(vfs vfs.VFS, size int) {
tstart := time.Now()
gc := New(m, 10, func(vfs vfs.VFS, size uint) (uint, uint) {
deletions := 0
targetreclaim := int64(size)
var reclaimed int64
var reclaimed uint
t.Logf("GC starting to reclaim %d bytes", targetreclaim)
t.Logf("GC starting to reclaim %d bytes", size)
stats := vfs.StatAll()
sort.Slice(stats, func(i, j int) bool {
@@ -31,7 +28,7 @@ func TestGCSmallRandom(t *testing.T) {
// Delete the oldest files until we've reclaimed enough space.
for _, s := range stats {
sz := s.Size() // Get the size of the file
sz := uint(s.Size()) // Get the size of the file
err := vfs.Delete(s.Name())
if err != nil {
panic(err)
@@ -41,12 +38,11 @@ func TestGCSmallRandom(t *testing.T) {
// t.Logf("GC deleting %s, %v", s.Name(), s.AccessTime().Format(time.RFC3339Nano))
if reclaimed >= targetreclaim { // We've reclaimed enough space
if reclaimed >= size { // We've reclaimed enough space
break
}
}
t.Logf("GC took %v to reclaim %d bytes by deleting %d files", time.Since(tstart), reclaimed, deletions)
return uint(reclaimed), uint(deletions)
})
for i := 0; i < 10000; i++ {
@@ -70,13 +66,11 @@ func TestGCLargeRandom(t *testing.T) {
t.Parallel()
m := memory.New(1024 * 1024 * 16) // 16MB
gc := New(m, 10, func(vfs vfs.VFS, size int) {
tstart := time.Now()
gc := New(m, 10, func(vfs vfs.VFS, size uint) (uint, uint) {
deletions := 0
targetreclaim := int64(size)
var reclaimed int64
var reclaimed uint
t.Logf("GC starting to reclaim %d bytes", targetreclaim)
t.Logf("GC starting to reclaim %d bytes", size)
stats := vfs.StatAll()
sort.Slice(stats, func(i, j int) bool {
@@ -86,17 +80,17 @@ func TestGCLargeRandom(t *testing.T) {
// Delete the oldest files until we've reclaimed enough space.
for _, s := range stats {
sz := s.Size() // Get the size of the file
sz := uint(s.Size()) // Get the size of the file
vfs.Delete(s.Name())
reclaimed += sz // Track how much space we've reclaimed
deletions++ // Track how many files we've deleted
if reclaimed >= targetreclaim { // We've reclaimed enough space
if reclaimed >= size { // We've reclaimed enough space
break
}
}
t.Logf("GC took %v to reclaim %d bytes by deleting %d files", time.Since(tstart), reclaimed, deletions)
return uint(reclaimed), uint(deletions)
})
for i := 0; i < 10000; i++ {