1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-26 13:48:59 +08:00

Merge pull request #870 from renaynay/naming-consistency

Renamed variables storing `CLK_TCK` value for consistency across OSs
This commit is contained in:
Lomanic 2020-05-31 17:01:13 +02:00 committed by GitHub
commit a901d160ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 19 deletions

View File

@ -13,7 +13,7 @@ import (
"github.com/shirou/gopsutil/internal/common" "github.com/shirou/gopsutil/internal/common"
) )
var CPUTick = float64(100) var ClocksPerSec = float64(100)
func init() { func init() {
getconf, err := exec.LookPath("getconf") getconf, err := exec.LookPath("getconf")
@ -25,7 +25,7 @@ func init() {
if err == nil { if err == nil {
i, err := strconv.ParseFloat(strings.TrimSpace(string(out)), 64) i, err := strconv.ParseFloat(strings.TrimSpace(string(out)), 64)
if err == nil { if err == nil {
CPUTick = i ClocksPerSec = i
} }
} }
} }
@ -250,34 +250,34 @@ func parseStatLine(line string) (*TimesStat, error) {
ct := &TimesStat{ ct := &TimesStat{
CPU: cpu, CPU: cpu,
User: user / CPUTick, User: user / ClocksPerSec,
Nice: nice / CPUTick, Nice: nice / ClocksPerSec,
System: system / CPUTick, System: system / ClocksPerSec,
Idle: idle / CPUTick, Idle: idle / ClocksPerSec,
Iowait: iowait / CPUTick, Iowait: iowait / ClocksPerSec,
Irq: irq / CPUTick, Irq: irq / ClocksPerSec,
Softirq: softirq / CPUTick, Softirq: softirq / ClocksPerSec,
} }
if len(fields) > 8 { // Linux >= 2.6.11 if len(fields) > 8 { // Linux >= 2.6.11
steal, err := strconv.ParseFloat(fields[8], 64) steal, err := strconv.ParseFloat(fields[8], 64)
if err != nil { if err != nil {
return nil, err return nil, err
} }
ct.Steal = steal / CPUTick ct.Steal = steal / ClocksPerSec
} }
if len(fields) > 9 { // Linux >= 2.6.24 if len(fields) > 9 { // Linux >= 2.6.24
guest, err := strconv.ParseFloat(fields[9], 64) guest, err := strconv.ParseFloat(fields[9], 64)
if err != nil { if err != nil {
return nil, err return nil, err
} }
ct.Guest = guest / CPUTick ct.Guest = guest / ClocksPerSec
} }
if len(fields) > 10 { // Linux >= 3.2.0 if len(fields) > 10 { // Linux >= 3.2.0
guestNice, err := strconv.ParseFloat(fields[10], 64) guestNice, err := strconv.ParseFloat(fields[10], 64)
if err != nil { if err != nil {
return nil, err return nil, err
} }
ct.GuestNice = guestNice / CPUTick ct.GuestNice = guestNice / ClocksPerSec
} }
return ct, nil return ct, nil

View File

@ -50,7 +50,7 @@ type Win32_PerfFormattedData_PerfOS_System struct {
} }
const ( const (
win32_TicksPerSecond = 10000000.0 ClocksPerSec = 10000000.0
// systemProcessorPerformanceInformationClass information class to query with NTQuerySystemInformation // systemProcessorPerformanceInformationClass information class to query with NTQuerySystemInformation
// https://processhacker.sourceforge.io/doc/ntexapi_8h.html#ad5d815b48e8f4da1ef2eb7a2f18a54e0 // https://processhacker.sourceforge.io/doc/ntexapi_8h.html#ad5d815b48e8f4da1ef2eb7a2f18a54e0
@ -159,10 +159,10 @@ func perCPUTimes() ([]TimesStat, error) {
for core, v := range stats { for core, v := range stats {
c := TimesStat{ c := TimesStat{
CPU: fmt.Sprintf("cpu%d", core), CPU: fmt.Sprintf("cpu%d", core),
User: float64(v.UserTime) / win32_TicksPerSecond, User: float64(v.UserTime) / ClocksPerSec,
System: float64(v.KernelTime-v.IdleTime) / win32_TicksPerSecond, System: float64(v.KernelTime-v.IdleTime) / ClocksPerSec,
Idle: float64(v.IdleTime) / win32_TicksPerSecond, Idle: float64(v.IdleTime) / ClocksPerSec,
Irq: float64(v.InterruptTime) / win32_TicksPerSecond, Irq: float64(v.InterruptTime) / ClocksPerSec,
} }
ret = append(ret, c) ret = append(ret, c)
} }

View File

@ -117,13 +117,13 @@ func CgroupCPUWithContext(ctx context.Context, containerID string, base string)
if fields[0] == "user" { if fields[0] == "user" {
user, err := strconv.ParseFloat(fields[1], 64) user, err := strconv.ParseFloat(fields[1], 64)
if err == nil { if err == nil {
ret.User = user / cpu.CPUTick ret.User = user / cpu.ClocksPerSec
} }
} }
if fields[0] == "system" { if fields[0] == "system" {
system, err := strconv.ParseFloat(fields[1], 64) system, err := strconv.ParseFloat(fields[1], 64)
if err == nil { if err == nil {
ret.System = system / cpu.CPUTick ret.System = system / cpu.ClocksPerSec
} }
} }
} }