Generalize nan_to_zero option to invalid_to_zero including +Inf,+Inf and NaN

This commit is contained in:
Thomas Roehl 2022-02-21 13:02:41 +01:00
parent e991c4c3b2
commit dc18714d83
2 changed files with 10 additions and 4 deletions

View File

@ -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

View File

@ -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