mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-22 03:26:39 +00:00
Compare commits
No commits in common. "b9dd14a588e70d0c910310ebd6b1c0337de3d9f8" and "77ddcf722a67356bcc61aaa721668e1bede79205" have entirely different histories.
b9dd14a588
...
77ddcf722a
@ -209,8 +209,8 @@ func (config *JSONConfig) MergeConfigs(newConfig *JSONConfig) {
|
|||||||
|
|
||||||
type CLIConfig struct {
|
type CLIConfig struct {
|
||||||
*Config
|
*Config
|
||||||
Yes Option[bool] `json:"yes" validate:"omitempty"`
|
Yes Option[bool] `json:"yes" validate:"omitempty"`
|
||||||
ConfigFile string `validation_name:"config-file" validate:"omitempty,filepath"`
|
ConfigFile string `validation_name:"config-file" validate:"omitempty,filepath"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCLIConfig(
|
func NewCLIConfig(
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/aykhans/dodo/types"
|
. "github.com/aykhans/dodo/types"
|
||||||
"github.com/aykhans/dodo/utils"
|
|
||||||
"github.com/jedib0t/go-pretty/v6/table"
|
"github.com/jedib0t/go-pretty/v6/table"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,7 +17,7 @@ type Responses []*Response
|
|||||||
|
|
||||||
// Print prints the responses in a tabular format, including information such as
|
// Print prints the responses in a tabular format, including information such as
|
||||||
// response count, minimum time, maximum time, average time, and latency percentiles.
|
// response count, minimum time, maximum time, average time, and latency percentiles.
|
||||||
func (responses Responses) Print() {
|
func (respones Responses) Print() {
|
||||||
total := struct {
|
total := struct {
|
||||||
Count int
|
Count int
|
||||||
Min time.Duration
|
Min time.Duration
|
||||||
@ -28,14 +27,14 @@ func (responses Responses) Print() {
|
|||||||
P95 time.Duration
|
P95 time.Duration
|
||||||
P99 time.Duration
|
P99 time.Duration
|
||||||
}{
|
}{
|
||||||
Count: len(responses),
|
Count: len(respones),
|
||||||
Min: responses[0].Time,
|
Min: respones[0].Time,
|
||||||
Max: responses[0].Time,
|
Max: respones[0].Time,
|
||||||
}
|
}
|
||||||
mergedResponses := make(map[string]Durations)
|
mergedResponses := make(map[string]Durations)
|
||||||
var allDurations Durations
|
var allDurations Durations
|
||||||
|
|
||||||
for _, response := range responses {
|
for _, response := range respones {
|
||||||
if response.Time < total.Min {
|
if response.Time < total.Min {
|
||||||
total.Min = response.Time
|
total.Min = response.Time
|
||||||
}
|
}
|
||||||
@ -65,15 +64,14 @@ func (responses Responses) Print() {
|
|||||||
t.AppendHeader(table.Row{
|
t.AppendHeader(table.Row{
|
||||||
"Response",
|
"Response",
|
||||||
"Count",
|
"Count",
|
||||||
"Min",
|
"Min Time",
|
||||||
"Max",
|
"Max Time",
|
||||||
"Average",
|
"Average Time",
|
||||||
"P90",
|
"P90",
|
||||||
"P95",
|
"P95",
|
||||||
"P99",
|
"P99",
|
||||||
})
|
})
|
||||||
|
|
||||||
var roundPrecision int64 = 4
|
|
||||||
for key, durations := range mergedResponses {
|
for key, durations := range mergedResponses {
|
||||||
durations.Sort()
|
durations.Sort()
|
||||||
durationsLen := len(durations)
|
durationsLen := len(durations)
|
||||||
@ -82,12 +80,12 @@ func (responses Responses) Print() {
|
|||||||
t.AppendRow(table.Row{
|
t.AppendRow(table.Row{
|
||||||
key,
|
key,
|
||||||
durationsLen,
|
durationsLen,
|
||||||
utils.DurationRoundBy(*durations.First(), roundPrecision),
|
durations.First(),
|
||||||
utils.DurationRoundBy(*durations.Last(), roundPrecision),
|
durations.Last(),
|
||||||
utils.DurationRoundBy(durations.Avg(), roundPrecision),
|
durations.Avg(),
|
||||||
utils.DurationRoundBy(durations[int(0.90*durationsLenAsFloat)], roundPrecision),
|
durations[int(0.90*durationsLenAsFloat)],
|
||||||
utils.DurationRoundBy(durations[int(0.95*durationsLenAsFloat)], roundPrecision),
|
durations[int(0.95*durationsLenAsFloat)],
|
||||||
utils.DurationRoundBy(durations[int(0.99*durationsLenAsFloat)], roundPrecision),
|
durations[int(0.99*durationsLenAsFloat)],
|
||||||
})
|
})
|
||||||
t.AppendSeparator()
|
t.AppendSeparator()
|
||||||
}
|
}
|
||||||
@ -96,12 +94,12 @@ func (responses Responses) Print() {
|
|||||||
t.AppendRow(table.Row{
|
t.AppendRow(table.Row{
|
||||||
"Total",
|
"Total",
|
||||||
total.Count,
|
total.Count,
|
||||||
utils.DurationRoundBy(total.Min, roundPrecision),
|
total.Min,
|
||||||
utils.DurationRoundBy(total.Max, roundPrecision),
|
total.Max,
|
||||||
utils.DurationRoundBy(total.Sum/time.Duration(total.Count), roundPrecision), // Average
|
total.Sum / time.Duration(total.Count), // Average
|
||||||
utils.DurationRoundBy(total.P90, roundPrecision),
|
total.P90,
|
||||||
utils.DurationRoundBy(total.P95, roundPrecision),
|
total.P95,
|
||||||
utils.DurationRoundBy(total.P99, roundPrecision),
|
total.P99,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
t.Render()
|
t.Render()
|
||||||
|
21
utils/int.go
21
utils/int.go
@ -1,21 +0,0 @@
|
|||||||
package utils
|
|
||||||
|
|
||||||
type Number interface {
|
|
||||||
int | int8 | int16 | int32 | int64
|
|
||||||
}
|
|
||||||
|
|
||||||
func NumLen[T Number](n T) T {
|
|
||||||
if n < 0 {
|
|
||||||
n = -n
|
|
||||||
}
|
|
||||||
if n == 0 {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
var count T = 0
|
|
||||||
for n > 0 {
|
|
||||||
n /= 10
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
return count
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package utils
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
func DurationRoundBy(duration time.Duration, n int64) time.Duration {
|
|
||||||
if durationLen := NumLen(duration.Nanoseconds()); durationLen > n {
|
|
||||||
roundNum := 1
|
|
||||||
for range durationLen - n {
|
|
||||||
roundNum *= 10
|
|
||||||
}
|
|
||||||
return duration.Round(time.Duration(roundNum))
|
|
||||||
}
|
|
||||||
return duration
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user