blob: 138cf8cd5dcbfcedca774b1908c1ed0a0bfebba9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
// Package cpu provides CPU stress testing with multiple algorithms and chaos modes.
package cpu
import "time"
// helpers.go provides utility functions for randomization and timing.
func (s *Stresser) randomIntensity() int {
s.mu.Lock()
defer s.mu.Unlock()
return s.rand.Intn(s.config.IntensityMax-s.config.IntensityMin+1) + s.config.IntensityMin
}
func (s *Stresser) determineCPUCount() int {
if s.config.ChaosEnabled {
return s.rand.Intn(s.config.MaxCPUs-s.config.MinCPUs+1) + s.config.MinCPUs
}
if s.config.Workers > 0 {
return s.config.Workers
}
return s.config.MaxCPUs
}
func (s *Stresser) getRandomMode() Mode {
return allModes[s.rand.Intn(len(allModes))]
}
func (s *Stresser) sleepWithJitter(minMs, maxMs int) {
ms := s.rand.Intn(maxMs-minMs+1) + minMs
time.Sleep(time.Duration(ms) * time.Millisecond)
}
|