2021-03-25 14:47:10 +01:00
|
|
|
package collectors
|
2021-03-25 17:47:08 +01:00
|
|
|
|
2021-03-25 14:47:10 +01:00
|
|
|
/*
|
|
|
|
#cgo CFLAGS: -I./likwid
|
|
|
|
#cgo LDFLAGS: -L./likwid -llikwid -llikwid-hwloc -lm
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <likwid.h>
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
2021-11-25 15:11:39 +01:00
|
|
|
"encoding/json"
|
2021-03-25 14:47:10 +01:00
|
|
|
"errors"
|
2021-03-25 17:47:08 +01:00
|
|
|
"fmt"
|
2021-11-25 15:11:39 +01:00
|
|
|
"io/ioutil"
|
|
|
|
"math"
|
|
|
|
"os"
|
2022-02-01 16:01:31 +01:00
|
|
|
"regexp"
|
2021-11-25 15:11:39 +01:00
|
|
|
"strconv"
|
2021-03-25 14:47:10 +01:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"unsafe"
|
2022-02-01 16:01:31 +01:00
|
|
|
|
|
|
|
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
2022-01-25 15:37:43 +01:00
|
|
|
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
2022-02-01 16:01:31 +01:00
|
|
|
topo "github.com/ClusterCockpit/cc-metric-collector/internal/ccTopology"
|
|
|
|
"github.com/PaesslerAG/gval"
|
2021-03-25 14:47:10 +01:00
|
|
|
)
|
|
|
|
|
2022-02-01 16:01:31 +01:00
|
|
|
type MetricScope string
|
2022-01-25 15:37:43 +01:00
|
|
|
|
|
|
|
const (
|
|
|
|
METRIC_SCOPE_HWTHREAD = iota
|
2022-02-01 16:01:31 +01:00
|
|
|
METRIC_SCOPE_CORE
|
|
|
|
METRIC_SCOPE_LLC
|
2022-01-25 15:37:43 +01:00
|
|
|
METRIC_SCOPE_NUMA
|
2022-02-01 16:01:31 +01:00
|
|
|
METRIC_SCOPE_DIE
|
|
|
|
METRIC_SCOPE_SOCKET
|
2022-01-25 15:37:43 +01:00
|
|
|
METRIC_SCOPE_NODE
|
|
|
|
)
|
|
|
|
|
|
|
|
func (ms MetricScope) String() string {
|
2022-02-01 16:01:31 +01:00
|
|
|
return string(ms)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms MetricScope) Granularity() int {
|
|
|
|
grans := []string{"hwthread", "core", "llc", "numadomain", "die", "socket", "node"}
|
|
|
|
for i, g := range grans {
|
|
|
|
if ms.String() == g {
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
2022-01-25 15:37:43 +01:00
|
|
|
}
|
|
|
|
|
2021-11-25 14:04:03 +01:00
|
|
|
type LikwidCollectorMetricConfig struct {
|
2022-02-01 16:01:31 +01:00
|
|
|
Name string `json:"name"` // Name of the metric
|
|
|
|
Calc string `json:"calc"` // Calculation for the metric using
|
|
|
|
Aggr string `json:"aggregation"` // if scope unequal to LIKWID metric scope, the values are combined (sum, min, max, mean or avg, median)
|
|
|
|
Scope MetricScope `json:"scope"` // scope for calculation. subscopes are aggregated using the 'aggregation' function
|
|
|
|
Publish bool `json:"publish"`
|
|
|
|
granulatity MetricScope
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type LikwidCollectorEventsetConfig struct {
|
2022-02-01 16:01:31 +01:00
|
|
|
Events map[string]string `json:"events"`
|
|
|
|
granulatity map[string]MetricScope
|
|
|
|
Metrics []LikwidCollectorMetricConfig `json:"metrics"`
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type LikwidCollectorConfig struct {
|
2021-11-25 15:11:39 +01:00
|
|
|
Eventsets []LikwidCollectorEventsetConfig `json:"eventsets"`
|
|
|
|
Metrics []LikwidCollectorMetricConfig `json:"globalmetrics"`
|
|
|
|
ExcludeMetrics []string `json:"exclude_metrics"`
|
|
|
|
ForceOverwrite bool `json:"force_overwrite"`
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
|
|
|
|
2021-03-25 14:47:10 +01:00
|
|
|
type LikwidCollector struct {
|
2022-01-25 15:37:43 +01:00
|
|
|
metricCollector
|
2021-11-25 15:11:39 +01:00
|
|
|
cpulist []C.int
|
|
|
|
sock2tid map[int]int
|
|
|
|
metrics map[C.int]map[string]int
|
|
|
|
groups []C.int
|
|
|
|
config LikwidCollectorConfig
|
|
|
|
results map[int]map[int]map[string]interface{}
|
|
|
|
mresults map[int]map[int]map[string]float64
|
2021-11-25 14:04:03 +01:00
|
|
|
gmresults map[int]map[string]float64
|
2021-11-25 15:11:39 +01:00
|
|
|
basefreq float64
|
2022-02-01 16:01:31 +01:00
|
|
|
running bool
|
2021-03-25 14:47:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type LikwidMetric struct {
|
2022-02-01 16:01:31 +01:00
|
|
|
name string
|
|
|
|
search string
|
|
|
|
scope MetricScope
|
|
|
|
group_idx int
|
2021-03-25 14:47:10 +01:00
|
|
|
}
|
|
|
|
|
2021-11-25 14:04:03 +01:00
|
|
|
func eventsToEventStr(events map[string]string) string {
|
2021-11-25 15:11:39 +01:00
|
|
|
elist := make([]string, 0)
|
|
|
|
for k, v := range events {
|
|
|
|
elist = append(elist, fmt.Sprintf("%s:%s", v, k))
|
|
|
|
}
|
|
|
|
return strings.Join(elist, ",")
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
|
|
|
|
2022-02-01 16:01:31 +01:00
|
|
|
func getGranularity(counter, event string) MetricScope {
|
|
|
|
if strings.HasPrefix(counter, "PMC") || strings.HasPrefix(counter, "FIXC") {
|
|
|
|
return "hwthread"
|
|
|
|
} else if strings.Contains(counter, "BOX") || strings.Contains(counter, "DEV") {
|
|
|
|
return "socket"
|
|
|
|
} else if strings.HasPrefix(counter, "PWR") {
|
|
|
|
if event == "RAPL_CORE_ENERGY" {
|
|
|
|
return "hwthread"
|
|
|
|
} else {
|
|
|
|
return "socket"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "unknown"
|
|
|
|
}
|
|
|
|
|
2021-11-25 14:04:03 +01:00
|
|
|
func getBaseFreq() float64 {
|
2021-11-25 15:11:39 +01:00
|
|
|
var freq float64 = math.NaN()
|
|
|
|
C.power_init(0)
|
|
|
|
info := C.get_powerInfo()
|
|
|
|
if float64(info.baseFrequency) != 0 {
|
|
|
|
freq = float64(info.baseFrequency)
|
|
|
|
} else {
|
|
|
|
buffer, err := ioutil.ReadFile("/sys/devices/system/cpu/cpu0/cpufreq/bios_limit")
|
|
|
|
if err == nil {
|
|
|
|
data := strings.Replace(string(buffer), "\n", "", -1)
|
|
|
|
x, err := strconv.ParseInt(data, 0, 64)
|
|
|
|
if err == nil {
|
|
|
|
freq = float64(x) * 1e3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return freq
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
|
|
|
|
2021-03-25 14:47:10 +01:00
|
|
|
func getSocketCpus() map[C.int]int {
|
2021-03-25 17:47:08 +01:00
|
|
|
slist := SocketList()
|
|
|
|
var cpu C.int
|
|
|
|
outmap := make(map[C.int]int)
|
|
|
|
for _, s := range slist {
|
|
|
|
t := C.CString(fmt.Sprintf("S%d", s))
|
|
|
|
clen := C.cpustr_to_cpulist(t, &cpu, 1)
|
|
|
|
if int(clen) == 1 {
|
|
|
|
outmap[cpu] = s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return outmap
|
2021-03-25 14:47:10 +01:00
|
|
|
}
|
|
|
|
|
2022-02-01 16:01:31 +01:00
|
|
|
func (m *LikwidCollector) CatchGvalPanic() {
|
|
|
|
if rerr := recover(); rerr != nil {
|
|
|
|
cclog.ComponentError(m.name, "Gval failed to calculate a metric", rerr)
|
|
|
|
m.init = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *LikwidCollector) initGranularity() {
|
|
|
|
for _, evset := range m.config.Eventsets {
|
|
|
|
evset.granulatity = make(map[string]MetricScope)
|
|
|
|
for counter, event := range evset.Events {
|
|
|
|
gran := getGranularity(counter, event)
|
|
|
|
if gran.Granularity() >= 0 {
|
|
|
|
evset.granulatity[counter] = gran
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i, metric := range evset.Metrics {
|
|
|
|
s := regexp.MustCompile("[+-/*()]").Split(metric.Calc, -1)
|
|
|
|
gran := MetricScope("hwthread")
|
|
|
|
evset.Metrics[i].granulatity = gran
|
|
|
|
for _, x := range s {
|
|
|
|
if _, ok := evset.Events[x]; ok {
|
|
|
|
if evset.granulatity[x].Granularity() > gran.Granularity() {
|
|
|
|
gran = evset.granulatity[x]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
evset.Metrics[i].granulatity = gran
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i, metric := range m.config.Metrics {
|
|
|
|
s := regexp.MustCompile("[+-/*()]").Split(metric.Calc, -1)
|
|
|
|
gran := MetricScope("hwthread")
|
|
|
|
m.config.Metrics[i].granulatity = gran
|
|
|
|
for _, x := range s {
|
|
|
|
for _, evset := range m.config.Eventsets {
|
|
|
|
for _, m := range evset.Metrics {
|
|
|
|
if m.Name == x && m.granulatity.Granularity() > gran.Granularity() {
|
|
|
|
gran = m.granulatity
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m.config.Metrics[i].granulatity = gran
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-25 15:37:43 +01:00
|
|
|
func (m *LikwidCollector) Init(config json.RawMessage) error {
|
2021-05-18 15:14:11 +02:00
|
|
|
var ret C.int
|
2021-03-25 17:47:08 +01:00
|
|
|
m.name = "LikwidCollector"
|
2021-11-25 14:04:03 +01:00
|
|
|
if len(config) > 0 {
|
2021-11-25 15:11:39 +01:00
|
|
|
err := json.Unmarshal(config, &m.config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
2022-02-01 16:01:31 +01:00
|
|
|
m.initGranularity()
|
|
|
|
if m.config.ForceOverwrite {
|
|
|
|
os.Setenv("LIKWID_FORCE", "1")
|
|
|
|
}
|
2021-03-25 14:47:10 +01:00
|
|
|
m.setup()
|
2022-02-01 16:01:31 +01:00
|
|
|
// in some cases, gval causes a panic. We catch it with the handler and deactivate
|
|
|
|
// the collector (m.init = false).
|
|
|
|
defer m.CatchGvalPanic()
|
|
|
|
|
2022-01-25 15:37:43 +01:00
|
|
|
m.meta = map[string]string{"source": m.name, "group": "PerfCounter"}
|
2022-02-01 16:01:31 +01:00
|
|
|
cpulist := topo.CpuList()
|
2021-03-25 14:47:10 +01:00
|
|
|
m.cpulist = make([]C.int, len(cpulist))
|
2021-03-25 17:47:08 +01:00
|
|
|
|
2022-02-01 16:01:31 +01:00
|
|
|
cclog.ComponentDebug(m.name, "Create maps for socket, numa, core and die metrics")
|
2021-03-25 14:47:10 +01:00
|
|
|
m.sock2tid = make(map[int]int)
|
2022-02-01 16:01:31 +01:00
|
|
|
// m.numa2tid = make(map[int]int)
|
|
|
|
// m.core2tid = make(map[int]int)
|
|
|
|
// m.die2tid = make(map[int]int)
|
2021-03-25 14:47:10 +01:00
|
|
|
for i, c := range cpulist {
|
2021-03-25 17:47:08 +01:00
|
|
|
m.cpulist[i] = C.int(c)
|
2022-02-01 16:01:31 +01:00
|
|
|
m.sock2tid[topo.GetCpuSocket(c)] = i
|
|
|
|
// m.numa2tid[topo.GetCpuNumaDomain(c)] = i
|
|
|
|
// m.core2tid[topo.GetCpuCore(c)] = i
|
|
|
|
// m.die2tid[topo.GetCpuDie(c)] = i
|
2021-03-25 14:47:10 +01:00
|
|
|
}
|
2021-11-25 14:04:03 +01:00
|
|
|
m.results = make(map[int]map[int]map[string]interface{})
|
|
|
|
m.mresults = make(map[int]map[int]map[string]float64)
|
|
|
|
m.gmresults = make(map[int]map[string]float64)
|
2021-05-18 15:14:11 +02:00
|
|
|
ret = C.topology_init()
|
|
|
|
if ret != 0 {
|
2022-02-01 16:01:31 +01:00
|
|
|
err := errors.New("failed to initialize LIKWID topology")
|
|
|
|
cclog.ComponentError(m.name, err.Error())
|
|
|
|
return err
|
2021-11-25 15:11:39 +01:00
|
|
|
}
|
2021-05-18 15:14:11 +02:00
|
|
|
ret = C.perfmon_init(C.int(len(m.cpulist)), &m.cpulist[0])
|
|
|
|
if ret != 0 {
|
|
|
|
C.topology_finalize()
|
2022-02-01 16:01:31 +01:00
|
|
|
err := errors.New("failed to initialize LIKWID topology")
|
|
|
|
cclog.ComponentError(m.name, err.Error())
|
|
|
|
return err
|
2021-05-18 15:14:11 +02:00
|
|
|
}
|
2021-11-25 15:11:39 +01:00
|
|
|
|
2022-02-01 16:01:31 +01:00
|
|
|
globalParams := make(map[string]interface{})
|
|
|
|
globalParams["time"] = float64(1.0)
|
|
|
|
globalParams["inverseClock"] = float64(1.0)
|
|
|
|
|
2021-11-25 14:04:03 +01:00
|
|
|
for i, evset := range m.config.Eventsets {
|
2021-11-25 15:11:39 +01:00
|
|
|
estr := eventsToEventStr(evset.Events)
|
2022-02-01 16:01:31 +01:00
|
|
|
params := make(map[string]interface{})
|
|
|
|
params["time"] = float64(1.0)
|
|
|
|
params["inverseClock"] = float64(1.0)
|
|
|
|
for counter, _ := range evset.Events {
|
|
|
|
params[counter] = float64(1.0)
|
|
|
|
}
|
|
|
|
for _, metric := range evset.Metrics {
|
|
|
|
_, err := gval.Evaluate(metric.Calc, params, gval.Full())
|
|
|
|
if err != nil {
|
|
|
|
cclog.ComponentError(m.name, "Calculation for metric", metric.Name, "failed:", err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if _, ok := globalParams[metric.Name]; !ok {
|
|
|
|
globalParams[metric.Name] = float64(1.0)
|
|
|
|
}
|
|
|
|
}
|
2021-11-25 15:11:39 +01:00
|
|
|
cstr := C.CString(estr)
|
|
|
|
gid := C.perfmon_addEventSet(cstr)
|
|
|
|
if gid >= 0 {
|
|
|
|
m.groups = append(m.groups, gid)
|
|
|
|
}
|
|
|
|
C.free(unsafe.Pointer(cstr))
|
|
|
|
m.results[i] = make(map[int]map[string]interface{})
|
|
|
|
m.mresults[i] = make(map[int]map[string]float64)
|
2022-01-21 15:20:53 +01:00
|
|
|
for tid := range m.cpulist {
|
2021-11-25 15:11:39 +01:00
|
|
|
m.results[i][tid] = make(map[string]interface{})
|
|
|
|
m.mresults[i][tid] = make(map[string]float64)
|
|
|
|
m.gmresults[tid] = make(map[string]float64)
|
|
|
|
}
|
2021-03-25 17:47:08 +01:00
|
|
|
}
|
2022-02-01 16:01:31 +01:00
|
|
|
for _, metric := range m.config.Metrics {
|
|
|
|
_, err := gval.Evaluate(metric.Calc, globalParams, gval.Full())
|
|
|
|
if err != nil {
|
|
|
|
cclog.ComponentError(m.name, "Calculation for metric", metric.Name, "failed:", err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
2021-11-25 14:04:03 +01:00
|
|
|
|
2021-05-18 15:14:11 +02:00
|
|
|
if len(m.groups) == 0 {
|
|
|
|
C.perfmon_finalize()
|
|
|
|
C.topology_finalize()
|
2022-02-01 16:01:31 +01:00
|
|
|
err := errors.New("no LIKWID performance group initialized")
|
|
|
|
cclog.ComponentError(m.name, err.Error())
|
|
|
|
return err
|
2021-05-18 15:14:11 +02:00
|
|
|
}
|
2021-11-25 14:04:03 +01:00
|
|
|
m.basefreq = getBaseFreq()
|
2021-05-18 15:14:11 +02:00
|
|
|
m.init = true
|
2021-05-14 19:21:16 +02:00
|
|
|
return nil
|
2021-03-25 14:47:10 +01:00
|
|
|
}
|
|
|
|
|
2022-02-01 16:01:31 +01:00
|
|
|
func (m *LikwidCollector) takeMeasurement(group int, interval time.Duration) error {
|
2021-11-25 14:04:03 +01:00
|
|
|
var ret C.int
|
2022-02-01 16:01:31 +01:00
|
|
|
gid := m.groups[group]
|
|
|
|
ret = C.perfmon_setupCounters(gid)
|
|
|
|
if ret != 0 {
|
|
|
|
gctr := C.GoString(C.perfmon_getGroupName(gid))
|
|
|
|
err := fmt.Errorf("failed to setup performance group %s", gctr)
|
|
|
|
cclog.ComponentError(m.name, err.Error())
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
ret = C.perfmon_startCounters()
|
|
|
|
if ret != 0 {
|
|
|
|
gctr := C.GoString(C.perfmon_getGroupName(gid))
|
|
|
|
err := fmt.Errorf("failed to start performance group %s", gctr)
|
|
|
|
cclog.ComponentError(m.name, err.Error())
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.running = true
|
|
|
|
time.Sleep(interval)
|
|
|
|
m.running = false
|
|
|
|
ret = C.perfmon_stopCounters()
|
|
|
|
if ret != 0 {
|
|
|
|
gctr := C.GoString(C.perfmon_getGroupName(gid))
|
|
|
|
err := fmt.Errorf("failed to stop performance group %s", gctr)
|
|
|
|
cclog.ComponentError(m.name, err.Error())
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2021-11-25 15:11:39 +01:00
|
|
|
|
2022-02-01 16:01:31 +01:00
|
|
|
func (m *LikwidCollector) calcEventsetMetrics(group int, interval time.Duration) error {
|
|
|
|
var eidx C.int
|
|
|
|
evset := m.config.Eventsets[group]
|
|
|
|
gid := m.groups[group]
|
|
|
|
for tid := range m.cpulist {
|
|
|
|
for eidx = 0; int(eidx) < len(evset.Events); eidx++ {
|
|
|
|
ctr := C.perfmon_getCounterName(gid, eidx)
|
|
|
|
gctr := C.GoString(ctr)
|
|
|
|
res := C.perfmon_getLastResult(gid, eidx, C.int(tid))
|
|
|
|
m.results[group][tid][gctr] = float64(res)
|
|
|
|
if m.results[group][tid][gctr] == 0 {
|
|
|
|
m.results[group][tid][gctr] = 1.0
|
2021-11-25 15:11:39 +01:00
|
|
|
}
|
2022-02-01 16:01:31 +01:00
|
|
|
}
|
|
|
|
m.results[group][tid]["time"] = interval.Seconds()
|
|
|
|
m.results[group][tid]["inverseClock"] = float64(1.0 / m.basefreq)
|
|
|
|
for _, metric := range evset.Metrics {
|
|
|
|
value, err := gval.Evaluate(metric.Calc, m.results[group][tid], gval.Full())
|
|
|
|
if err != nil {
|
|
|
|
cclog.ComponentError(m.name, "Calculation for metric", metric.Name, "failed:", err.Error())
|
|
|
|
continue
|
2021-11-25 15:11:39 +01:00
|
|
|
}
|
2022-02-01 16:01:31 +01:00
|
|
|
m.mresults[group][tid][metric.Name] = value.(float64)
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-01 16:01:31 +01:00
|
|
|
return nil
|
|
|
|
}
|
2021-11-25 15:11:39 +01:00
|
|
|
|
2022-02-01 16:01:31 +01:00
|
|
|
func (m *LikwidCollector) calcGlobalMetrics(interval time.Duration) error {
|
2021-11-25 14:04:03 +01:00
|
|
|
for _, metric := range m.config.Metrics {
|
2022-01-21 15:20:53 +01:00
|
|
|
for tid := range m.cpulist {
|
2022-02-01 16:01:31 +01:00
|
|
|
params := make(map[string]interface{})
|
2022-01-21 15:20:53 +01:00
|
|
|
for j := range m.groups {
|
2021-11-25 15:11:39 +01:00
|
|
|
for mname, mres := range m.mresults[j][tid] {
|
|
|
|
params[mname] = mres
|
|
|
|
}
|
|
|
|
}
|
2022-02-01 16:01:31 +01:00
|
|
|
value, err := gval.Evaluate(metric.Calc, params, gval.Full())
|
2021-11-25 15:11:39 +01:00
|
|
|
if err != nil {
|
2022-02-01 16:01:31 +01:00
|
|
|
cclog.ComponentError(m.name, "Calculation for metric", metric.Name, "failed:", err.Error())
|
2021-11-25 15:11:39 +01:00
|
|
|
continue
|
|
|
|
}
|
2022-02-01 16:01:31 +01:00
|
|
|
m.gmresults[tid][metric.Name] = value.(float64)
|
2021-11-25 15:11:39 +01:00
|
|
|
}
|
2021-11-25 14:04:03 +01:00
|
|
|
}
|
2022-02-01 16:01:31 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// func (m *LikwidCollector) calcResultMetrics(interval time.Duration) ([]lp.CCMetric, error) {
|
|
|
|
// var err error = nil
|
|
|
|
// metrics := make([]lp.CCMetric, 0)
|
|
|
|
// for i := range m.groups {
|
|
|
|
// evset := m.config.Eventsets[i]
|
|
|
|
// for _, metric := range evset.Metrics {
|
|
|
|
// log.Print(metric.Name, " ", metric.Scope, " ", metric.granulatity)
|
|
|
|
// if metric.Scope.Granularity() > metric.granulatity.Granularity() {
|
|
|
|
// log.Print("Different granularity wanted for ", metric.Name, ": ", metric.Scope, " vs ", metric.granulatity)
|
|
|
|
// var idlist []int
|
|
|
|
// idfunc := func(cpuid int) int { return cpuid }
|
|
|
|
// switch metric.Scope {
|
|
|
|
// case "socket":
|
|
|
|
// idlist = topo.SocketList()
|
|
|
|
// idfunc = topo.GetCpuSocket
|
|
|
|
// case "numa":
|
|
|
|
// idlist = topo.NumaNodeList()
|
|
|
|
// idfunc = topo.GetCpuNumaDomain
|
|
|
|
// case "core":
|
|
|
|
// idlist = topo.CoreList()
|
|
|
|
// idfunc = topo.GetCpuCore
|
|
|
|
// case "die":
|
|
|
|
// idlist = topo.DieList()
|
|
|
|
// idfunc = topo.GetCpuDie
|
|
|
|
// case "node":
|
|
|
|
// idlist = topo.CpuList()
|
|
|
|
// }
|
|
|
|
// for i := 0; i < num_results; i++ {
|
|
|
|
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// for _, metric := range m.config.Metrics {
|
|
|
|
// log.Print(metric.Name, " ", metric.Scope, " ", metric.granulatity)
|
|
|
|
// if metric.Scope.Granularity() > metric.granulatity.Granularity() {
|
|
|
|
// log.Print("Different granularity wanted for ", metric.Name, ": ", metric.Scope, " vs ", metric.granulatity)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return metrics, err
|
|
|
|
// }
|
|
|
|
|
|
|
|
func (m *LikwidCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|
|
|
if !m.init {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer m.CatchGvalPanic()
|
|
|
|
|
|
|
|
for i, _ := range m.groups {
|
|
|
|
// measure event set 'i' for 'interval' seconds
|
|
|
|
err := m.takeMeasurement(i, interval)
|
|
|
|
if err != nil {
|
|
|
|
cclog.ComponentError(m.name, err.Error())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
m.calcEventsetMetrics(i, interval)
|
|
|
|
}
|
|
|
|
|
|
|
|
m.calcGlobalMetrics(interval)
|
|
|
|
|
|
|
|
//metrics, err = m.calcResultMetrics(interval)
|
|
|
|
|
2022-01-21 15:20:53 +01:00
|
|
|
for i := range m.groups {
|
2021-11-25 15:11:39 +01:00
|
|
|
evset := m.config.Eventsets[i]
|
|
|
|
for _, metric := range evset.Metrics {
|
2022-02-01 16:01:31 +01:00
|
|
|
|
2021-11-25 15:11:39 +01:00
|
|
|
_, skip := stringArrayContains(m.config.ExcludeMetrics, metric.Name)
|
|
|
|
if metric.Publish && !skip {
|
2022-02-01 16:01:31 +01:00
|
|
|
if metric.Scope == "socket" {
|
2021-11-25 15:11:39 +01:00
|
|
|
for sid, tid := range m.sock2tid {
|
|
|
|
y, err := lp.New(metric.Name,
|
2022-01-25 15:37:43 +01:00
|
|
|
map[string]string{"type": "socket",
|
|
|
|
"type-id": fmt.Sprintf("%d", int(sid))},
|
|
|
|
m.meta,
|
2021-11-25 15:11:39 +01:00
|
|
|
map[string]interface{}{"value": m.mresults[i][tid][metric.Name]},
|
|
|
|
time.Now())
|
2021-11-25 14:04:03 +01:00
|
|
|
if err == nil {
|
2022-01-25 15:37:43 +01:00
|
|
|
output <- y
|
2021-11-25 15:11:39 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-01 16:01:31 +01:00
|
|
|
} else if metric.Scope == "hwthread" {
|
2021-11-25 15:11:39 +01:00
|
|
|
for tid, cpu := range m.cpulist {
|
|
|
|
y, err := lp.New(metric.Name,
|
2022-01-25 15:37:43 +01:00
|
|
|
map[string]string{"type": "cpu",
|
|
|
|
"type-id": fmt.Sprintf("%d", int(cpu))},
|
|
|
|
m.meta,
|
2021-11-25 15:11:39 +01:00
|
|
|
map[string]interface{}{"value": m.mresults[i][tid][metric.Name]},
|
|
|
|
time.Now())
|
|
|
|
if err == nil {
|
2022-01-25 15:37:43 +01:00
|
|
|
output <- y
|
2021-11-25 15:11:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-25 14:47:10 +01:00
|
|
|
}
|
2021-11-25 14:04:03 +01:00
|
|
|
for _, metric := range m.config.Metrics {
|
2021-11-25 15:11:39 +01:00
|
|
|
_, skip := stringArrayContains(m.config.ExcludeMetrics, metric.Name)
|
|
|
|
if metric.Publish && !skip {
|
2022-02-01 16:01:31 +01:00
|
|
|
if metric.Scope == "socket" {
|
2021-11-25 15:11:39 +01:00
|
|
|
for sid, tid := range m.sock2tid {
|
|
|
|
y, err := lp.New(metric.Name,
|
2022-01-25 15:37:43 +01:00
|
|
|
map[string]string{"type": "socket",
|
|
|
|
"type-id": fmt.Sprintf("%d", int(sid))},
|
|
|
|
m.meta,
|
2021-11-25 15:11:39 +01:00
|
|
|
map[string]interface{}{"value": m.gmresults[tid][metric.Name]},
|
|
|
|
time.Now())
|
2021-11-25 14:04:03 +01:00
|
|
|
if err == nil {
|
2022-01-25 15:37:43 +01:00
|
|
|
output <- y
|
2021-11-25 15:11:39 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-01 16:01:31 +01:00
|
|
|
} else if metric.Scope == "hwthread" {
|
2021-11-25 15:11:39 +01:00
|
|
|
for tid, cpu := range m.cpulist {
|
|
|
|
y, err := lp.New(metric.Name,
|
2022-01-25 15:37:43 +01:00
|
|
|
map[string]string{"type": "cpu",
|
|
|
|
"type-id": fmt.Sprintf("%d", int(cpu))},
|
|
|
|
m.meta,
|
2021-11-25 15:11:39 +01:00
|
|
|
map[string]interface{}{"value": m.gmresults[tid][metric.Name]},
|
|
|
|
time.Now())
|
|
|
|
if err == nil {
|
2022-01-25 15:37:43 +01:00
|
|
|
output <- y
|
2021-11-25 15:11:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-25 14:47:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *LikwidCollector) Close() {
|
2021-05-18 15:14:11 +02:00
|
|
|
if m.init {
|
2022-02-01 16:01:31 +01:00
|
|
|
cclog.ComponentDebug(m.name, "Closing ...")
|
2021-11-25 15:11:39 +01:00
|
|
|
m.init = false
|
2022-02-01 16:01:31 +01:00
|
|
|
if m.running {
|
|
|
|
cclog.ComponentDebug(m.name, "Stopping counters")
|
|
|
|
C.perfmon_stopCounters()
|
|
|
|
}
|
|
|
|
cclog.ComponentDebug(m.name, "Finalize LIKWID perfmon module")
|
2021-05-18 15:14:11 +02:00
|
|
|
C.perfmon_finalize()
|
2022-02-01 16:01:31 +01:00
|
|
|
cclog.ComponentDebug(m.name, "Finalize LIKWID topology module")
|
2021-05-18 15:14:11 +02:00
|
|
|
C.topology_finalize()
|
2022-02-01 16:01:31 +01:00
|
|
|
cclog.ComponentDebug(m.name, "Closing done")
|
2021-05-18 15:14:11 +02:00
|
|
|
}
|
2021-03-25 14:47:10 +01:00
|
|
|
}
|