Skip to content

fix: use the windows api function equivalent to rusage #1470

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package _Time

import (
"syscall"
"time"

"github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Wrappers"
Expand Down Expand Up @@ -36,12 +35,3 @@ func CurrentRelativeTimeMilli() int64 {
func (CompanionStruct_Default___) GetProcessCpuTimeMillis() int64 {
return GetProcessCpuTimeMillis()
}

func GetProcessCpuTimeMillis() int64 {
var usage syscall.Rusage
err := syscall.Getrusage(syscall.RUSAGE_SELF, &usage)
if err != nil {
return 0
}
return (usage.Utime.Nano() + usage.Stime.Nano()) / 1000000
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build !windows
// +build !windows

package _Time

import "syscall"

func GetProcessCpuTimeMillis() int64 {
var usage syscall.Rusage
err := syscall.Getrusage(syscall.RUSAGE_SELF, &usage)
if err != nil {
return 0
}
return (usage.Utime.Nano() + usage.Stime.Nano()) / 1000000
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//go:build windows
// +build windows

package _Time

import (
"golang.org/x/sys/windows"
)


func GetProcessCpuTimeMillis() int64 {
windows.GetCurrentProcessId()
var proc_handle windows.Handle
var err error
if proc_handle, err = windows.OpenProcess(windows.PROCESS_QUERY_INFORMATION|windows.PROCESS_VM_READ, false, uint32(windows.GetCurrentProcessId())); err != nil {
return 0
}
var creation_time, exit_time, kernel_time, user_time *windows.Filetime
if err = windows.GetProcessTimes(proc_handle, creation_time, exit_time, kernel_time, user_time); err != nil {
return 0
}
return (int64(kernel_time.Nanoseconds()) + int64(user_time.Nanoseconds())) / 1000000
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ go 1.23.0
require github.com/dafny-lang/DafnyRuntimeGo/v4 v4.9.2

require github.com/google/uuid v1.6.0

require golang.org/x/sys v0.32.0 // indirect
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ github.com/dafny-lang/DafnyRuntimeGo/v4 v4.9.2 h1:g/xAj4F7Zt9wXJ6QjfbfocVi/ZYlAF
github.com/dafny-lang/DafnyRuntimeGo/v4 v4.9.2/go.mod h1:l2Tm4N2DKuq3ljONC2vOATeM9PUpXbIc8SgXdwwqEto=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=