-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|
||
|