Skip to content

Commit

Permalink
delete v2 directory, move v3 to top #1078
Browse files Browse the repository at this point in the history
  • Loading branch information
shirou committed Nov 30, 2021
1 parent 3b41707 commit 0969c94
Show file tree
Hide file tree
Showing 327 changed files with 1,059 additions and 28,126 deletions.
4 changes: 0 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
version: 2
updates:
- package-ecosystem: gomod
directory: /v3
schedule:
interval: daily
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
11 changes: 0 additions & 11 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
v3:
- v3/**/*.go
package:cpu:
- cpu/*
- v3/cpu/*
package:disk:
- disk/*
- v3/disk/*
package:docker:
- docker/*
- v3/docker/*
package:host:
- host/*
- v3/host/*
package:load:
- load/*
- v3/load/*
package:mem:
- mem/*
- v3/mem/*
package:net:
- net/*
- v3/net/*
package:process:
- process/*
- v3/process/*
package:winservices:
- winservices/*
- v3/winservices/*
os:linux:
- ./**/*_linux.go
- ./**/*_linux_mips64.go
Expand Down
34 changes: 1 addition & 33 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,6 @@
on: [push, pull_request]
name: Build Test
jobs:
build_test_v2:
env:
GOPATH: ${{ github.workspace }}
GO111MODULE: off
strategy:
matrix:
go-version: [1.16.x, 1.17.x]
runs-on: ubuntu-20.04
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
with:
path: ${{ github.workspace }}/src/github.com/shirou/gopsutil
- name: Get dependencies
if: runner.os != 'Windows'
run: |
if ! command -v dep &>/dev/null; then
mkdir -p $GOPATH/bin
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
echo "PATH=$GOPATH/bin:$PATH" >> $GITHUB_PATH
fi
cd $GOPATH/src/github.com/shirou/gopsutil
dep ensure
# exclude v3 from being run with ./...
rm -rf $GOPATH/src/github.com/shirou/gopsutil/v3
- name: Build Test v2
run: |
cd $GOPATH/src/github.com/shirou/gopsutil && make build_test
build_test_v3:
strategy:
matrix:
Expand All @@ -47,4 +15,4 @@ jobs:
uses: actions/checkout@v2
- name: Build Test v3
run: |
cd v3 && make build_test
make build_test
74 changes: 1 addition & 73 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,76 +16,4 @@ jobs:
uses: actions/checkout@v2
- name: Test
run: |
cd ./v3/
go test ./...
test_v3_gopath:
env:
GOPATH: ${{ github.workspace }}
GO111MODULE: off
strategy:
matrix:
go-version: [1.16.x, 1.17.x]
os: [ubuntu-20.04, ubuntu-18.04, windows-2019, windows-2016, macOS-10.15, macos-11]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
with:
path: ${{ github.workspace }}/src/github.com/shirou/gopsutil
- name: Get dependencies
run: |
go get -t github.com/shirou/gopsutil/v3/...
- name: Test
run: |
go test github.com/shirou/gopsutil/v3/...
test_v2_gopath:
env:
GOPATH: ${{ github.workspace }}
GO111MODULE: off
strategy:
matrix:
go-version: [1.16.x, 1.17.x]
os: [ubuntu-20.04, ubuntu-18.04, windows-2019, windows-2016, macOS-10.15, macos-11]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
with:
path: ${{ github.workspace }}/src/github.com/shirou/gopsutil
- name: Get dependencies
if: runner.os == 'Windows'
run: |
go get -d -u github.com/golang/dep
cd $Env:GOPATH/src/github.com/golang/dep
git checkout v0.5.4
go install -ldflags="-X main.version=v0.5.4" ./cmd/dep
echo "$Env:GOPATH/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
cd $Env:GOPATH/src/github.com/shirou/gopsutil
dep ensure
# exclude v3 from being run with ./...
try { rm -ErrorAction:Stop -Recurse -Force $Env:GOPATH/src/github.com/shirou/gopsutil/v3 } catch [System.Management.Automation.ItemNotFoundException] {}
- name: Get dependencies
if: runner.os != 'Windows'
run: |
if ! command -v dep &>/dev/null; then
mkdir -p $GOPATH/bin
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
echo "PATH=$GOPATH/bin:$PATH" >> $GITHUB_PATH
fi
cd $GOPATH/src/github.com/shirou/gopsutil
dep ensure
# exclude v3 from being run with ./...
rm -rf $GOPATH/src/github.com/shirou/gopsutil/v3
- name: Test
run: |
go test github.com/shirou/gopsutil/...
go test ./...
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
.DEFAULT_GOAL := help

SUBPKGS=cpu disk docker host internal load mem net process
TAG=$(shell date +'v3.%y.%-m' --date='last Month')

help: ## Show help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand All @@ -29,6 +28,7 @@ build_test: ## test only buildable
GOOS=netbsd go test ./... | $(BUILD_FAIL_PATTERN)
# cross build to OpenBSD not worked since process has "C"
# GOOS=openbsd go test ./... | $(BUILD_FAIL_PATTERN)
GOOS=plan9 go test ./... | $(BUILD_FAIL_PATTERN)

ifeq ($(shell uname -s), Darwin)
CGO_ENABLED=1 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN)
Expand Down Expand Up @@ -68,13 +68,18 @@ vet:
GOOS=windows GOARCH=amd64 go vet ./...
GOOS=windows GOARCH=386 go vet ./...

GOOS=plan9 GOARCH=amd64 go vet ./...
GOOS=plan9 GOARCH=386 go vet ./...

macos_test:
CGO_ENABLED=0 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN)
CGO_ENABLED=1 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN)

init_tools:
go get github.com/golang/dep/cmd/dep

TAG=$(shell date +'v3.%y.%-m' --date='last Month')

release:
git tag $(TAG)
git push origin $(TAG)
2 changes: 1 addition & 1 deletion cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sync"
"time"

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

// TimesStat contains the amounts of time the CPU has spent performing different
Expand Down
10 changes: 5 additions & 5 deletions cpu/cpu_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
// sys/resource.h
const (
CPUser = 0
CPNice = 1
CPSys = 2
CPIntr = 3
CPIdle = 4
CPUStates = 5
cpNice = 1
cpSys = 2
cpIntr = 3
cpIdle = 4
cpUStates = 5
)

// default value. from time.h
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/internal/common"
import "github.com/shirou/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/internal/common"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/tklauser/go-sysconf"
"golang.org/x/sys/unix"
)
Expand Down
4 changes: 2 additions & 2 deletions cpu/cpu_fallback.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows,!dragonfly
// +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows,!dragonfly,!plan9

package cpu

import (
"context"
"runtime"

"github.com/shirou/gopsutil/internal/common"
"github.com/shirou/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/internal/common"
"github.com/shirou/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/internal/common"
"github.com/shirou/gopsutil/v3/internal/common"
)

func TestParseDmesgBoot(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions cpu/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strconv"
"strings"

"github.com/shirou/gopsutil/internal/common"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/tklauser/go-sysconf"
)

Expand Down Expand Up @@ -321,7 +321,7 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
if err == nil {
for _, line := range lines {
line = strings.ToLower(line)
if strings.HasPrefix(line, "processor") {
if strings.HasPrefix(line, "processor") {
_, err = strconv.Atoi(strings.TrimSpace(line[strings.IndexByte(line, ':')+1:]))
if err == nil {
ret++
Expand Down
44 changes: 22 additions & 22 deletions cpu/cpu_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ import (
"strings"
"syscall"

"github.com/shirou/gopsutil/internal/common"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/tklauser/go-sysconf"
"golang.org/x/sys/unix"
)

// sys/sched.h
var (
CPUser = 0
CPNice = 1
CPSys = 2
CPIntr = 3
CPIdle = 4
CPUStates = 5
cpNice = 1
cpSys = 2
cpIntr = 3
cpIdle = 4
cpUStates = 5
)

// sys/sysctl.h
const (
CTLKern = 1 // "high kernel": proc, limits
CTLHw = 6 // CTL_HW
SMT = 24 // HW_SMT
KernCptime = 40 // KERN_CPTIME
KernCptime2 = 71 // KERN_CPTIME2
ctlKern = 1 // "high kernel": proc, limits
ctlHw = 6 // CTL_HW
sMT = 24 // HW_sMT
kernCptime = 40 // KERN_CPTIME
kernCptime2 = 71 // KERN_CPTIME2
)

var ClocksPerSec = float64(128)
Expand All @@ -56,15 +56,15 @@ func init() {
return
}
if version >= 6.4 {
CPIntr = 4
CPIdle = 5
CPUStates = 6
cpIntr = 4
cpIdle = 5
cpUStates = 6
}
}()
}

func smt() (bool, error) {
mib := []int32{CTLHw, SMT}
mib := []int32{ctlHw, sMT}
buf, _, err := common.CallSyscall(mib)
if err != nil {
return false, err
Expand Down Expand Up @@ -108,12 +108,12 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
j *= 2
}

var cpuTimes = make([]int32, CPUStates)
var cpuTimes = make([]int32, cpUStates)
var mib []int32
if percpu {
mib = []int32{CTLKern, KernCptime2, int32(j)}
mib = []int32{ctlKern, kernCptime2, int32(j)}
} else {
mib = []int32{CTLKern, KernCptime}
mib = []int32{ctlKern, kernCptime}
}
buf, _, err := common.CallSyscall(mib)
if err != nil {
Expand All @@ -127,10 +127,10 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
}
c := TimesStat{
User: float64(cpuTimes[CPUser]) / ClocksPerSec,
Nice: float64(cpuTimes[CPNice]) / ClocksPerSec,
System: float64(cpuTimes[CPSys]) / ClocksPerSec,
Idle: float64(cpuTimes[CPIdle]) / ClocksPerSec,
Irq: float64(cpuTimes[CPIntr]) / ClocksPerSec,
Nice: float64(cpuTimes[cpNice]) / ClocksPerSec,
System: float64(cpuTimes[cpSys]) / ClocksPerSec,
Idle: float64(cpuTimes[cpIdle]) / ClocksPerSec,
Irq: float64(cpuTimes[cpIntr]) / ClocksPerSec,
}
if percpu {
c.CPU = fmt.Sprintf("cpu%d", j)
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cpu/cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/shirou/gopsutil/internal/common"
"github.com/shirou/gopsutil/v3/internal/common"
"github.com/stretchr/testify/assert"
)

Expand Down
Loading

0 comments on commit 0969c94

Please sign in to comment.