@cryptotaxi247 / netdata-1 / commits / 10685dff6

go.d fix intelgpu with update_every > 3 (#17491)

Ilya Mashchenko committed Apr 23, 2024 at 12:08 UTC 10685dff6680961c712ee2b6daaff0ebe3956351
1 file changed +23 -13
src/go/collectors/go.d.plugin/modules/intelgpu/exec.go
+23 -13
@@ -16,9 +16,10 @@ import (
16
17 func newIntelGpuTopExec(ndsudoPath string, updateEvery int, log *logger.Logger) (*intelGpuTopExec, error) {
18 topExec := &intelGpuTopExec{
19 - Logger: log,
20 - ndsudoPath: ndsudoPath,
21 - updateEvery: updateEvery,
19 + Logger: log,
20 + ndsudoPath: ndsudoPath,
21 + updateEvery: updateEvery,
22 + firstSampleTimeout: time.Second * 3,
23 }
24
25 if err := topExec.run(); err != nil {
@@ -31,8 +32,9 @@ func newIntelGpuTopExec(ndsudoPath string, updateEvery int, log *logger.Logger)
32 type intelGpuTopExec struct {
33 *logger.Logger
34
34 - ndsudoPath string
35 - updateEvery int
35 + ndsudoPath string
36 + updateEvery int
37 + firstSampleTimeout time.Duration
38
39 cmd *exec.Cmd
40 done chan struct{}
@@ -42,12 +44,7 @@ type intelGpuTopExec struct {
44 }
45
46 func (e *intelGpuTopExec) run() error {
45 - refresh := 900
46 - if e.updateEvery > 1 {
47 - refresh = e.updateEvery*1000 - 500 // milliseconds
48 - }
49 -
50 - cmd := exec.Command(e.ndsudoPath, "igt-json", "--interval", strconv.Itoa(refresh))
47 + cmd := exec.Command(e.ndsudoPath, "igt-json", "--interval", e.calcIntervalArg())
48
49 e.Debugf("executing '%s'", cmd)
50
@@ -78,7 +75,7 @@ func (e *intelGpuTopExec) run() error {
75
76 text := sc.Text()
77
81 - if buf.Cap() == 0 && text != "{" || text == "" {
78 + if buf.Len() == 0 && text != "{" || text == "" {
79 continue
80 }
81
@@ -108,7 +105,7 @@ func (e *intelGpuTopExec) run() error {
105 case <-e.done:
106 _ = e.stop()
107 return errors.New("process exited before the first sample was collected")
111 - case <-time.After(time.Second * 3):
108 + case <-time.After(e.firstSampleTimeout):
109 _ = e.stop()
110 return errors.New("timed out waiting for first sample")
111 case <-firstSample:
@@ -145,3 +142,16 @@ func (e *intelGpuTopExec) stop() error {
142 return errors.New("timed out waiting for process to exit")
143 }
144 }
145 +
146 +func (e *intelGpuTopExec) calcIntervalArg() string {
147 + // intel_gpu_top appends the end marker ("},\n") of the previous sample to the beginning of the next sample.
148 + // interval must be < than 'firstSampleTimeout'
149 + var interval int
150 + m := min(e.updateEvery, int(e.firstSampleTimeout.Seconds()))
151 + if m <= 1 {
152 + interval = 900
153 + } else {
154 + interval = m*1000 - 500 // milliseconds
155 + }
156 + return strconv.Itoa(interval)
157 +}