mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-26 13:48:59 +08:00
remove unused code
This commit is contained in:
parent
d6f5a9e920
commit
e004ef15e1
116
net/net_linux.go
116
net/net_linux.go
@ -12,7 +12,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/internal/common"
|
"github.com/shirou/gopsutil/internal/common"
|
||||||
)
|
)
|
||||||
@ -351,8 +350,8 @@ func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fetch process owner Real, effective, saved set, and filesystem UIDs
|
// fetch process owner Real, effective, saved set, and filesystem UIDs
|
||||||
proc := Process{Pid: conn.Pid}
|
proc := process{Pid: conn.Pid}
|
||||||
conn.Uids, _ = proc.Uids()
|
conn.Uids, _ = proc.getUids()
|
||||||
|
|
||||||
// check duplicate using JSON format
|
// check duplicate using JSON format
|
||||||
json := conn.String()
|
json := conn.String()
|
||||||
@ -437,53 +436,17 @@ func Pids() ([]int32, error) {
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: the following are copys of cpu_linux / process_linux structs and methods
|
// Note: the following is based off process_linux structs and methods
|
||||||
// we need these to fetch the owner of a process ID
|
// we need these to fetch the owner of a process ID
|
||||||
// FIXME: Import process occures import cycle.
|
// FIXME: Import process occures import cycle.
|
||||||
// see remarks on pids()
|
// see remarks on pids()
|
||||||
type TimesStat struct {
|
type process struct {
|
||||||
CPU string `json:"cpu"`
|
Pid int32 `json:"pid"`
|
||||||
User float64 `json:"user"`
|
uids []int32
|
||||||
System float64 `json:"system"`
|
|
||||||
Idle float64 `json:"idle"`
|
|
||||||
Nice float64 `json:"nice"`
|
|
||||||
Iowait float64 `json:"iowait"`
|
|
||||||
Irq float64 `json:"irq"`
|
|
||||||
Softirq float64 `json:"softirq"`
|
|
||||||
Steal float64 `json:"steal"`
|
|
||||||
Guest float64 `json:"guest"`
|
|
||||||
GuestNice float64 `json:"guestNice"`
|
|
||||||
Stolen float64 `json:"stolen"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Process struct {
|
|
||||||
Pid int32 `json:"pid"`
|
|
||||||
name string
|
|
||||||
status string
|
|
||||||
parent int32
|
|
||||||
numCtxSwitches *NumCtxSwitchesStat
|
|
||||||
uids []int32
|
|
||||||
gids []int32
|
|
||||||
numThreads int32
|
|
||||||
memInfo *MemoryInfoStat
|
|
||||||
|
|
||||||
lastCPUTimes *TimesStat
|
|
||||||
lastCPUTime time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
type MemoryInfoStat struct {
|
|
||||||
RSS uint64 `json:"rss"` // bytes
|
|
||||||
VMS uint64 `json:"vms"` // bytes
|
|
||||||
Swap uint64 `json:"swap"` // bytes
|
|
||||||
}
|
|
||||||
|
|
||||||
type NumCtxSwitchesStat struct {
|
|
||||||
Voluntary int64 `json:"voluntary"`
|
|
||||||
Involuntary int64 `json:"involuntary"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uids returns user ids of the process as a slice of the int
|
// Uids returns user ids of the process as a slice of the int
|
||||||
func (p *Process) Uids() ([]int32, error) {
|
func (p *process) getUids() ([]int32, error) {
|
||||||
err := p.fillFromStatus()
|
err := p.fillFromStatus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []int32{}, err
|
return []int32{}, err
|
||||||
@ -491,8 +454,8 @@ func (p *Process) Uids() ([]int32, error) {
|
|||||||
return p.uids, nil
|
return p.uids, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get various status from /proc/(pid)/status
|
// Get status from /proc/(pid)/status
|
||||||
func (p *Process) fillFromStatus() error {
|
func (p *process) fillFromStatus() error {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
statPath := common.HostProc(strconv.Itoa(int(pid)), "status")
|
statPath := common.HostProc(strconv.Itoa(int(pid)), "status")
|
||||||
contents, err := ioutil.ReadFile(statPath)
|
contents, err := ioutil.ReadFile(statPath)
|
||||||
@ -500,8 +463,6 @@ func (p *Process) fillFromStatus() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
lines := strings.Split(string(contents), "\n")
|
lines := strings.Split(string(contents), "\n")
|
||||||
p.numCtxSwitches = &NumCtxSwitchesStat{}
|
|
||||||
p.memInfo = &MemoryInfoStat{}
|
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
tabParts := strings.SplitN(line, "\t", 2)
|
tabParts := strings.SplitN(line, "\t", 2)
|
||||||
if len(tabParts) < 2 {
|
if len(tabParts) < 2 {
|
||||||
@ -509,16 +470,6 @@ func (p *Process) fillFromStatus() error {
|
|||||||
}
|
}
|
||||||
value := tabParts[1]
|
value := tabParts[1]
|
||||||
switch strings.TrimRight(tabParts[0], ":") {
|
switch strings.TrimRight(tabParts[0], ":") {
|
||||||
case "Name":
|
|
||||||
p.name = strings.Trim(value, " \t")
|
|
||||||
case "State":
|
|
||||||
p.status = value[0:1]
|
|
||||||
case "PPid", "Ppid":
|
|
||||||
pval, err := strconv.ParseInt(value, 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
p.parent = int32(pval)
|
|
||||||
case "Uid":
|
case "Uid":
|
||||||
p.uids = make([]int32, 0, 4)
|
p.uids = make([]int32, 0, 4)
|
||||||
for _, i := range strings.Split(value, "\t") {
|
for _, i := range strings.Split(value, "\t") {
|
||||||
@ -528,56 +479,7 @@ func (p *Process) fillFromStatus() error {
|
|||||||
}
|
}
|
||||||
p.uids = append(p.uids, int32(v))
|
p.uids = append(p.uids, int32(v))
|
||||||
}
|
}
|
||||||
case "Gid":
|
|
||||||
p.gids = make([]int32, 0, 4)
|
|
||||||
for _, i := range strings.Split(value, "\t") {
|
|
||||||
v, err := strconv.ParseInt(i, 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
p.gids = append(p.gids, int32(v))
|
|
||||||
}
|
|
||||||
case "Threads":
|
|
||||||
v, err := strconv.ParseInt(value, 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
p.numThreads = int32(v)
|
|
||||||
case "voluntary_ctxt_switches":
|
|
||||||
v, err := strconv.ParseInt(value, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
p.numCtxSwitches.Voluntary = v
|
|
||||||
case "nonvoluntary_ctxt_switches":
|
|
||||||
v, err := strconv.ParseInt(value, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
p.numCtxSwitches.Involuntary = v
|
|
||||||
case "VmRSS":
|
|
||||||
value := strings.Trim(value, " kB") // remove last "kB"
|
|
||||||
v, err := strconv.ParseUint(value, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
p.memInfo.RSS = v * 1024
|
|
||||||
case "VmSize":
|
|
||||||
value := strings.Trim(value, " kB") // remove last "kB"
|
|
||||||
v, err := strconv.ParseUint(value, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
p.memInfo.VMS = v * 1024
|
|
||||||
case "VmSwap":
|
|
||||||
value := strings.Trim(value, " kB") // remove last "kB"
|
|
||||||
v, err := strconv.ParseUint(value, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
p.memInfo.Swap = v * 1024
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user