Skip to content

Commit

Permalink
[1] Fix windows load avg (#1)
Browse files Browse the repository at this point in the history
Use the same logic as in Linux[^1] but with
`NtQuerySystemInformation` Windows API call.[^2]

[^1]: https://www.brendangregg.com/blog/2017-08-08/linux-load-averages.html

[^2]: see shirou#1358
  • Loading branch information
elfrucool authored Mar 25, 2024
1 parent e767a0f commit fb3f2d8
Show file tree
Hide file tree
Showing 101 changed files with 381 additions and 166 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ linters-settings:
sections:
- standard
- default
- prefix(github.com/shirou)
- prefix(github.com/cloudsoda)
gomodguard:
blocked:
modules:
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# gopsutil: psutil for golang

[![Test](https://github.com/shirou/gopsutil/actions/workflows/test.yml/badge.svg)](https://github.com/shirou/gopsutil/actions/workflows/test.yml) [![Coverage Status](https://coveralls.io/repos/github/shirou/gopsutil/badge.svg?branch=master)](https://coveralls.io/github/shirou/gopsutil?branch=master) [![Go Reference](https://pkg.go.dev/badge/github.com/shirou/gopsutil/v3.svg)](https://pkg.go.dev/github.com/shirou/gopsutil/v3) [![Go Documentation](https://godocs.io/github.com/shirou/gopsutil/v3?status.svg)](https://godocs.io/github.com/shirou/gopsutil/v3) [![Calendar Versioning](https://img.shields.io/badge/calver-vMAJOR.YY.MM-22bfda.svg)](https://calver.org/)
[![Test](https://github.com/CloudSoda/gopsutil/actions/workflows/test.yml/badge.svg)](https://github.com/CloudSoda/gopsutil/actions/workflows/test.yml) [![Coverage Status](https://coveralls.io/repos/github/CloudSoda/gopsutil/badge.svg?branch=master)](https://coveralls.io/github/CloudSoda/gopsutil?branch=master) [![Go Reference](https://pkg.go.dev/badge/github.com/CloudSoda/gopsutil/v3.svg)](https://pkg.go.dev/github.com/CloudSoda/gopsutil/v3) [![Go Documentation](https://godocs.io/github.com/CloudSoda/gopsutil/v3?status.svg)](https://godocs.io/github.com/CloudSoda/gopsutil/v3) [![Calendar Versioning](https://img.shields.io/badge/calver-vMAJOR.YY.MM-22bfda.svg)](https://calver.org/)

This is a port of psutil (https://github.com/giampaolo/psutil). The
challenge is porting all psutil functions on some architectures.
Expand Down Expand Up @@ -52,8 +52,8 @@ package main
import (
"fmt"

"github.com/shirou/gopsutil/v3/mem"
// "github.com/shirou/gopsutil/mem" // to use v2
"github.com/CloudSoda/gopsutil/v3/mem"
// "github.com/CloudSoda/gopsutil/mem" // to use v2
)

func main() {
Expand Down Expand Up @@ -98,7 +98,7 @@ You can set an alternative location to `/proc/N/mountinfo` by setting the

### Adding settings using `context` (from v3.23.6)

As of v3.23.6, it is now possible to pass a path location using `context`: import `"github.com/shirou/gopsutil/v3/common"` and pass a context with `common.EnvMap` set to `common.EnvKey`, and the location will be used within each function.
As of v3.23.6, it is now possible to pass a path location using `context`: import `"github.com/CloudSoda/gopsutil/v3/common"` and pass a context with `common.EnvMap` set to `common.EnvKey`, and the location will be used within each function.

```
ctx := context.WithValue(context.Background(),
Expand All @@ -113,7 +113,7 @@ First priority is given to the value set in `context`, then the value from the e

As of v3.24.1, it is now possible to cached some values. These values default to false, not cached.

Be very careful that enabling the cache may cause inconsistencies. For example, if you enable caching of boottime on Linux, be aware that unintended values may be returned if [the boottime is changed by NTP after booted](https://github.com/shirou/gopsutil/issues/1070#issuecomment-842512782).
Be very careful that enabling the cache may cause inconsistencies. For example, if you enable caching of boottime on Linux, be aware that unintended values may be returned if [the boottime is changed by NTP after booted](https://github.com/CloudSoda/gopsutil/issues/1070#issuecomment-842512782).

- `host`
- EnableBootTimeCache
Expand All @@ -122,7 +122,7 @@ Be very careful that enabling the cache may cause inconsistencies. For example,

## Documentation

See https://pkg.go.dev/github.com/shirou/gopsutil/v3 or https://godocs.io/github.com/shirou/gopsutil/v3
See https://pkg.go.dev/github.com/CloudSoda/gopsutil/v3 or https://godocs.io/github.com/CloudSoda/gopsutil/v3

## Requirements

Expand Down
18 changes: 9 additions & 9 deletions _tools/v3migration/v3Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

- v3 is in the `v3` directory

- [process] RLimit is now uint64 ([#364](https://github.com/shirou/gopsutil/issues/364))
- [process] Remove process.NetIOCounters ([#429](https://github.com/shirou/gopsutil/issues/429))
- [docker] fix typo of memoryLimitInBbytes ([#464](https://github.com/shirou/gopsutil/issues/464))
- [mem] VirtualMemoryStat JSON fields capitalization ([#545](https://github.com/shirou/gopsutil/issues/545))
- [process] RLimit is now uint64 ([#364](https://github.com/CloudSoda/gopsutil/issues/364))
- [process] Remove process.NetIOCounters ([#429](https://github.com/CloudSoda/gopsutil/issues/429))
- [docker] fix typo of memoryLimitInBbytes ([#464](https://github.com/CloudSoda/gopsutil/issues/464))
- [mem] VirtualMemoryStat JSON fields capitalization ([#545](https://github.com/CloudSoda/gopsutil/issues/545))
- various JSON field name and some of Variable name have been changed. see v3migration.sh
- [all] various kind of platform dependent values/constants such as process.GetWin32Proc is now private. see v3migration.sh
- [process] process.Status() now returns []string. and status string is "Running", not just "R". defined in process.go. ([#596](https://github.com/shirou/gopsutil/issues/596))
- [docker] `CgroupCPU()` now returns `*CgroupCPUStat` with Usage ([#590](https://github.com/shirou/gopsutil/issues/590) and [#581](https://github.com/shirou/gopsutil/issues/581))
- [disk] `disk.Opts` is now string[], not string. (related to [#955](https://github.com/shirou/gopsutil/issues/955))
- [host] Fixed temperature sensors detection in Linux ([#905](https://github.com/shirou/gopsutil/issues/905))
- [process] process.Status() now returns []string. and status string is "Running", not just "R". defined in process.go. ([#596](https://github.com/CloudSoda/gopsutil/issues/596))
- [docker] `CgroupCPU()` now returns `*CgroupCPUStat` with Usage ([#590](https://github.com/CloudSoda/gopsutil/issues/590) and [#581](https://github.com/CloudSoda/gopsutil/issues/581))
- [disk] `disk.Opts` is now string[], not string. (related to [#955](https://github.com/CloudSoda/gopsutil/issues/955))
- [host] Fixed temperature sensors detection in Linux ([#905](https://github.com/CloudSoda/gopsutil/issues/905))
- [disk] `GetDiskSerialNumber()` is now `SerialNumber()` and spread to all platforms
- [disk] `GetLabel ()` is now `Label()` and spread to all platform
- [net] Change net.InterfaceStat.Addrs to InterfaceAddrList ([#226](https://github.com/shirou/gopsutil/issues/226))
- [net] Change net.InterfaceStat.Addrs to InterfaceAddrList ([#226](https://github.com/CloudSoda/gopsutil/issues/226))
- [cpu] Removed windows-specific `ProcInfo()`
2 changes: 1 addition & 1 deletion _tools/v3migration/v3migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"golang.org/x/tools/go/ast/astutil"
)

// https://github.com/shirou/gopsutil/issues/429
// https://github.com/cloudsoda/gopsutil/issues/429
func issue429() error {
f := func(filename string) error {
fset := token.NewFileSet()
Expand Down
6 changes: 3 additions & 3 deletions _tools/v3migration/v3migration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -eu

# this scripts is used when migrating v2 to v3.
# usage: cd ${GOPATH}/src/github.com/shirou/gopsutil && bash tools/v3migration/v3migration.sh
# usage: cd ${GOPATH}/src/github.com/CloudSoda/gopsutil && bash tools/v3migration/v3migration.sh



Expand Down Expand Up @@ -33,14 +33,14 @@ cd "${V3DIR}"
go mod init

### change import path
find . -name "*.go" -print0 | xargs -0 -I@ sed -i 's|"github.com/shirou/gopsutil/|"github.com/shirou/gopsutil/v3/|g' @
find . -name "*.go" -print0 | xargs -0 -I@ sed -i 's|"github.com/CloudSoda/gopsutil/|"github.com/CloudSoda/gopsutil/v3/|g' @

############ Issues

# #429 process.NetIOCounters is pointless on Linux
./v3migration "$(pwd)" 429
sed -i '/NetIOCounters/d' process/process.go
sed -i "/github.com\/shirou\/gopsutil\/v3\/net/d" process/process_bsd.go
sed -i "/github.com\/CloudSoda\/gopsutil\/v3\/net/d" process/process_bsd.go


# #464 CgroupMem : fix typo and wrong file names
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"sync"
"time"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
)

// TimesStat contains the amounts of time the CPU has spent performing different
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu_aix_nocgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strconv"
"strings"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
)

func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu_darwin_nocgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package cpu

import "github.com/shirou/gopsutil/v3/internal/common"
import "github.com/cloudsoda/gopsutil/v3/internal/common"

func perCPUTimes() ([]TimesStat, error) {
return []TimesStat{}, common.ErrNotImplementedError
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu_dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"unsafe"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
"github.com/tklauser/go-sysconf"
"golang.org/x/sys/unix"
)
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu_fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
"runtime"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
)

func Times(percpu bool) ([]TimesStat, error) {
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"unsafe"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
"github.com/tklauser/go-sysconf"
"golang.org/x/sys/unix"
)
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu_freebsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime"
"testing"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
)

func TestParseDmesgBoot(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/tklauser/go-sysconf"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
)

var ClocksPerSec = float64(100)
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestCPUCountsAgainstLscpu(t *testing.T) {
}
}

func TestCPUCountsLogicalAndroid_1037(t *testing.T) { // https://github.com/shirou/gopsutil/issues/1037
func TestCPUCountsLogicalAndroid_1037(t *testing.T) { // https://github.com/cloudsoda/gopsutil/issues/1037
t.Setenv("HOST_PROC", "testdata/linux/1037/proc")

count, err := Counts(true)
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu_netbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"runtime"
"unsafe"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
"github.com/tklauser/go-sysconf"
"golang.org/x/sys/unix"
)
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"runtime"
"unsafe"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
"github.com/tklauser/go-sysconf"
"golang.org/x/sys/unix"
)
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"runtime"

stats "github.com/lufia/plan9stats"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
)

func Times(percpu bool) ([]TimesStat, error) {
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
)

func skipIfNotImplementedErr(t *testing.T, err error) {
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"unsafe"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
"github.com/yusufpapurcu/wmi"
"golang.org/x/sys/windows"
)
Expand Down
2 changes: 1 addition & 1 deletion disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
)

var invoke common.Invoker = common.Invoke{}
Expand Down
2 changes: 1 addition & 1 deletion disk/disk_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package disk
import (
"context"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
)

func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
Expand Down
2 changes: 1 addition & 1 deletion disk/disk_aix_nocgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"regexp"
"strings"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
"golang.org/x/sys/unix"
)

Expand Down
4 changes: 2 additions & 2 deletions disk/disk_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"golang.org/x/sys/unix"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
)

// PartitionsWithContext returns disk partition.
Expand All @@ -28,7 +28,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
// On 10.14, and possibly other OS versions, the actual count may
// be less than from the first call. Truncate to the returned count
// to prevent accessing uninitialized entries.
// https://github.com/shirou/gopsutil/issues/1390
// https://github.com/cloudsoda/gopsutil/issues/1390
fs = fs[:count]
for _, stat := range fs {
opts := []string{"rw"}
Expand Down
2 changes: 1 addition & 1 deletion disk/disk_darwin_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import "C"
import (
"context"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
)

func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
Expand Down
2 changes: 1 addition & 1 deletion disk/disk_darwin_nocgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package disk
import (
"context"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
)

func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
Expand Down
2 changes: 1 addition & 1 deletion disk/disk_fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package disk
import (
"context"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
)

func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
Expand Down
2 changes: 1 addition & 1 deletion disk/disk_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strconv"
"strings"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
"golang.org/x/sys/unix"
)

Expand Down
2 changes: 1 addition & 1 deletion disk/disk_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

"golang.org/x/sys/unix"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion disk/disk_netbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
"unsafe"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
"golang.org/x/sys/unix"
)

Expand Down
2 changes: 1 addition & 1 deletion disk/disk_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"context"
"encoding/binary"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
"golang.org/x/sys/unix"
)

Expand Down
2 changes: 1 addition & 1 deletion disk/disk_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"strconv"
"strings"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
"golang.org/x/sys/unix"
)

Expand Down
4 changes: 2 additions & 2 deletions disk/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"
"testing"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
)

func skipIfNotImplementedErr(t *testing.T, err error) {
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestDisk_io_counters(t *testing.T) {
}
}

// https://github.com/shirou/gopsutil/issues/560 regression test
// https://github.com/cloudsoda/gopsutil/issues/560 regression test
func TestDisk_io_counters_concurrency_on_darwin_cgo(t *testing.T) {
if runtime.GOOS != "darwin" {
t.Skip("darwin only")
Expand Down
2 changes: 1 addition & 1 deletion disk/disk_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
ret.UsedPercent = 0
} else {
// We don't use ret.Total to calculate percent.
// see https://github.com/shirou/gopsutil/issues/562
// see https://github.com/cloudsoda/gopsutil/issues/562
ret.UsedPercent = (float64(ret.Used) / float64(ret.Used+ret.Free)) * 100.0
}

Expand Down
2 changes: 1 addition & 1 deletion disk/disk_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"syscall"
"unsafe"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/cloudsoda/gopsutil/v3/internal/common"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
)
Expand Down
Loading

0 comments on commit fb3f2d8

Please sign in to comment.