usage_windows.go 943 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at http://mozilla.org/MPL/2.0/.
  6. //go:build integration && benchmark && windows
  7. // +build integration,benchmark,windows
  8. package integration
  9. import (
  10. "log"
  11. "os"
  12. "syscall"
  13. "time"
  14. )
  15. func ftToDuration(ft *syscall.Filetime) time.Duration {
  16. n := int64(ft.HighDateTime)<<32 + int64(ft.LowDateTime) // in 100-nanosecond intervals
  17. return time.Duration(n*100) * time.Nanosecond
  18. }
  19. func printUsage(name string, proc *os.ProcessState, total int64) {
  20. if rusage, ok := proc.SysUsage().(*syscall.Rusage); ok {
  21. mib := total / 1024 / 1024
  22. log.Printf("%s: Utime: %s / MiB", name, time.Duration(rusage.UserTime.Nanoseconds()/mib))
  23. log.Printf("%s: Stime: %s / MiB", name, time.Duration(rusage.KernelTime.Nanoseconds()/mib))
  24. }
  25. }