mirror of
https://github.com/shirou/gopsutil.git
synced 2025-05-01 13:48:52 +08:00
initial commit of v3 migration.
This commit is contained in:
parent
f810d518bb
commit
9bbeb5bc81
13
tools/v3migration/v3Changes.md
Normal file
13
tools/v3migration/v3Changes.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# v2 to v3 changes
|
||||||
|
|
||||||
|
|
||||||
|
- create v3 directory
|
||||||
|
- Remove process.NetIOCounters (#429)
|
||||||
|
- rename memoryLimitInBbytes JSON key in docker (#464)
|
||||||
|
- fix cgroup filename (#464)
|
||||||
|
- RLimit is now uint64 (#364)
|
||||||
|
|
||||||
|
### not yet
|
||||||
|
|
||||||
|
- mem.VirtualMemoryStat JSON fields capitalization and TestX_String tests (#545)
|
||||||
|
- Determine if process is running in the foreground (#596)
|
74
tools/v3migration/v3migration.go
Normal file
74
tools/v3migration/v3migration.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"go/ast"
|
||||||
|
"go/format"
|
||||||
|
"go/parser"
|
||||||
|
"go/token"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"golang.org/x/tools/go/ast/astutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
// https://github.com/shirou/gopsutil/issues/429
|
||||||
|
func issue429() error {
|
||||||
|
f := func(filename string) error {
|
||||||
|
fset := token.NewFileSet()
|
||||||
|
expr, err := parser.ParseFile(fset, filename, nil, parser.ParseComments)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
n := astutil.Apply(expr, func(cr *astutil.Cursor) bool {
|
||||||
|
if cr.Name() == "Decls" {
|
||||||
|
switch n := cr.Node().(type) {
|
||||||
|
case *ast.FuncDecl:
|
||||||
|
if n.Name.Name == "NetIOCounters" || n.Name.Name == ("NetIOCountersWithContext") {
|
||||||
|
cr.Delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}, nil)
|
||||||
|
return replace(filename, fset, n)
|
||||||
|
}
|
||||||
|
|
||||||
|
root := "process/process_"
|
||||||
|
fnames := []string{"darwin.go", "fallback.go", "freebsd.go", "linux.go", "openbsd.go", "posix.go", "windows.go", "test.go"}
|
||||||
|
for _, fname := range fnames {
|
||||||
|
if err := f(root + fname); err != nil {
|
||||||
|
log.Fatalln("run 429:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func replace(filename string, fset *token.FileSet, n ast.Node) error {
|
||||||
|
if err := os.Remove(filename); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fp, err := os.Create(filename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer fp.Close()
|
||||||
|
if err := format.Node(fp, fset, n); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fp.WriteString("\n")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
for _, n := range flag.Args() {
|
||||||
|
fmt.Println("issue:" + n)
|
||||||
|
switch n {
|
||||||
|
case "429":
|
||||||
|
issue429()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
63
tools/v3migration/v3migration.sh
Normal file
63
tools/v3migration/v3migration.sh
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
# this scripts is used when migrating v2 to v3.
|
||||||
|
# usage: cd ${GOPATH}/src/github.com/shirou/gopsutil && bash tools/v3migration/v3migration.sh
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
|
ROOT=$(cd ${DIR}/../.. && pwd)
|
||||||
|
|
||||||
|
|
||||||
|
## 1. refresh
|
||||||
|
cd ${ROOT}
|
||||||
|
|
||||||
|
/bin/rm -rf v3
|
||||||
|
|
||||||
|
## 2. copy directories
|
||||||
|
# docker is removed, #464 will be fixed
|
||||||
|
mkdir -p v3
|
||||||
|
cp -rp cpu disk docker host internal load mem net process winservices v3
|
||||||
|
|
||||||
|
# build migartion tool
|
||||||
|
go build -o v3/v3migration ${DIR}/v3migration.go
|
||||||
|
|
||||||
|
|
||||||
|
V3DIR=$(cd ${ROOT}/v3 && pwd)
|
||||||
|
cd ${V3DIR}
|
||||||
|
|
||||||
|
## 3. mod
|
||||||
|
go mod init
|
||||||
|
|
||||||
|
### change import path
|
||||||
|
find . -name "*.go" | xargs -I@ sed -i 's|"github.com/shirou/gopsutil/|"github.com/shirou/gopsutil/v3/|g' @
|
||||||
|
|
||||||
|
############ Issues
|
||||||
|
|
||||||
|
# #429 process.NetIOCounters is pointless on Linux
|
||||||
|
./v3migration `pwd` 429
|
||||||
|
|
||||||
|
|
||||||
|
# #464 CgroupMem : fix typo and wrong file names
|
||||||
|
sed -i 's|memoryLimitInBbytes|memoryLimitInBytes|g' docker/docker.go
|
||||||
|
sed -i 's|memoryLimitInBbytes|memory.limit_in_bytes|g' docker/docker_linux.go
|
||||||
|
sed -i 's|memoryFailcnt|"memory.failcnt|g' docker/docker_linux.go
|
||||||
|
|
||||||
|
|
||||||
|
# fix #346
|
||||||
|
sed -i 's/Soft int32/Soft uint64/' process/process.go
|
||||||
|
sed -i 's/Hard int32/Hard uint64/' process/process.go
|
||||||
|
sed -i 's| //TODO too small. needs to be uint64||' process/process.go
|
||||||
|
sed -i 's|limitToInt(val string) (int32, error)|limitToUint(val string) (uint64, error)|' process/process_*.go
|
||||||
|
sed -i 's|limitToInt|limitToUint|' process/process_*.go
|
||||||
|
sed -i 's|return int32(res), nil|return uint64(res), nil|' process/process_*.go
|
||||||
|
sed -i 's|math.MaxInt32|math.MaxUint64|' process/process_*.go
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
############ SHOULD BE FIXED BY HAND
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user