usage_unix.go 987 B

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