aboutsummaryrefslogtreecommitdiff
path: root/internal/progress/refresh.go
blob: ed1782db7ffbaab3778780bbb1675c799320d16e (about) (plain) (blame)
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
package progress

import "time"

func (meter *Meter) refreshThroughput(now time.Time) {
	if !meter.throughput {
		return
	}

	if meter.nextThroughput.After(now) && meter.throughputSuffix != "" {
		return
	}

	for !now.Before(meter.nextThroughput) {
		meter.nextThroughput = meter.nextThroughput.Add(throughputInterval)
	}

	elapsed := now.Sub(meter.startedAt)
	if elapsed <= 0 {
		return
	}

	rate := uint64(float64(meter.lastBytes) / elapsed.Seconds())
	meter.throughputSuffix = ", " + humanizeBytes(meter.lastBytes) + " | " + humanizeBytes(rate) + "/s"
}