From dc18714d83ae9866b0e2f4ea781b4567c626c7e1 Mon Sep 17 00:00:00 2001 From: Thomas Roehl Date: Mon, 21 Feb 2022 13:02:41 +0100 Subject: [PATCH] Generalize nan_to_zero option to invalid_to_zero including +Inf,+Inf and NaN --- collectors/likwidMetric.go | 12 +++++++++--- collectors/likwidMetric.md | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/collectors/likwidMetric.go b/collectors/likwidMetric.go index 14980ac..f627a24 100644 --- a/collectors/likwidMetric.go +++ b/collectors/likwidMetric.go @@ -94,7 +94,7 @@ type LikwidCollectorConfig struct { Eventsets []LikwidCollectorEventsetConfig `json:"eventsets"` Metrics []LikwidCollectorMetricConfig `json:"globalmetrics,omitempty"` ForceOverwrite bool `json:"force_overwrite,omitempty"` - NanToZero bool `json:"nan_to_zero,omitempty"` + InvalidToZero bool `json:"invalid_to_zero,omitempty"` } type LikwidCollector struct { @@ -449,7 +449,10 @@ func (m *LikwidCollector) calcEventsetMetrics(group int, interval time.Duration, continue } m.mresults[group][tid][metric.Name] = value - if m.config.NanToZero && math.IsNaN(value) { + if m.config.InvalidToZero && math.IsNaN(value) { + value = 0.0 + } + if m.config.InvalidToZero && math.IsInf(value, 0) { value = 0.0 } // Now we have the result, send it with the proper tags @@ -493,7 +496,10 @@ func (m *LikwidCollector) calcGlobalMetrics(interval time.Duration, output chan continue } m.gmresults[tid][metric.Name] = value - if m.config.NanToZero && math.IsNaN(value) { + if m.config.InvalidToZero && math.IsNaN(value) { + value = 0.0 + } + if m.config.InvalidToZero && math.IsInf(value, 0) { value = 0.0 } // Now we have the result, send it with the proper tags diff --git a/collectors/likwidMetric.md b/collectors/likwidMetric.md index 5c54bb6..8b5dee2 100644 --- a/collectors/likwidMetric.md +++ b/collectors/likwidMetric.md @@ -9,7 +9,7 @@ The `likwid` configuration consists of two parts, the "eventsets" and "globalmet Additional options: - `force_overwrite`: Same as setting `LIKWID_FORCE=1`. In case counters are already in-use, LIKWID overwrites their configuration to do its measurements -- `nan_to_zero`: In some cases, the calculations result in `NaN`. With this option, all `NaN` values are replaces with `0.0`. +- `invalid_to_zero`: In some cases, the calculations result in `NaN` or `Inf`. With this option, all `NaN` and `Inf` values are replaces with `0.0`. ### Available metric scopes