Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

add --stats-unit option and improve alignment for --stats output

Scott McGillivrayf9df545e3c3c
diff --git a/cmd/cmd.go b/cmd/cmd.go
index 17cac7c6c..4c628d01d 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -11,6 +11,7 @@ import (
"log"
"os"
"path"
+ "regexp"
"runtime"
"runtime/pprof"
"time"
@@ -27,6 +28,7 @@ var (
cpuProfile = pflag.StringP("cpuprofile", "", "", "Write cpu profile to file")
memProfile = pflag.String("memprofile", "", "Write memory profile to file")
statsInterval = pflag.DurationP("stats", "", time.Minute*1, "Interval between printing stats, e.g 500ms, 60s, 5m. (0 to disable)")
+ dataRateUnit = pflag.StringP("stats-unit", "", "bytes", "Show data rate in stats as either 'bits' or 'bytes'/s")
version bool
logFile = pflag.StringP("log-file", "", "", "Log everything to this file")
retries = pflag.IntP("retries", "", 3, "Retry operations this many times if they fail")
@@ -293,4 +295,11 @@ func initConfig() {
}
}()
}
+
+ if m, _ := regexp.MatchString("^(bits|bytes)$", *dataRateUnit); m == false {
+ fs.ErrorLog(nil, "Invalid unit passed to --stats-unit. Defaulting to bytes.")
+ fs.Config.DataRateUnit = "bytes"
+ } else {
+ fs.Config.DataRateUnit = *dataRateUnit
+ }
}
diff --git a/docs/content/docs.md b/docs/content/docs.md
index d9d29905b..502bb8169 100644
--- a/docs/content/docs.md
+++ b/docs/content/docs.md
@@ -396,6 +396,19 @@ This sets the interval.
The default is `1m`. Use 0 to disable.
+### --stats-unit=bits|bytes ###
+
+By default data transfer rates will be printed in bytes/second.
+
+This option allows the data rate to be printed in bits/second.
+
+Data transfer volume will still be reported in bytes.
+
+The rate is reported as a binary unit, not SI unit. So 1 Mbit/s
+equals 1,048,576 bits/s and not 1,000,000 bits/s.
+
+The default is `bytes`.
+
### --delete-(before,during,after) ###
This option allows you to specify when files on your destination are
diff --git a/fs/accounting.go b/fs/accounting.go
index f04d2e423..c2bfedaff 100644
--- a/fs/accounting.go
+++ b/fs/accounting.go
@@ -129,6 +129,11 @@ func (s *StatsInfo) String() string {
}
dtRounded := dt - (dt % (time.Second / 10))
buf := &bytes.Buffer{}
+
+ if Config.DataRateUnit == "bits" {
+ speed = speed * 8
+ }
+
fmt.Fprintf(buf, `
Transferred: %10s (%s)
Errors: %10d
@@ -136,7 +141,7 @@ Checks: %10d
Transferred: %10d
Elapsed time: %10v
`,
- SizeSuffix(s.bytes).Unit("Bytes"), SizeSuffix(speed).Unit("Bytes/s"),
+ SizeSuffix(s.bytes).Unit("Bytes"), SizeSuffix(speed).Unit(strings.Title(Config.DataRateUnit)+"/s"),
s.errors,
s.checks,
s.transfers,
@@ -438,10 +443,21 @@ func (acc *Account) String() string {
where := len(name) - 42
name = append([]rune{'.', '.', '.'}, name[where:]...)
}
- if b <= 0 {
- return fmt.Sprintf("%45s: avg:%7.1f, cur: %6.1f kByte/s. ETA: %s", string(name), avg/1024, cur/1024, etas)
+
+ if Config.DataRateUnit == "bits" {
+ cur, avg = cur*8, avg*8
+ }
+
+ done := ""
+ if b > 0 {
+ done = fmt.Sprintf("%2d%% done, ", int(100*float64(a)/float64(b)))
}
- return fmt.Sprintf("%45s: %2d%% done. avg: %6.1f, cur: %6.1f kByte/s. ETA: %s", string(name), int(100*float64(a)/float64(b)), avg/1024, cur/1024, etas)
+ return fmt.Sprintf("%45s: %s%s, ETA: %s",
+ string(name),
+ done,
+ SizeSuffix(cur).Unit(strings.Title(Config.DataRateUnit)+"/s"),
+ etas,
+ )
}
// Close the object
diff --git a/fs/config.go b/fs/config.go
index 89556f23e..4da97e53a 100644
--- a/fs/config.go
+++ b/fs/config.go
@@ -301,6 +301,7 @@ type ConfigInfo struct {
IgnoreSize bool
NoTraverse bool
NoUpdateModTime bool
+ DataRateUnit string
}
// Find the config directory