1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-05-10 19:29:14 +08:00

Merge pull request #869 from renaynay/master

Added check for `CLK_TCK` for darwin
This commit is contained in:
Lomanic 2020-05-17 21:11:00 +02:00 committed by GitHub
commit ee64e05b02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@ package cpu
import (
"context"
"os/exec"
"strconv"
"strings"
@ -23,6 +24,21 @@ const (
// default value. from time.h
var ClocksPerSec = float64(128)
func init() {
getconf, err := exec.LookPath("getconf")
if err != nil {
return
}
out, err := invoke.Command(getconf, "CLK_TCK")
// ignore errors
if err == nil {
i, err := strconv.ParseFloat(strings.TrimSpace(string(out)), 64)
if err == nil {
ClocksPerSec = float64(i)
}
}
}
func Times(percpu bool) ([]TimesStat, error) {
return TimesWithContext(context.Background(), percpu)
}