cmd/syncthing: Use a 10 second EWMA for CPU usage, refactor a little
We have it lying around so might as well use it instead of inventing our own thing. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4111
This commit is contained in:
18
cmd/syncthing/cpuusage_unix.go
Normal file
18
cmd/syncthing/cpuusage_unix.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// 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 https://mozilla.org/MPL/2.0/.
|
||||
|
||||
//+build !windows,!solaris
|
||||
|
||||
package main
|
||||
|
||||
import "syscall"
|
||||
import "time"
|
||||
|
||||
func cpuUsage() time.Duration {
|
||||
var rusage syscall.Rusage
|
||||
syscall.Getrusage(syscall.RUSAGE_SELF, &rusage)
|
||||
return time.Duration(rusage.Utime.Nano() + rusage.Stime.Nano())
|
||||
}
|
||||
Reference in New Issue
Block a user