in util-images/network/netperfbenchmark/pkg/worker/util.go [80:123]
func parseIperfResponse(result []string, testDuration string, metricCount int, protocol string, operators []string) ([]float64, error) {
aggregatedResult := make([]float64, 0, metricCount)
count := 0
sessionID := make(map[string]bool)
for _, line := range result {
klog.V(4).Info(line)
split := parseIperfLine(line)
// iperf gives aggregated result in a row with "SUM", but many fields are not
// getting aggregated hence not depending on iperf's aggregation.
if len(split) < metricCount+1 || "SUM" == split[1] || !intervalRegex.MatchString(split[2]) {
continue
}
// iperf sometimes prints duplicate rows for same session id(for same duration), making sure
// the row is taken for calculation only once.
if _, isDuplicate := sessionID[split[1]]; isDuplicate {
continue
}
sessionID[split[1]] = true
// The first three and the last items are not metrics in iperf summary.
for i := 3; i < len(split)-1; i++ {
tmp, err := strconv.ParseFloat(split[i], 64)
if err != nil {
klog.Errorf("Error converting %v to float: %v", split[i], err)
return nil, err
}
if len(aggregatedResult) < metricCount {
aggregatedResult = append(aggregatedResult, tmp)
} else {
switch operators[i] {
case "Sum":
aggregatedResult[i-3] = tmp + aggregatedResult[i-3]
case "Avg":
aggregatedResult[i-3] = (float64(count)*tmp + aggregatedResult[i-3]) / (float64(1 + count))
case "Min":
aggregatedResult[i-3] = math.Min(tmp, aggregatedResult[i-3])
case "Max":
aggregatedResult[i-3] = math.Max(tmp, aggregatedResult[i-3])
}
}
count++
}
}
return aggregatedResult, nil
}