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

syscall: Update documented syscall.Timeval units #43010

Closed
ntBre opened this issue Dec 4, 2020 · 3 comments
Closed

syscall: Update documented syscall.Timeval units #43010

ntBre opened this issue Dec 4, 2020 · 3 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ntBre
Copy link

ntBre commented Dec 4, 2020

What version of Go are you using (go version)?

$ go version
go version go1.15.5 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/brent/.cache/go-build"
GOENV="/home/brent/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/brent/Projects/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/brent/Projects/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build211847425=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I was trying to check the CPU time used by my program using syscall.Getrusage() and syscall.Rusage.Timeval.Nano().
Example code:

func GetCPU() int64 {
	use := new(syscall.Rusage)
	syscall.Getrusage(syscall.RUSAGE_SELF, use)
	return use.Utime.Nano() + use.Stime.Nano()
}

Link to playground: https://play.golang.org/p/-HYHrxvlzwv

What did you expect to see?

I expected the output of use.Utime.Nano() and use.Stime.Nano() to be in units of "nanoseconds elapsed since the Unix epoch" as the documentation states.

What did you see instead?

Instead, I think the results are just the nanoseconds of CPU time used, not nanoseconds since the Unix epoch. That seems to be how the underlying system calls work anyway, so I think the documentation just needs to be updated.

@toothrot
Copy link
Contributor

toothrot commented Dec 8, 2020

/cc @ianlancetaylor @bradfitz

@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 8, 2020
@toothrot toothrot added this to the Backlog milestone Dec 8, 2020
@gopherbot
Copy link

Change https://golang.org/cl/277073 mentions this issue: syscall: drop referencet to Unix epoch in Timeval/Timespec docs

@gopherbot
Copy link

Change https://golang.org/cl/277252 mentions this issue: unix: drop references to Unix epoch in Timeval/Timespec docs

@dmitshur dmitshur modified the milestones: Backlog, Go1.16 Dec 13, 2020
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Dec 13, 2020
gopherbot pushed a commit to golang/sys that referenced this issue Dec 14, 2020
Follow what CL 277073 did for package syscall:

The various conversion functions just change the format of time values.
They don't use the Unix epoch. Although in practice the values are often
times since the Unix epoch, they aren't always, so referring to the
epoch can be confusing.

Updates golang/go#43010

Change-Id: Icb9953e20d7cab8e36ddfb467dc2380ee181f18b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/277252
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@golang golang locked and limited conversation to collaborators Dec 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants
@toothrot @dmitshur @gopherbot @ntBre and others