Correct CPU core counts and report incomplete data size scans
This commit is contained in:
@@ -2,6 +2,7 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"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 {
|
if v, e := cpu.InfoWithContext(ctx); e == nil && len(v) > 0 {
|
||||||
r.Model = v[0].ModelName
|
r.Model = v[0].ModelName
|
||||||
}
|
}
|
||||||
r.LogicalCores, _ = cpu.CountsWithContext(ctx, false)
|
r.LogicalCores, _ = cpu.CountsWithContext(ctx, true)
|
||||||
r.PhysicalCores, _ = cpu.CountsWithContext(ctx, true)
|
r.PhysicalCores, _ = cpu.CountsWithContext(ctx, false)
|
||||||
if v, e := cpu.PercentWithContext(ctx, 500*time.Millisecond, true); e == nil {
|
if v, e := cpu.PercentWithContext(ctx, 500*time.Millisecond, true); e == nil {
|
||||||
r.PerCorePercent = v
|
r.PerCorePercent = v
|
||||||
for _, n := range v {
|
for _, n := range v {
|
||||||
@@ -214,6 +215,7 @@ func boundedSize(ctx context.Context, root string, match func(string) bool) (uin
|
|||||||
}
|
}
|
||||||
entries++
|
entries++
|
||||||
if entries > maxSizeWalkEntries {
|
if entries > maxSizeWalkEntries {
|
||||||
|
walkErr = errors.New("directory size is partial: entry limit reached")
|
||||||
return filepath.SkipAll
|
return filepath.SkipAll
|
||||||
}
|
}
|
||||||
if d.Type()&os.ModeSymlink != 0 {
|
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 !d.IsDir() && (match == nil || match(path)) {
|
||||||
if i, e := d.Info(); e == nil && i.Size() > 0 {
|
if i, e := d.Info(); e == nil && i.Size() > 0 {
|
||||||
n += uint64(i.Size())
|
n += uint64(i.Size())
|
||||||
|
} else if e != nil && walkErr == nil {
|
||||||
|
walkErr = e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -53,3 +53,14 @@ func TestBoundedSizeSkipsSymlinks(t *testing.T) {
|
|||||||
t.Fatalf("size=%d, want 4", got)
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user