add --stats-unit option and improve alignment for --stats output
This commit is contained in:
parent
5e62ede8d0
commit
f9df545e3c
4 changed files with 43 additions and 4 deletions
|
@ -11,6 +11,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"time"
|
"time"
|
||||||
|
@ -27,6 +28,7 @@ var (
|
||||||
cpuProfile = pflag.StringP("cpuprofile", "", "", "Write cpu profile to file")
|
cpuProfile = pflag.StringP("cpuprofile", "", "", "Write cpu profile to file")
|
||||||
memProfile = pflag.String("memprofile", "", "Write memory 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)")
|
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
|
version bool
|
||||||
logFile = pflag.StringP("log-file", "", "", "Log everything to this file")
|
logFile = pflag.StringP("log-file", "", "", "Log everything to this file")
|
||||||
retries = pflag.IntP("retries", "", 3, "Retry operations this many times if they fail")
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -396,6 +396,19 @@ This sets the interval.
|
||||||
|
|
||||||
The default is `1m`. Use 0 to disable.
|
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) ###
|
### --delete-(before,during,after) ###
|
||||||
|
|
||||||
This option allows you to specify when files on your destination are
|
This option allows you to specify when files on your destination are
|
||||||
|
|
|
@ -129,6 +129,11 @@ func (s *StatsInfo) String() string {
|
||||||
}
|
}
|
||||||
dtRounded := dt - (dt % (time.Second / 10))
|
dtRounded := dt - (dt % (time.Second / 10))
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
|
|
||||||
|
if Config.DataRateUnit == "bits" {
|
||||||
|
speed = speed * 8
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Fprintf(buf, `
|
fmt.Fprintf(buf, `
|
||||||
Transferred: %10s (%s)
|
Transferred: %10s (%s)
|
||||||
Errors: %10d
|
Errors: %10d
|
||||||
|
@ -136,7 +141,7 @@ Checks: %10d
|
||||||
Transferred: %10d
|
Transferred: %10d
|
||||||
Elapsed time: %10v
|
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.errors,
|
||||||
s.checks,
|
s.checks,
|
||||||
s.transfers,
|
s.transfers,
|
||||||
|
@ -438,10 +443,21 @@ func (acc *Account) String() string {
|
||||||
where := len(name) - 42
|
where := len(name) - 42
|
||||||
name = append([]rune{'.', '.', '.'}, name[where:]...)
|
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
|
||||||
}
|
}
|
||||||
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)
|
|
||||||
|
done := ""
|
||||||
|
if b > 0 {
|
||||||
|
done = fmt.Sprintf("%2d%% done, ", int(100*float64(a)/float64(b)))
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%45s: %s%s, ETA: %s",
|
||||||
|
string(name),
|
||||||
|
done,
|
||||||
|
SizeSuffix(cur).Unit(strings.Title(Config.DataRateUnit)+"/s"),
|
||||||
|
etas,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the object
|
// Close the object
|
||||||
|
|
|
@ -301,6 +301,7 @@ type ConfigInfo struct {
|
||||||
IgnoreSize bool
|
IgnoreSize bool
|
||||||
NoTraverse bool
|
NoTraverse bool
|
||||||
NoUpdateModTime bool
|
NoUpdateModTime bool
|
||||||
|
DataRateUnit string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the config directory
|
// Find the config directory
|
||||||
|
|
Loading…
Reference in a new issue