Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace time.Now().Sub by time.Since #1173

Merged
merged 1 commit into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/daemon/peer/peertask_conductor.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ func (pt *peerTaskConductor) waitFirstPeerPacket() (done bool, backSource bool)
if ok {
// preparePieceTasksByPeer func already send piece result with error
pt.Infof("new peer client ready, scheduler time cost: %dus, main peer: %s",
time.Now().Sub(pt.startTime).Microseconds(), pt.peerPacket.Load().(*scheduler.PeerPacket).MainPeer)
time.Since(pt.startTime).Microseconds(), pt.peerPacket.Load().(*scheduler.PeerPacket).MainPeer)
return true, false
}
// when scheduler says base.Code_SchedNeedBackSource, receivePeerPacket will close pt.peerPacketReady
Expand Down Expand Up @@ -1170,7 +1170,7 @@ func (pt *peerTaskConductor) done() {
pt.span.End()
}()
var (
cost = time.Now().Sub(pt.startTime).Milliseconds()
cost = time.Since(pt.startTime).Milliseconds()
success = true
code = base.Code_Success
)
Expand Down
2 changes: 1 addition & 1 deletion client/daemon/peer/peertask_reuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (ptm *peerTaskManager) tryReuseFilePeerTask(ctx context.Context,
return nil, false
}

var cost = time.Now().Sub(start).Milliseconds()
var cost = time.Since(start).Milliseconds()
log.Infof("reuse file peer task done, cost: %dms", cost)

pg := &FileTaskProgress{
Expand Down
2 changes: 1 addition & 1 deletion client/daemon/storage/storage_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ func (s *storageManager) TryGC() (bool, error) {
}
// task is not done, and is active in s.gcInterval
// next gc loop will check it again
if !task.Done && time.Now().Sub(time.Unix(0, task.lastAccess.Load())) < s.gcInterval {
if !task.Done && time.Since(time.Unix(0, task.lastAccess.Load())) < s.gcInterval {
return true
}
tasks = append(tasks, task)
Expand Down
4 changes: 2 additions & 2 deletions client/dfget/dfget.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func singleDownload(ctx context.Context, client daemonclient.DaemonClient, cfg *
_ = pb.Close()
}

wLog.Infof("download from daemon success, length: %d bytes cost: %d ms", result.CompletedLength, time.Now().Sub(start).Milliseconds())
wLog.Infof("download from daemon success, length: %d bytes cost: %d ms", result.CompletedLength, time.Since(start).Milliseconds())
fmt.Printf("finish total length %d bytes\n", result.CompletedLength)

break
Expand Down Expand Up @@ -188,7 +188,7 @@ func downloadFromSource(ctx context.Context, cfg *config.DfgetConfig, hdr map[st
return err
}

wLog.Infof("download from source success, length: %d bytes cost: %d ms", written, time.Now().Sub(start).Milliseconds())
wLog.Infof("download from source success, length: %d bytes cost: %d ms", written, time.Since(start).Milliseconds())
fmt.Printf("finish total length %d bytes\n", written)

return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/dfget/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var rootCmd = &cobra.Command{
errInfo = fmt.Sprintf("error: %v", err)
}

msg := fmt.Sprintf("download success: %t cost: %d ms %s", err == nil, time.Now().Sub(start).Milliseconds(), errInfo)
msg := fmt.Sprintf("download success: %t cost: %d ms %s", err == nil, time.Since(start).Milliseconds(), errInfo)
logger.With("url", dfgetConfig.URL).Info(msg)
fmt.Println(msg)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ require (
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.28.0
github.com/schollz/progressbar/v3 v3.8.2
github.com/serialx/hashring v0.0.0-20200727003509-22c0c7ab6b1b
github.com/shirou/gopsutil/v3 v3.21.11
Expand Down Expand Up @@ -164,6 +163,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.28.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
Expand Down