|
|
@@ -5,12 +5,17 @@ import "testing"
|
|
|
|
|
|
func TestMemUsagePct(t *testing.T) {
|
|
|
cases := []struct {
|
|
|
- name string
|
|
|
- total, free, buff, cach, av float64
|
|
|
- want int
|
|
|
+ name string
|
|
|
+ total, free, buff, cach, av, usedProc float64
|
|
|
+ want int
|
|
|
}{
|
|
|
{
|
|
|
- // rt3 AX6 real: con Cached (fórmula clásica) baja del 79% al 67%.
|
|
|
+ // Con usedProc (RSS de procesos) se usa ese valor directamente: es
|
|
|
+ // lo que el usuario percibe como uso real (netgrip #279).
|
|
|
+ name: "rt3 con usedProc rss", total: 414264, free: 57364, buff: 0, cach: 94136, av: 99684, usedProc: 78000, want: 19,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ // Sin usedProc pero con Cached (fórmula clásica) baja del 79% al 67%.
|
|
|
name: "rt3 con cached", total: 414264, free: 45780, buff: 0, cach: 90464, av: 88088, want: 67,
|
|
|
},
|
|
|
{
|
|
|
@@ -26,11 +31,16 @@ func TestMemUsagePct(t *testing.T) {
|
|
|
// Sin available, cae a free+buffered.
|
|
|
name: "sin available", total: 1000, free: 100, buff: 50, cach: 0, av: 0, want: 85,
|
|
|
},
|
|
|
+ {
|
|
|
+ // usedProc mayor que total se ignora y cae a la fórmula clásica
|
|
|
+ // (con Cached): used = total - free - buffered - cached.
|
|
|
+ name: "usedProc invalido", total: 1000, free: 100, buff: 0, cach: 400, av: 0, usedProc: 5000, want: 50,
|
|
|
+ },
|
|
|
{name: "cached mayor que el resto", total: 100, free: 0, buff: 0, cach: 500, av: 0, want: 0},
|
|
|
{name: "total cero", total: 0, free: 0, buff: 0, cach: 0, av: 0, want: 0},
|
|
|
}
|
|
|
for _, tc := range cases {
|
|
|
- got := memUsagePct(tc.total, tc.free, tc.buff, tc.cach, tc.av)
|
|
|
+ got := memUsagePct(tc.total, tc.free, tc.buff, tc.cach, tc.av, tc.usedProc)
|
|
|
if got != tc.want {
|
|
|
t.Errorf("%s: got %d, want %d", tc.name, got, tc.want)
|
|
|
}
|