syncthing/test/usage_unix.go
Jakob Borg a3c724f2c3
all: Add build constants for runtime.GOOS comparisons (#8442)
all: Add package runtimeos for runtime.GOOS comparisons

I grew tired of hand written string comparisons. This adds generated
constants for the GOOS values, and predefined Is$OS constants that can
be iffed on. In a couple of places I rewrote trivial switch:es to if:s,
and added Illumos where we checked for Solaris (because they are
effectively the same, and if we're going to target one of them that
would be Illumos...).
2022-07-28 19:36:39 +02:00

34 lines
987 B
Go

// Copyright (C) 2014 The Syncthing Authors.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
//go:build integration && benchmark && !windows
// +build integration,benchmark,!windows
package integration
import (
"log"
"os"
"syscall"
"time"
"github.com/syncthing/syncthing/lib/build"
)
func printUsage(name string, proc *os.ProcessState, total int64) {
if rusage, ok := proc.SysUsage().(*syscall.Rusage); ok {
mib := total / 1024 / 1024
log.Printf("%s: Utime: %s / MiB", name, time.Duration(rusage.Utime.Nano()/mib))
log.Printf("%s: Stime: %s / MiB", name, time.Duration(rusage.Stime.Nano()/mib))
if build.IsDarwin {
// Darwin reports in bytes, Linux seems to report in KiB even
// though the manpage says otherwise.
rusage.Maxrss /= 1024
}
log.Printf("%s: MaxRSS: %d KiB", name, rusage.Maxrss)
}
}