mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-11-10 04:27:25 +01:00
Properly check error codes in LikwidCollector
This commit is contained in:
parent
6e7babe084
commit
cda6ebf884
@ -72,6 +72,7 @@ func getSocketCpus() map[C.int]int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *LikwidCollector) Init() error {
|
func (m *LikwidCollector) Init() error {
|
||||||
|
var ret C.int
|
||||||
m.name = "LikwidCollector"
|
m.name = "LikwidCollector"
|
||||||
m.setup()
|
m.setup()
|
||||||
cpulist := CpuList()
|
cpulist := CpuList()
|
||||||
@ -86,41 +87,71 @@ func (m *LikwidCollector) Init() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.metrics = make(map[C.int]map[string]int)
|
m.metrics = make(map[C.int]map[string]int)
|
||||||
C.topology_init()
|
m.groups = make(map[string]C.int)
|
||||||
C.perfmon_init(C.int(len(m.cpulist)), &m.cpulist[0])
|
ret = C.topology_init()
|
||||||
|
if ret != 0 {
|
||||||
|
return errors.New("Failed to initialize LIKWID topology")
|
||||||
|
}
|
||||||
|
ret = C.perfmon_init(C.int(len(m.cpulist)), &m.cpulist[0])
|
||||||
|
if ret != 0 {
|
||||||
|
C.topology_finalize()
|
||||||
|
return errors.New("Failed to initialize LIKWID topology")
|
||||||
|
}
|
||||||
gpath := C.CString(GROUPPATH)
|
gpath := C.CString(GROUPPATH)
|
||||||
C.config_setGroupPath(gpath)
|
C.config_setGroupPath(gpath)
|
||||||
C.free(unsafe.Pointer(gpath))
|
C.free(unsafe.Pointer(gpath))
|
||||||
m.init = true
|
|
||||||
m.groups = make(map[string]C.int)
|
|
||||||
for g, metrics := range likwid_metrics {
|
for g, metrics := range likwid_metrics {
|
||||||
cstr := C.CString(g)
|
cstr := C.CString(g)
|
||||||
gid := C.perfmon_addEventSet(cstr)
|
gid := C.perfmon_addEventSet(cstr)
|
||||||
if gid >= 0 {
|
if gid >= 0 {
|
||||||
m.groups[g] = gid
|
gmetrics := 0
|
||||||
for i, metric := range metrics {
|
for i, metric := range metrics {
|
||||||
idx, err := getMetricId(gid, metric.search)
|
idx, err := getMetricId(gid, metric.search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
} else {
|
} else {
|
||||||
likwid_metrics[g][i].group_idx = idx
|
likwid_metrics[g][i].group_idx = idx
|
||||||
|
gmetrics++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if gmetrics > 0 {
|
||||||
|
m.groups[g] = gid
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Print("Failed to add events set ", g)
|
log.Print("Failed to add events set ", g)
|
||||||
}
|
}
|
||||||
C.free(unsafe.Pointer(cstr))
|
C.free(unsafe.Pointer(cstr))
|
||||||
}
|
}
|
||||||
|
if len(m.groups) == 0 {
|
||||||
|
C.perfmon_finalize()
|
||||||
|
C.topology_finalize()
|
||||||
|
return errors.New("No LIKWID performance group initialized")
|
||||||
|
}
|
||||||
|
m.init = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *LikwidCollector) Read(interval time.Duration) {
|
func (m *LikwidCollector) Read(interval time.Duration) {
|
||||||
if m.init {
|
if m.init {
|
||||||
|
var ret C.int
|
||||||
for gname, gid := range m.groups {
|
for gname, gid := range m.groups {
|
||||||
C.perfmon_setupCounters(gid)
|
ret = C.perfmon_setupCounters(gid)
|
||||||
C.perfmon_startCounters()
|
if ret != 0 {
|
||||||
|
log.Print("Failed to setup performance group ", gname)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ret = C.perfmon_startCounters()
|
||||||
|
if ret != 0 {
|
||||||
|
log.Print("Failed to start performance group ", gname)
|
||||||
|
continue
|
||||||
|
}
|
||||||
time.Sleep(interval)
|
time.Sleep(interval)
|
||||||
C.perfmon_stopCounters()
|
ret = C.perfmon_stopCounters()
|
||||||
|
if ret != 0 {
|
||||||
|
log.Print("Failed to stop performance group ", gname)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
for _, lmetric := range likwid_metrics[gname] {
|
for _, lmetric := range likwid_metrics[gname] {
|
||||||
if lmetric.socket_scope {
|
if lmetric.socket_scope {
|
||||||
@ -161,8 +192,10 @@ func (m *LikwidCollector) Read(interval time.Duration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *LikwidCollector) Close() {
|
func (m *LikwidCollector) Close() {
|
||||||
|
if m.init {
|
||||||
C.perfmon_finalize()
|
C.perfmon_finalize()
|
||||||
C.topology_finalize()
|
C.topology_finalize()
|
||||||
m.init = false
|
m.init = false
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user