diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-04 23:28:48 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-04 23:28:48 +0300 |
| commit | d0a5493e9710f4b515ad5825aeee3c0102d03ee7 (patch) | |
| tree | 8f8ddcbf96beb517252ce525060382f22b83fa6a /internal/cpu/stresser.go | |
| parent | 2f09915d3da7a23574e1a90fa70eb1af1cdf830a (diff) | |
renamemain
Diffstat (limited to 'internal/cpu/stresser.go')
| -rw-r--r-- | internal/cpu/stresser.go | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/internal/cpu/stresser.go b/internal/cpu/stresser.go index 906467a..62ae3b7 100644 --- a/internal/cpu/stresser.go +++ b/internal/cpu/stresser.go @@ -13,12 +13,13 @@ import ( // Stresser uses pointer receivers because it contains a sync.Mutex // and shared mutable state that must not be copied. type Stresser struct { - config Config - cancel context.CancelFunc - wg sync.WaitGroup - mu sync.Mutex - current Mode - rand *rand.Rand + config Config + cancel context.CancelFunc + wg sync.WaitGroup + mu sync.Mutex + current Mode + currentCPUs int + rand *rand.Rand } func New(cfg Config) *Stresser { @@ -34,6 +35,11 @@ func New(cfg Config) *Stresser { if cfg.Mode == "" { cfg.Mode = ModePrime } + if !cfg.ChaosEnabled && cfg.MinCPUs <= 0 { + cfg.MinCPUs = cfg.Workers + cfg.MaxCPUs = cfg.Workers + } + cfg.normalize() return &Stresser{ config: cfg, rand: rand.New(rand.NewSource(time.Now().UnixNano())), @@ -44,8 +50,12 @@ func (s *Stresser) Start() { ctx, cancel := context.WithCancel(context.Background()) s.cancel = cancel - s.wg.Add(s.config.Workers) - for i := 0; i < s.config.Workers; i++ { + s.mu.Lock() + s.currentCPUs = s.determineCPUCount() + s.mu.Unlock() + + s.wg.Add(s.currentCPUs) + for i := 0; i < s.currentCPUs; i++ { go s.worker(ctx, i) } |
