Skip to content

Commit

Permalink
[fix] fix the condition (#197)
Browse files Browse the repository at this point in the history
A minor fix. Build query if performance counters are enabled.
  • Loading branch information
VihasMakwana authored Dec 10, 2024
1 parent 80aacba commit b0ba118
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion metric/cpu/cpu_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func New(hostfs resolve.Resolver, opts ...OptionFunc) (*Monitor, error) {
for _, o := range opts {
o(&op)
}
if !op.usePerformanceCounter {
if op.usePerformanceCounter {
if query, err = buildQuery(); err != nil {
return nil, err
}
Expand Down
8 changes: 7 additions & 1 deletion metric/cpu/metric_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func TestCounterLength(t *testing.T) {
monitor, err := New(systemtests.DockerTestResolver())
monitor, err := New(systemtests.DockerTestResolver(), WithWindowsPerformanceCounter())
require.NoError(t, err)
require.NoError(t, monitor.query.CollectData())

Expand All @@ -52,3 +52,9 @@ func TestCounterLength(t *testing.T) {
require.Equal(t, kernelRawData[i].InstanceName, idleRawData[i].InstanceName, "InstanceName should be equal")
}
}

func TestCounterDisabled(t *testing.T) {
monitor, err := New(systemtests.DockerTestResolver())
require.NoError(t, err)
require.Nil(t, monitor.query)
}

0 comments on commit b0ba118

Please sign in to comment.