diff options
Diffstat (limited to 'internal/cpu/types.go')
| -rw-r--r-- | internal/cpu/types.go | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/internal/cpu/types.go b/internal/cpu/types.go index 58da0a9..45f6ff5 100644 --- a/internal/cpu/types.go +++ b/internal/cpu/types.go @@ -1,7 +1,10 @@ // Package cpu provides CPU stress testing with multiple algorithms and chaos modes. package cpu -import "time" +import ( + "runtime" + "time" +) // types.go defines the configuration types and mode constants for CPU stress testing. @@ -18,7 +21,6 @@ const ( ModeEncrypt Mode = "encrypt" ModeSort Mode = "sort" ModeBusy Mode = "busy" - ModeRandom Mode = "random" ) var allModes = []Mode{ @@ -42,4 +44,24 @@ type Config struct { ChaosInterval time.Duration IntensityMin int IntensityMax int + MinCPUs int + MaxCPUs int +} + +func (c *Config) normalize() { + if c.MinCPUs <= 0 { + c.MinCPUs = 1 + } + if c.MaxCPUs <= 0 { + c.MaxCPUs = runtime.NumCPU() + } + if c.MinCPUs > runtime.NumCPU() { + c.MinCPUs = runtime.NumCPU() + } + if c.MaxCPUs > runtime.NumCPU() { + c.MaxCPUs = runtime.NumCPU() + } + if c.MinCPUs > c.MaxCPUs { + c.MinCPUs, c.MaxCPUs = c.MaxCPUs, c.MinCPUs + } } |
