usage_windows.go 806 B

12345678910111213141516171819202122232425262728
  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. // +build integration,benchmark,windows
  7. package integration
  8. import (
  9. "log"
  10. "os"
  11. "syscall"
  12. "time"
  13. )
  14. func ftToDuration(ft *syscall.Filetime) time.Duration {
  15. n := int64(ft.HighDateTime)<<32 + int64(ft.LowDateTime) // in 100-nanosecond intervals
  16. return time.Duration(n*100) * time.Nanosecond
  17. }
  18. func printUsage(name string, proc *os.ProcessState) {
  19. if rusage, ok := proc.SysUsage().(*syscall.Rusage); ok {
  20. log.Printf("%s: Utime: %s", name, ftToDuration(&rusage.UserTime))
  21. log.Printf("%s: Stime: %s", name, ftToDuration(&rusage.KernelTime))
  22. }
  23. }