This commit is contained in:
12600k-rog-d4
2026-08-13 22:49:50 +08:00
parent 5e296bfe19
commit 2aaaa16ae2
24 changed files with 1415 additions and 327 deletions

View File

@@ -1,6 +1,7 @@
package stress
import (
"fmt"
"time"
)
@@ -10,10 +11,11 @@ import (
// Metric 测试指标(定义测什么、用什么工具、怎么判结果)
type Metric struct {
Name string // 指标名称cpu/memory/disk/memnative/full
Tool string // 依赖的工具stress-ng/stressapptest
Enabled bool // 是否启用
IsMonitor bool // 是否为监控指标temp/dmesg自动附加
Name string // 指标名称cpu/memory/disk/memnative/full
Tool string // 依赖的工具stress-ng/stressapptest/fio
Enabled bool // 是否启用
IsMonitor bool // 是否为监控指标temp/dmesg自动附加
DisableReason string // 禁用时展示的原因
}
// BuildMetrics 根据配置和可用工具,生成要执行的指标列表
@@ -28,16 +30,36 @@ func BuildMetrics(types []TestType, tools ToolSet) []Metric {
case TestMemory:
m.Tool = "stress-ng"
case TestDiskIO:
m.Tool = "stress-ng"
// disk 优先 fio无 fio 可降级 stress-ng
switch {
case tools.Has("fio"):
m.Tool = "fio"
case tools.Has("stress-ng"):
m.Tool = "stress-ng"
default:
m.Tool = "fio"
}
case TestMemNative:
m.Tool = "stressapptest"
case TestFull:
m.Tool = "stress-ng"
default:
m.Enabled = false
m.DisableReason = "未知测试类型"
}
if m.Tool != "" && !tools.Has(m.Tool) {
m.Enabled = false // 工具可用,禁用
// 根据工具可用性决定是否禁用,并记录原因
switch t {
case TestDiskIO:
if !tools.Has("fio") && !tools.Has("stress-ng") {
m.Enabled = false
m.DisableReason = "缺少 fio 或 stress-ng"
}
default:
if m.Tool != "" && !tools.Has(m.Tool) {
m.Enabled = false
m.DisableReason = fmt.Sprintf("缺少 %s", m.Tool)
}
}
metrics = append(metrics, m)
}
@@ -61,6 +83,7 @@ type Config struct {
DiskSizeMB int // 0=默认1024
DiskDir string // 空=自动临时目录
TempLogInt time.Duration // 0=10s
TempLimit float64 // 温度上限(°C)0=不判定
}
// DefaultConfig 默认配置
@@ -70,5 +93,6 @@ func DefaultConfig() Config {
Threads: 4,
DiskSizeMB: 1024,
TempLogInt: 10 * time.Second,
TempLimit: 90,
}
}