mirror of https://github.com/restic/restic.git
Unify progress report frequency calculation
This commit is contained in:
parent
969141b5e9
commit
85fe5feadb
|
@ -11,7 +11,6 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -545,15 +544,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, term *termstatus.Termina
|
||||||
}()
|
}()
|
||||||
gopts.stdout, gopts.stderr = p.Stdout(), p.Stderr()
|
gopts.stdout, gopts.stderr = p.Stdout(), p.Stderr()
|
||||||
|
|
||||||
if s, ok := os.LookupEnv("RESTIC_PROGRESS_FPS"); ok {
|
p.SetMinUpdatePause(calculateProgressInterval())
|
||||||
fps, err := strconv.Atoi(s)
|
|
||||||
if err == nil && fps >= 1 {
|
|
||||||
if fps > 60 {
|
|
||||||
fps = 60
|
|
||||||
}
|
|
||||||
p.SetMinUpdatePause(time.Second / time.Duration(fps))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Go(func() error { return p.Run(t.Context(gopts.ctx)) })
|
t.Go(func() error { return p.Run(t.Context(gopts.ctx)) })
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,10 @@ import (
|
||||||
"github.com/restic/restic/internal/ui/progress"
|
"github.com/restic/restic/internal/ui/progress"
|
||||||
)
|
)
|
||||||
|
|
||||||
// newProgressMax returns a progress.Counter that prints to stdout.
|
// calculateProgressInterval returns the interval configured via RESTIC_PROGRESS_FPS
|
||||||
func newProgressMax(show bool, max uint64, description string) *progress.Counter {
|
// or if unset returns an interval for 60fps on interactive terminals and 0 (=disabled)
|
||||||
if !show {
|
// for non-interactive terminals
|
||||||
return nil
|
func calculateProgressInterval() time.Duration {
|
||||||
}
|
|
||||||
|
|
||||||
interval := time.Second / 60
|
interval := time.Second / 60
|
||||||
fps, err := strconv.ParseInt(os.Getenv("RESTIC_PROGRESS_FPS"), 10, 64)
|
fps, err := strconv.ParseInt(os.Getenv("RESTIC_PROGRESS_FPS"), 10, 64)
|
||||||
if err == nil && fps >= 1 {
|
if err == nil && fps >= 1 {
|
||||||
|
@ -25,6 +23,15 @@ func newProgressMax(show bool, max uint64, description string) *progress.Counter
|
||||||
} else if !stdoutIsTerminal() {
|
} else if !stdoutIsTerminal() {
|
||||||
interval = 0
|
interval = 0
|
||||||
}
|
}
|
||||||
|
return interval
|
||||||
|
}
|
||||||
|
|
||||||
|
// newProgressMax returns a progress.Counter that prints to stdout.
|
||||||
|
func newProgressMax(show bool, max uint64, description string) *progress.Counter {
|
||||||
|
if !show {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
interval := calculateProgressInterval()
|
||||||
|
|
||||||
return progress.New(interval, func(v uint64, d time.Duration, final bool) {
|
return progress.New(interval, func(v uint64, d time.Duration, final bool) {
|
||||||
status := fmt.Sprintf("[%s] %s %d / %d %s",
|
status := fmt.Sprintf("[%s] %s %d / %d %s",
|
||||||
|
|
Loading…
Reference in New Issue