-
Notifications
You must be signed in to change notification settings - Fork 393
/
clientui.go
204 lines (181 loc) · 6.47 KB
/
clientui.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//-----------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license.
// See LICENSE.txt file in the project root for full license information.
//-----------------------------------------------------------------------------
package main
import (
"fmt"
"sync/atomic"
"time"
)
type clientUI struct {
title string
}
func (u *clientUI) fini() {
}
func (u *clientUI) getTitle() string {
return u.title
}
func (u *clientUI) printMsg(format string, a ...interface{}) {
s := fmt.Sprintf(format, a...)
logInfo(s)
fmt.Println(s)
}
func (u *clientUI) printErr(format string, a ...interface{}) {
s := fmt.Sprintf(format, a...)
logError(s)
fmt.Println(s)
}
func (u *clientUI) printDbg(format string, a ...interface{}) {
if loggingLevel == LogLevelDebug {
s := fmt.Sprintf(format, a...)
logDebug(s)
fmt.Println(s)
}
}
func (u *clientUI) paint(seconds uint64) {
}
func (u *clientUI) emitTestResultBegin() {
}
func (u *clientUI) emitTestHdr() {
s := []string{"ServerAddress", "Proto", "Bits/s", "Conn/s", "Pkt/s"}
fmt.Println("-----------------------------------------------------------")
fmt.Printf("%-15s %-5s %7s %7s %7s\n", s[0], s[1], s[2], s[3], s[4])
}
func (u *clientUI) emitLatencyHdr() {
s := []string{"Avg", "Min", "50%", "90%", "95%", "99%", "99.9%", "99.99%", "Max"}
fmt.Println("-----------------------------------------------------------------------------------------")
fmt.Printf("%9s %9s %9s %9s %9s %9s %9s %9s %9s\n", s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8])
}
func (u *clientUI) emitLatencyResults(remote, proto string, avg, min, max, p50, p90, p95, p99, p999, p9999 time.Duration) {
logLatency(remote, proto, avg, min, max, p50, p90, p95, p99, p999, p9999)
fmt.Printf("%9s %9s %9s %9s %9s %9s %9s %9s %9s\n",
durationToString(avg), durationToString(min),
durationToString(p50), durationToString(p90),
durationToString(p95), durationToString(p99),
durationToString(p999), durationToString(p9999),
durationToString(max))
}
func (u *clientUI) emitTestResultEnd() {
}
func (u *clientUI) emitStats(netStats ethrNetStat) {
}
func (u *clientUI) printTestResults(s []string) {
}
func initClientUI(title string) {
cli := &clientUI{title}
ui = cli
}
var gInterval uint64
var gNoConnectionStats bool
func printBwTestDivider(p EthrProtocol) {
if p == TCP {
ui.printMsg("- - - - - - - - - - - - - - - - - - - - - - -")
} else if p == UDP {
ui.printMsg("- - - - - - - - - - - - - - - - - - - - - - - - - - - -")
}
}
func printBwTestHeader(p EthrProtocol) {
if p == TCP {
ui.printMsg("[ ID ] Protocol Interval Bits/s")
} else if p == UDP {
// Printing packets only makes sense for UDP as it is a datagram protocol.
// For TCP, TCP itself decides how to chunk the stream to send as packets.
ui.printMsg("[ ID ] Protocol Interval Bits/s Pkts/s")
}
}
func printBwTestResult(p EthrProtocol, fd string, t0, t1, bw, pps uint64) {
if p == TCP {
ui.printMsg("[%5s] %-5s %03d-%03d sec %7s", fd,
protoToString(p), t0, t1, bytesToRate(bw))
} else if p == UDP {
ui.printMsg("[%5s] %-5s %03d-%03d sec %7s %7s", fd,
protoToString(p), t0, t1, bytesToRate(bw), ppsToString(pps))
}
}
func printTestResult(test *ethrTest, seconds uint64) {
if test.testID.Type == Bandwidth &&
(test.testID.Protocol == TCP || test.testID.Protocol == UDP) {
if gInterval == 0 {
printBwTestDivider(test.testID.Protocol)
printBwTestHeader(test.testID.Protocol)
}
cbw := uint64(0)
cpps := uint64(0)
ccount := 0
test.connListDo(func(ec *ethrConn) {
bw := atomic.SwapUint64(&ec.bw, 0)
pps := atomic.SwapUint64(&ec.pps, 0)
bw /= seconds
if !gNoConnectionStats {
fd := fmt.Sprintf("%5d", ec.fd)
printBwTestResult(test.testID.Protocol, fd, gInterval, gInterval+1, bw, pps)
}
cbw += bw
cpps += pps
ccount++
})
if ccount > 1 || gNoConnectionStats {
printBwTestResult(test.testID.Protocol, "SUM", gInterval, gInterval+1, cbw, cpps)
if !gNoConnectionStats {
printBwTestDivider(test.testID.Protocol)
}
}
logResults([]string{test.session.remoteIP, protoToString(test.testID.Protocol),
bytesToRate(cbw), "", ppsToString(cpps), ""})
} else if test.testID.Type == Cps {
if gInterval == 0 {
ui.printMsg("- - - - - - - - - - - - - - - - - - ")
ui.printMsg("Protocol Interval Conn/s")
}
cps := atomic.SwapUint64(&test.testResult.cps, 0)
ui.printMsg(" %-5s %03d-%03d sec %7s",
protoToString(test.testID.Protocol),
gInterval, gInterval+1, cpsToString(cps))
logResults([]string{test.session.remoteIP, protoToString(test.testID.Protocol),
"", cpsToString(cps), "", ""})
} else if test.testID.Type == Pps {
if gInterval == 0 {
ui.printMsg("- - - - - - - - - - - - - - - - - - - - - - -")
ui.printMsg("Protocol Interval Bits/s Pkts/s")
}
bw := atomic.SwapUint64(&test.testResult.bw, 0)
pps := atomic.SwapUint64(&test.testResult.pps, 0)
ui.printMsg(" %-5s %03d-%03d sec %7s %7s",
protoToString(test.testID.Protocol),
gInterval, gInterval+1, bytesToRate(bw), ppsToString(pps))
logResults([]string{test.session.remoteIP, protoToString(test.testID.Protocol),
bytesToRate(bw), "", ppsToString(pps), ""})
} else if test.testID.Type == MyTraceRoute {
if gCurHops > 0 {
ui.printMsg("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ")
ui.printMsg("Host: %-40s Sent Recv Last Avg Best Wrst", test.session.remoteIP)
}
for i := 0; i < gCurHops; i++ {
hopData := gHop[i]
if hopData.addr != "" {
if hopData.sent > 0 {
avg := time.Duration(0)
if hopData.rcvd > 0 {
avg = time.Duration(hopData.total.Nanoseconds() / int64(hopData.rcvd))
}
ui.printMsg("%2d.|--%-40s %5d %5d %9s %9s %9s %9s", i+1, hopData.addr, hopData.sent, hopData.rcvd,
durationToString(hopData.last), durationToString(avg), durationToString(hopData.best), durationToString(hopData.worst))
}
} else {
ui.printMsg("%2d.|--%-40s %5s %5s %9s %9s %9s %9s", i+1, "???", "-", "-", "-", "-", "-", "-")
}
}
}
gInterval++
}
func (u *clientUI) emitTestResult(s *ethrSession, proto EthrProtocol, seconds uint64) {
var testList = []EthrTestType{Bandwidth, Cps, Pps, TraceRoute, MyTraceRoute}
for _, testType := range testList {
test, found := s.tests[EthrTestID{proto, testType}]
if found && test.isActive {
printTestResult(test, seconds)
}
}
}