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

Commit 19caf3a

Browse files
bvwellsrghetia
authored andcommitted
Use time.Since rather than time.Now().Sub (#1160)
1 parent 29aa3ca commit 19caf3a

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

examples/derived_gauges/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (q *queue) Size() int64 {
131131
func (q *queue) Elapsed() float64 {
132132
q.mu.Lock()
133133
defer q.mu.Unlock()
134-
return time.Now().Sub(q.lastConsumed).Seconds()
134+
return time.Since(q.lastConsumed).Seconds()
135135
}
136136

137137
```
@@ -254,7 +254,7 @@ func (q *queue) Size() int64 {
254254
func (q *queue) Elapsed() float64 {
255255
q.mu.Lock()
256256
defer q.mu.Unlock()
257-
return time.Now().Sub(q.lastConsumed).Seconds()
257+
return time.Since(q.lastConsumed).Seconds()
258258
}
259259

260260

examples/derived_gauges/derived_gauge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (q *queue) Size() int64 {
130130
func (q *queue) Elapsed() float64 {
131131
q.mu.Lock()
132132
defer q.mu.Unlock()
133-
return time.Now().Sub(q.lastConsumed).Seconds()
133+
return time.Since(q.lastConsumed).Seconds()
134134
}
135135

136136
// END tofloat64

internal/internal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ var UserAgent = fmt.Sprintf("opencensus-go/%s", opencensus.Version())
3333
// end as a monotonic time.
3434
// See https://golang.org/pkg/time/#hdr-Monotonic_Clocks
3535
func MonotonicEndTime(start time.Time) time.Time {
36-
return start.Add(time.Now().Sub(start))
36+
return start.Add(time.Since(start))
3737
}

zpages/rpcz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (s snapExporter) ExportView(vd *view.Data) {
205205
if len(vd.Rows) == 0 {
206206
return
207207
}
208-
ageSec := float64(time.Now().Sub(programStartTime)) / float64(time.Second)
208+
ageSec := float64(time.Since(programStartTime)) / float64(time.Second)
209209

210210
computeRate := func(maxSec, x float64) float64 {
211211
dur := ageSec

0 commit comments

Comments
 (0)