Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Use time.Since rather than time.Now().Sub (#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvwells authored and rghetia committed Sep 3, 2019
1 parent 29aa3ca commit 19caf3a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/derived_gauges/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (q *queue) Size() int64 {
func (q *queue) Elapsed() float64 {
q.mu.Lock()
defer q.mu.Unlock()
return time.Now().Sub(q.lastConsumed).Seconds()
return time.Since(q.lastConsumed).Seconds()
}

```
Expand Down Expand Up @@ -254,7 +254,7 @@ func (q *queue) Size() int64 {
func (q *queue) Elapsed() float64 {
q.mu.Lock()
defer q.mu.Unlock()
return time.Now().Sub(q.lastConsumed).Seconds()
return time.Since(q.lastConsumed).Seconds()
}


Expand Down
2 changes: 1 addition & 1 deletion examples/derived_gauges/derived_gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (q *queue) Size() int64 {
func (q *queue) Elapsed() float64 {
q.mu.Lock()
defer q.mu.Unlock()
return time.Now().Sub(q.lastConsumed).Seconds()
return time.Since(q.lastConsumed).Seconds()
}

// END tofloat64
Expand Down
2 changes: 1 addition & 1 deletion internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ var UserAgent = fmt.Sprintf("opencensus-go/%s", opencensus.Version())
// end as a monotonic time.
// See https://golang.org/pkg/time/#hdr-Monotonic_Clocks
func MonotonicEndTime(start time.Time) time.Time {
return start.Add(time.Now().Sub(start))
return start.Add(time.Since(start))
}
2 changes: 1 addition & 1 deletion zpages/rpcz.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (s snapExporter) ExportView(vd *view.Data) {
if len(vd.Rows) == 0 {
return
}
ageSec := float64(time.Now().Sub(programStartTime)) / float64(time.Second)
ageSec := float64(time.Since(programStartTime)) / float64(time.Second)

computeRate := func(maxSec, x float64) float64 {
dur := ageSec
Expand Down

0 comments on commit 19caf3a

Please sign in to comment.