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:
commit
ee64e05b02
@ -4,6 +4,7 @@ package cpu
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -23,6 +24,21 @@ const (
|
|||||||
// default value. from time.h
|
// default value. from time.h
|
||||||
var ClocksPerSec = float64(128)
|
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) {
|
func Times(percpu bool) ([]TimesStat, error) {
|
||||||
return TimesWithContext(context.Background(), percpu)
|
return TimesWithContext(context.Background(), percpu)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user