mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 13:31:52 +00:00
Merge pull request #122999 from marosset/fix-windows-stats-cpu-nano-seconds-usage
fixing issue with GetCPUUsageNanoCores on Windows
This commit is contained in:
commit
980033ee81
@ -250,7 +250,8 @@ func (p *perfCounterNodeStatsClient) convertCPUValue(cpuCores int, cpuValue uint
|
||||
|
||||
func (p *perfCounterNodeStatsClient) getCPUUsageNanoCores() uint64 {
|
||||
cachePeriodSeconds := uint64(defaultCachePeriod / time.Second)
|
||||
cpuUsageNanoCores := (p.cpuUsageCoreNanoSecondsCache.latestValue - p.cpuUsageCoreNanoSecondsCache.previousValue) / cachePeriodSeconds
|
||||
perfCounterUpdatePeriodSeconds := uint64(perfCounterUpdatePeriod / time.Second)
|
||||
cpuUsageNanoCores := ((p.cpuUsageCoreNanoSecondsCache.latestValue - p.cpuUsageCoreNanoSecondsCache.previousValue) * perfCounterUpdatePeriodSeconds) / cachePeriodSeconds
|
||||
return cpuUsageNanoCores
|
||||
}
|
||||
|
||||
|
@ -160,14 +160,16 @@ func TestConvertCPUValue(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetCPUUsageNanoCores(t *testing.T) {
|
||||
// Scaled expected unit test values by the frequency the CPU perf counters are polled.
|
||||
perfCounterUpdatePeriodSeconds := uint64(perfCounterUpdatePeriod / time.Second)
|
||||
testCases := []struct {
|
||||
latestValue uint64
|
||||
previousValue uint64
|
||||
expected uint64
|
||||
}{
|
||||
{latestValue: uint64(0), previousValue: uint64(0), expected: uint64(0)},
|
||||
{latestValue: uint64(2000000000), previousValue: uint64(0), expected: uint64(200000000)},
|
||||
{latestValue: uint64(5000000000), previousValue: uint64(2000000000), expected: uint64(300000000)},
|
||||
{latestValue: uint64(2000000000), previousValue: uint64(0), expected: uint64(200000000 * perfCounterUpdatePeriodSeconds)},
|
||||
{latestValue: uint64(5000000000), previousValue: uint64(2000000000), expected: uint64(300000000 * perfCounterUpdatePeriodSeconds)},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
Loading…
Reference in New Issue
Block a user