mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: make MemStats.LastGC Unix time again
The monotonic clock patch changed all runtime times
to abstract monotonic time. As the result user-visible
MemStats.LastGC become monotonic time as well.
Restore Unix time for LastGC.
This is the simplest way to expose time.now to runtime that I found.
Another option would be to change time.now to C called
int64 runtime.unixnanotime() and then express time.now in terms of it.
But this would require to introduce 2 64-bit divisions into time.now.
Another option would be to change time.now to C called
void runtime.unixnanotime1(struct {int64 sec, int32 nsec} *now)
and then express both time.now and runtime.unixnanotime in terms of it.
Fixes #7852.
LGTM=minux.ma, iant
R=minux.ma, rsc, iant
CC=golang-codereviews
https://golang.org/cl/93720045
This commit is contained in:
parent
3879f0abcd
commit
350a8fcde1
7 changed files with 35 additions and 1 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"runtime"
|
||||
"runtime/debug"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestGcSys(t *testing.T) {
|
||||
|
|
@ -152,6 +153,18 @@ func TestGcRescan(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGcLastTime(t *testing.T) {
|
||||
ms := new(runtime.MemStats)
|
||||
t0 := time.Now().UnixNano()
|
||||
runtime.GC()
|
||||
t1 := time.Now().UnixNano()
|
||||
runtime.ReadMemStats(ms)
|
||||
last := int64(ms.LastGC)
|
||||
if t0 > last || last > t1 {
|
||||
t.Fatalf("bad last GC time: got %v, want [%v, %v]", last, t0, t1)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSetTypeNoPtr1(b *testing.B) {
|
||||
type NoPtr1 struct {
|
||||
p uintptr
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue