Commit 50926d11 authored by Angela Li's avatar Angela Li

address comments

parent abc50fb7
...@@ -207,7 +207,8 @@ func (p *perfCounterNodeStatsClient) convertCPUValue(cpuCores int, cpuValue uint ...@@ -207,7 +207,8 @@ func (p *perfCounterNodeStatsClient) convertCPUValue(cpuCores int, cpuValue uint
} }
func (p *perfCounterNodeStatsClient) getCPUUsageNanoCores() uint64 { func (p *perfCounterNodeStatsClient) getCPUUsageNanoCores() uint64 {
cpuUsageNanoCores := (p.cpuUsageCoreNanoSecondsCache.latestValue - p.cpuUsageCoreNanoSecondsCache.previousValue) * uint64(time.Second/time.Nanosecond) / uint64(defaultCachePeriod) cachePeriodSeconds := uint64(defaultCachePeriod / time.Second)
cpuUsageNanoCores := (p.cpuUsageCoreNanoSecondsCache.latestValue - p.cpuUsageCoreNanoSecondsCache.previousValue) / cachePeriodSeconds
return cpuUsageNanoCores return cpuUsageNanoCores
} }
......
...@@ -149,13 +149,25 @@ func TestConvertCPUValue(t *testing.T) { ...@@ -149,13 +149,25 @@ func TestConvertCPUValue(t *testing.T) {
} }
func TestGetCPUUsageNanoCores(t *testing.T) { func TestGetCPUUsageNanoCores(t *testing.T) {
p := perfCounterNodeStatsClient{} testCases := []struct {
p.cpuUsageCoreNanoSecondsCache = cpuUsageCoreNanoSecondsCache{ latestValue uint64
latestValue: uint64(5000000000), previousValue uint64
previousValue: uint64(2000000000), 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)},
}
for _, tc := range testCases {
p := perfCounterNodeStatsClient{}
p.cpuUsageCoreNanoSecondsCache = cpuUsageCoreNanoSecondsCache{
latestValue: tc.latestValue,
previousValue: tc.previousValue,
}
cpuUsageNanoCores := p.getCPUUsageNanoCores()
assert.Equal(t, cpuUsageNanoCores, tc.expected)
} }
cpuUsageNanoCores := p.getCPUUsageNanoCores()
assert.Equal(t, cpuUsageNanoCores, uint64(300000000))
} }
func getClient(t *testing.T) Client { func getClient(t *testing.T) Client {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment