summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/intelgpu/charts.go
blob: 93670633c6653e5632f255525d35d673c927a377 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// SPDX-License-Identifier: GPL-3.0-or-later

package intelgpu

import (
	"fmt"
	"strings"

	"github.com/netdata/netdata/go/go.d.plugin/agent/module"
)

const (
	prioGPUFrequency = module.Priority + iota
	prioGPUPower
	prioGPUEngineBusy
)

var charts = module.Charts{
	intelGPUFrequencyChart.Copy(),
	intelGPUPowerGPUChart.Copy(),
}

var intelGPUFrequencyChart = module.Chart{
	ID:       "igpu_frequency",
	Title:    "Intel GPU frequency",
	Units:    "MHz",
	Fam:      "frequency",
	Ctx:      "intelgpu.frequency",
	Type:     module.Line,
	Priority: prioGPUFrequency,
	Dims: module.Dims{
		{ID: "frequency_actual", Name: "frequency", Div: precision},
	},
}

var intelGPUPowerGPUChart = module.Chart{
	ID:       "igpu_power_gpu",
	Title:    "Intel GPU power",
	Units:    "Watts",
	Fam:      "power",
	Ctx:      "intelgpu.power",
	Type:     module.Line,
	Priority: prioGPUPower,
	Dims: module.Dims{
		{ID: "power_gpu", Name: "gpu", Div: precision},
		{ID: "power_package", Name: "package", Div: precision},
	},
}

var intelGPUEngineBusyPercChartTmpl = module.Chart{
	ID:       "igpu_engine_%s_busy_percentage",
	Title:    "Intel GPU engine busy time percentage",
	Units:    "percentage",
	Fam:      "engines",
	Ctx:      "intelgpu.engine_busy_perc",
	Type:     module.Line,
	Priority: prioGPUEngineBusy,
	Dims: module.Dims{
		{ID: "engine_%s_busy", Name: "busy", Div: precision},
	},
}

func (ig *IntelGPU) addEngineCharts(engine string) {
	chart := intelGPUEngineBusyPercChartTmpl.Copy()

	s := strings.ToLower(engine)
	s = strings.ReplaceAll(s, "/", "_")

	chart.ID = fmt.Sprintf(chart.ID, s)
	chart.Labels = []module.Label{
		{Key: "engine_class", Value: engineClassName(engine)},
		{Key: "engine_instance", Value: engine},
	}
	for _, dim := range chart.Dims {
		dim.ID = fmt.Sprintf(dim.ID, engine)
	}

	if err := ig.Charts().Add(chart); err != nil {
		ig.Warning(err)
	}
}

func engineClassName(engine string) string {
	// https://gitlab.freedesktop.org/drm/igt-gpu-tools/-/blob/master/tools/intel_gpu_top.c#L431
	engines := []string{"Render/3D", "Blitter", "VideoEnhance", "Video", "Compute"}
	for _, name := range engines {
		if strings.HasPrefix(engine, name) {
			return name
		}
	}
	return "unknown"
}