From 5b96885c6d3c7d4067dcf2d87225be2319932d7b Mon Sep 17 00:00:00 2001 From: Konrad Wojas Date: Thu, 26 Oct 2017 14:46:56 +0800 Subject: [PATCH] Control progress rate with RESTIC_PROGRESS_FPS env Add a RESTIC_PROGRESS_FPS environment variable to limit the interval at which the progress indicator updates (allowed values: 1-60). The default rate of 60 FPS can cause high terminal CPU load on some systems, like iTerm2 on macOS with font anti-aliasing enabled. Usage: RESTIC_PROGRESS_FPS=1 restic ... RESTIC_PROGRESS_FPS=60 restic ... --- internal/restic/progress.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/restic/progress.go b/internal/restic/progress.go index e5d608f0f..12d2b8710 100644 --- a/internal/restic/progress.go +++ b/internal/restic/progress.go @@ -3,17 +3,31 @@ package restic import ( "fmt" "os" + "strconv" "sync" "time" "golang.org/x/crypto/ssh/terminal" ) -const minTickerTime = time.Second / 60 +// minTickerTime limits how often the progress ticker is updated. It can be +// overridden using the RESTIC_PROGRESS_FPS (frames per second) environment +// variable. +var minTickerTime = time.Second / 60 var isTerminal = terminal.IsTerminal(int(os.Stdout.Fd())) var forceUpdateProgress = make(chan bool) +func init() { + fps, err := strconv.ParseInt(os.Getenv("RESTIC_PROGRESS_FPS"), 10, 64) + if err == nil && fps >= 1 { + if fps > 60 { + fps = 60 + } + minTickerTime = time.Second / time.Duration(fps) + } +} + // Progress reports progress on an operation. type Progress struct { OnStart func()