usage_unix.go 915 B

1234567891011121314151617181920212223242526272829303132
  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, total int64) {
  16. if rusage, ok := proc.SysUsage().(*syscall.Rusage); ok {
  17. mib := total / 1024 / 1024
  18. log.Printf("%s: Utime: %s / MiB", name, time.Duration(rusage.Utime.Nano()/mib))
  19. log.Printf("%s: Stime: %s / MiB", name, time.Duration(rusage.Stime.Nano()/mib))
  20. if runtime.GOOS == "darwin" {
  21. // Darwin reports in bytes, Linux seems to report in KiB even
  22. // though the manpage says otherwise.
  23. rusage.Maxrss /= 1024
  24. }
  25. log.Printf("%s: MaxRSS: %d KiB", name, rusage.Maxrss)
  26. }
  27. }