usage_unix.go 853 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. // +build integration,benchmark,!windows
  7. package integration
  8. import (
  9. "log"
  10. "os"
  11. "runtime"
  12. "syscall"
  13. "time"
  14. )
  15. func printUsage(name string, proc *os.ProcessState) {
  16. if rusage, ok := proc.SysUsage().(*syscall.Rusage); ok {
  17. log.Printf("%s: Utime: %s", name, time.Duration(rusage.Utime.Nano()))
  18. log.Printf("%s: Stime: %s", name, time.Duration(rusage.Stime.Nano()))
  19. if runtime.GOOS == "darwin" {
  20. // Darwin reports in bytes, Linux seems to report in KiB even
  21. // though the manpage says otherwise.
  22. rusage.Maxrss /= 1024
  23. }
  24. log.Printf("%s: MaxRSS: %d KiB", name, rusage.Maxrss)
  25. }
  26. }