Correct CPU core counts and report incomplete data size scans

This commit is contained in:
2026-11-07 01:38:59 +00:00
parent e579c06b45
commit dbf6398231
2 changed files with 17 additions and 2 deletions
+6 -2
View File
@@ -2,6 +2,7 @@ package server
import (
"context"
"errors"
"os"
"path/filepath"
"runtime"
@@ -94,8 +95,8 @@ func (s *systemStatsSampler) cpu(ctx context.Context, r *protocol.ServerCPUStats
if v, e := cpu.InfoWithContext(ctx); e == nil && len(v) > 0 {
r.Model = v[0].ModelName
}
r.LogicalCores, _ = cpu.CountsWithContext(ctx, false)
r.PhysicalCores, _ = cpu.CountsWithContext(ctx, true)
r.LogicalCores, _ = cpu.CountsWithContext(ctx, true)
r.PhysicalCores, _ = cpu.CountsWithContext(ctx, false)
if v, e := cpu.PercentWithContext(ctx, 500*time.Millisecond, true); e == nil {
r.PerCorePercent = v
for _, n := range v {
@@ -214,6 +215,7 @@ func boundedSize(ctx context.Context, root string, match func(string) bool) (uin
}
entries++
if entries > maxSizeWalkEntries {
walkErr = errors.New("directory size is partial: entry limit reached")
return filepath.SkipAll
}
if d.Type()&os.ModeSymlink != 0 {
@@ -225,6 +227,8 @@ func boundedSize(ctx context.Context, root string, match func(string) bool) (uin
if !d.IsDir() && (match == nil || match(path)) {
if i, e := d.Info(); e == nil && i.Size() > 0 {
n += uint64(i.Size())
} else if e != nil && walkErr == nil {
walkErr = e
}
}
return nil
+11
View File
@@ -53,3 +53,14 @@ func TestBoundedSizeSkipsSymlinks(t *testing.T) {
t.Fatalf("size=%d, want 4", got)
}
}
func TestBoundedSizeReportsIncompleteWalk(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
if _, err := boundedSize(ctx, t.TempDir(), nil); err != context.Canceled {
t.Fatalf("cancelled size walk error = %v", err)
}
if _, err := boundedSize(context.Background(), filepath.Join(t.TempDir(), "missing"), nil); err == nil {
t.Fatal("missing root must report a partial/unavailable size")
}
}