mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Extract traffic formatter
This commit is contained in:
parent
f12cfe6a9f
commit
9208364475
1 changed files with 17 additions and 17 deletions
|
@ -72,28 +72,28 @@ func (b *bytesSyncLogger) AddInbound(amount int) {
|
||||||
|
|
||||||
// ThroughputSummary view a formatted summary of the throughput totals
|
// ThroughputSummary view a formatted summary of the throughput totals
|
||||||
func (b *bytesSyncLogger) ThroughputSummary() string {
|
func (b *bytesSyncLogger) ThroughputSummary() string {
|
||||||
var inUnit, outUnit string
|
|
||||||
units := []string{"B", "KB", "MB", "GB"}
|
|
||||||
|
|
||||||
inbound := b.inbound
|
inbound := b.inbound
|
||||||
outbound := b.outbound
|
outbound := b.outbound
|
||||||
|
|
||||||
for i, u := range units {
|
inbound, inUnit := formatTraffic(inbound)
|
||||||
inUnit = u
|
outbound, outUnit := formatTraffic(outbound)
|
||||||
if (inbound < 1000) || (i == len(units)-1) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
inbound = inbound / 1000
|
|
||||||
}
|
|
||||||
for i, u := range units {
|
|
||||||
outUnit = u
|
|
||||||
if (outbound < 1000) || (i == len(units)-1) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
outbound = outbound / 1000
|
|
||||||
}
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
return fmt.Sprintf("Traffic throughput (up|down): %d %s|%d %s -- (%d OnMessages, %d Sends, over %d seconds)", inbound, inUnit, outbound, outUnit, b.outEvents, b.inEvents, int(t.Sub(b.start).Seconds()))
|
return fmt.Sprintf("Traffic throughput (up|down): %d %s|%d %s -- (%d OnMessages, %d Sends, over %d seconds)", inbound, inUnit, outbound, outUnit, b.outEvents, b.inEvents, int(t.Sub(b.start).Seconds()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bytesSyncLogger) GetStat() (in int, out int) { return b.inbound, b.outbound }
|
func (b *bytesSyncLogger) GetStat() (in int, out int) { return b.inbound, b.outbound }
|
||||||
|
|
||||||
|
func formatTraffic(amount int) (value int, unit string) {
|
||||||
|
value = amount
|
||||||
|
units := []string{"B", "KB", "MB", "GB"}
|
||||||
|
for i, u := range units {
|
||||||
|
unit = u
|
||||||
|
if (value < 1000) || (i == len(units)-1) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
value = value / 1000
|
||||||
|
}
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue