Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rbarazzutti committed Dec 23, 2021
1 parent 7a3fd9a commit 688c2a5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 44 deletions.
92 changes: 50 additions & 42 deletions app/httpping.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func HTTPPing(config *Config, stdout io.Writer) {
} else {
if !measure.IsFailure {
if config.LogLevel >= 1 {
_, _ = fmt.Fprintf(stdout, "%8d: %s, code=%d, size=%d bytes, time=%.1f ms\n", attempts, measure.RemoteAddr, measure.StatusCode, measure.Bytes, measure.Measure.ToFloat(time.Millisecond))
_, _ = fmt.Fprintf(stdout, "%8d: %s, code=%d, size=%d bytes, time=%.1f ms\n", attempts, measure.RemoteAddr, measure.StatusCode, measure.Bytes, measure.Total.ToFloat(time.Millisecond))
}
if config.LogLevel == 2 {
_, _ = fmt.Fprintf(stdout, " proto=%s, socket reused=%t, compressed=%t\n", measure.Proto, measure.SocketReused, measure.Compressed)
Expand All @@ -71,51 +71,14 @@ func HTTPPing(config *Config, stdout io.Writer) {

_, _ = fmt.Fprintf(stdout, "\n")

z := measureEntry{
label: "request and response",
duration: measure.Measure,
children: []*measureEntry{
{label: "connection setup", duration: measure.ConnDuration,
children: []*measureEntry{
{label: "DNS resolution", duration: measure.DNSDuration},
{label: "TCP handshake", duration: measure.TCPHandshake},
{label: "TLS handshake", duration: measure.TLSDuration},
}},
{label: "request sending", duration: measure.ReqDuration},
{label: "wait", duration: measure.Wait},
{label: "response ingestion", duration: measure.RespDuration},
},
}

if !measure.TLSEnabled {
z.children[0].children = z.children[0].children[0:2]
}

l := makeTreeList(&z)
l := measureToMeasureEntryVisits(measure)

_, _ = fmt.Fprintf(stdout, " latency contributions:\n")
for i, e := range l {
pipes := make([]string, e.depth)
for j := 0; j < e.depth; j++ {
if i+1 >= len(l) || l[i+1].depth-1 < j {
pipes[j] = " └─"
} else if j == e.depth-1 {
pipes[j] = " ├─"
} else {
pipes[j] = " │ "
}

}
_, _ = fmt.Fprintf(stdout, " ")
for i := 0; i < e.depth; i++ {
_, _ = fmt.Fprintf(stdout, " %s ", pipes[i])
}

_, _ = fmt.Fprintf(stdout, "%6.1f ms %s\n", e.measureEntry.duration.ToFloat(time.Millisecond), e.measureEntry.label)
}

drawEntryVisits(l, stdout)
_, _ = fmt.Fprintf(stdout, "\n")
}
latencies = append(latencies, measure.Measure)
latencies = append(latencies, measure.Total)

if config.AudibleBell {
_, _ = fmt.Fprintf(stdout, "\a")
Expand Down Expand Up @@ -150,6 +113,51 @@ func HTTPPing(config *Config, stdout io.Writer) {

}

func measureToMeasureEntryVisits(measure *HTTPMeasure) []measureEntryVisit {
entries := measureEntry{
label: "request and response",
duration: measure.Total,
children: []*measureEntry{
{label: "connection setup", duration: measure.ConnDuration,
children: []*measureEntry{
{label: "DNS resolution", duration: measure.DNSDuration},
{label: "TCP handshake", duration: measure.TCPHandshake},
{label: "TLS handshake", duration: measure.TLSDuration},
}},
{label: "request sending", duration: measure.ReqDuration},
{label: "wait", duration: measure.Wait},
{label: "response ingestion", duration: measure.RespDuration},
},
}
if !measure.TLSEnabled {
entries.children[0].children = entries.children[0].children[0:2]
}

return makeTreeList(&entries)
}

func drawEntryVisits(l []measureEntryVisit, stdout io.Writer) {
for i, e := range l {
pipes := make([]string, e.depth)
for j := 0; j < e.depth; j++ {
if i+1 >= len(l) || l[i+1].depth-1 < j {
pipes[j] = " └─"
} else if j == e.depth-1 {
pipes[j] = " ├─"
} else {
pipes[j] = " │ "
}

}
_, _ = fmt.Fprintf(stdout, " ")
for i := 0; i < e.depth; i++ {
_, _ = fmt.Fprintf(stdout, " %s ", pipes[i])
}

_, _ = fmt.Fprintf(stdout, "%6.1f ms %s\n", e.measureEntry.duration.ToFloat(time.Millisecond), e.measureEntry.label)
}
}

type measureEntry struct {
label string
duration stats.Measure
Expand Down
2 changes: 1 addition & 1 deletion app/pinger.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// HTTPMeasure is the out of a measurement done as an HTTP ping
type HTTPMeasure struct {
Proto string
Measure stats.Measure
Total stats.Measure
StatusCode int
Bytes int64
InBytes int64
Expand Down
2 changes: 1 addition & 1 deletion app/webclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (webClient *WebClient) DoMeasure(followRedirect bool) *HTTPMeasure {

return &HTTPMeasure{
Proto: res.Proto,
Measure: stats.Measure(d),
Total: stats.Measure(d),
StatusCode: res.StatusCode,
Bytes: s,
InBytes: i,
Expand Down

0 comments on commit 688c2a5

Please sign in to comment.