1
mirror of https://github.com/rclone/rclone synced 2024-12-23 14:23:44 +01:00

accounting: Fix elapsed time not show actual time since beginning

This fixes the elapsed time display in the statistics output in the rc and in the log messages.
This commit is contained in:
Chaitanya Bankanhal 2020-07-26 16:29:50 +05:30 committed by GitHub
parent 4f9a80e2d3
commit 8913679d88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -16,6 +16,8 @@ import (
// MaxCompletedTransfers specifies maximum number of completed transfers in startedTransfers list
var MaxCompletedTransfers = 100
var startTime = time.Now()
// StatsInfo accounts all transfers
type StatsInfo struct {
mu sync.RWMutex
@ -66,7 +68,8 @@ func (s *StatsInfo) RemoteStats() (out rc.Params, err error) {
out["transfers"] = s.transfers
out["deletes"] = s.deletes
out["renames"] = s.renames
out["elapsedTime"] = s.totalDuration().Seconds()
out["transferTime"] = s.totalDuration().Seconds()
out["elapsedTime"] = time.Since(startTime).Seconds()
s.mu.RUnlock()
if !s.checking.empty() {
var c []string
@ -248,9 +251,10 @@ func (s *StatsInfo) String() string {
s.mu.RLock()
elapsedTime := time.Since(startTime)
elapsedTimeSecondsOnly := elapsedTime.Truncate(time.Second/10) % time.Minute
dt := s.totalDuration()
dtSeconds := dt.Seconds()
dtSecondsOnly := dt.Truncate(time.Second/10) % time.Minute
speed := 0.0
if dt > 0 {
speed = float64(s.bytes) / dtSeconds
@ -332,7 +336,7 @@ func (s *StatsInfo) String() string {
_, _ = fmt.Fprintf(buf, "Transferred: %10d / %d, %s\n",
s.transfers, totalTransfer, percent(s.transfers, totalTransfer))
}
_, _ = fmt.Fprintf(buf, "Elapsed time: %10ss\n", strings.TrimRight(dt.Truncate(time.Minute).String(), "0s")+fmt.Sprintf("%.1f", dtSecondsOnly.Seconds()))
_, _ = fmt.Fprintf(buf, "Elapsed time: %10ss\n", strings.TrimRight(elapsedTime.Truncate(time.Minute).String(), "0s")+fmt.Sprintf("%.1f", elapsedTimeSecondsOnly.Seconds()))
}
// checking and transferring have their own locking so unlock

View File

@ -95,6 +95,7 @@ Returns the following values:
"transfers": number of transferred files,
"deletes" : number of deleted files,
"renames" : number of renamed files,
"transferTime" : total time spent on running jobs,
"elapsedTime": time in seconds since the start of the process,
"lastError": last occurred error,
"transferring": an array of currently active file transfers: