-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add function for merging benchmark result stats
- Loading branch information
Ondřej Benkovský
committed
Apr 24, 2024
1 parent
54377ca
commit 74d90c0
Showing
4 changed files
with
147 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package reporter | ||
|
||
import ( | ||
"errors" | ||
"github.com/HdrHistogram/hdrhistogram-go" | ||
"github.com/tantalor93/dnspyre/v3/pkg/dnsbench" | ||
"net" | ||
"sort" | ||
) | ||
|
||
type BenchmarkResultStats struct { | ||
Codes map[int]int64 | ||
Qtypes map[string]int64 | ||
Hist *hdrhistogram.Histogram | ||
Timings []dnsbench.Datapoint | ||
Counters dnsbench.Counters | ||
Errors []dnsbench.ErrorDatapoint | ||
GroupedErrors map[string]int | ||
AuthenticatedDomains map[string]struct{} | ||
DoHStatusCodes map[int]int64 | ||
} | ||
|
||
func Merge(b *dnsbench.Benchmark, stats []*dnsbench.ResultStats) BenchmarkResultStats { | ||
totals := BenchmarkResultStats{ | ||
Codes: make(map[int]int64), | ||
Qtypes: make(map[string]int64), | ||
Hist: hdrhistogram.New(b.HistMin.Nanoseconds(), b.HistMax.Nanoseconds(), b.HistPre), | ||
GroupedErrors: make(map[string]int), | ||
AuthenticatedDomains: make(map[string]struct{}), | ||
DoHStatusCodes: make(map[int]int64), | ||
} | ||
|
||
for _, s := range stats { | ||
for _, err := range s.Errors { | ||
errorString := errString(err) | ||
|
||
if v, ok := totals.GroupedErrors[errorString]; ok { | ||
totals.GroupedErrors[errorString] = v + 1 | ||
} else { | ||
totals.GroupedErrors[errorString] = 1 | ||
} | ||
} | ||
totals.Errors = append(totals.Errors, s.Errors...) | ||
|
||
totals.Hist.Merge(s.Hist) | ||
totals.Timings = append(totals.Timings, s.Timings...) | ||
if s.Codes != nil { | ||
for k, v := range s.Codes { | ||
totals.Codes[k] += v | ||
} | ||
} | ||
if s.Qtypes != nil { | ||
for k, v := range s.Qtypes { | ||
totals.Qtypes[k] += v | ||
} | ||
} | ||
if s.DoHStatusCodes != nil { | ||
for k, v := range s.DoHStatusCodes { | ||
totals.DoHStatusCodes[k] += v | ||
} | ||
} | ||
if s.Counters != nil { | ||
totals.Counters = dnsbench.Counters{ | ||
Total: totals.Counters.Total + s.Counters.Total, | ||
IOError: totals.Counters.IOError + s.Counters.IOError, | ||
Success: totals.Counters.Success + s.Counters.Success, | ||
Negative: totals.Counters.Negative + s.Counters.Negative, | ||
Error: totals.Counters.Error + s.Counters.Error, | ||
IDmismatch: totals.Counters.IDmismatch + s.Counters.IDmismatch, | ||
Truncated: totals.Counters.Truncated + s.Counters.Truncated, | ||
} | ||
} | ||
if b.DNSSEC { | ||
for k := range s.AuthenticatedDomains { | ||
totals.AuthenticatedDomains[k] = struct{}{} | ||
} | ||
} | ||
} | ||
|
||
// sort data points from the oldest to the earliest, so we can better plot time dependant graphs (like line) | ||
sort.SliceStable(totals.Timings, func(i, j int) bool { | ||
return totals.Timings[i].Start.Before(totals.Timings[j].Start) | ||
}) | ||
|
||
// sort error data points from the oldest to the earliest, so we can better plot time dependant graphs (like line) | ||
sort.SliceStable(totals.Errors, func(i, j int) bool { | ||
return totals.Errors[i].Start.Before(totals.Errors[j].Start) | ||
}) | ||
return totals | ||
} | ||
|
||
func errString(err dnsbench.ErrorDatapoint) string { | ||
var errorString string | ||
var netOpErr *net.OpError | ||
var resolveErr *net.DNSError | ||
|
||
switch { | ||
case errors.As(err.Err, &resolveErr): | ||
errorString = resolveErr.Err + " " + resolveErr.Name | ||
case errors.As(err.Err, &netOpErr): | ||
errorString = netOpErr.Op + " " + netOpErr.Net | ||
if netOpErr.Addr != nil { | ||
errorString += " " + netOpErr.Addr.String() | ||
} | ||
default: | ||
errorString = err.Err.Error() | ||
} | ||
return errorString | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters