forked from TrueCloudLab/restic
Merge pull request #1384 from wojas/reduce-ticker-refresh
Reduce ticker refresh rate with RESTIC_PROGRESS_FPS env
This commit is contained in:
commit
f1cfb73a8b
1 changed files with 15 additions and 1 deletions
|
@ -3,17 +3,31 @@ package restic
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
"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 isTerminal = terminal.IsTerminal(int(os.Stdout.Fd()))
|
||||||
var forceUpdateProgress = make(chan bool)
|
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.
|
// Progress reports progress on an operation.
|
||||||
type Progress struct {
|
type Progress struct {
|
||||||
OnStart func()
|
OnStart func()
|
||||||
|
|
Loading…
Reference in a new issue