From 432beda542b70749110b0077ccf721ca12be06d8 Mon Sep 17 00:00:00 2001 From: Sylvain Baubeau Date: Mon, 17 Feb 2020 13:43:46 +0100 Subject: [PATCH] common: move ProcessInfo to its own 'process' package --- {common => process}/proc.go | 34 +++++++++---------- topology/probes/runc/runc.go | 5 +-- .../probes/socketinfo/socket_info_proc.go | 4 +-- 3 files changed, 22 insertions(+), 21 deletions(-) rename {common => process}/proc.go (76%) diff --git a/common/proc.go b/process/proc.go similarity index 76% rename from common/proc.go rename to process/proc.go index 3b15f5a462..8c833ea658 100644 --- a/common/proc.go +++ b/process/proc.go @@ -15,7 +15,7 @@ * */ -package common +package process import ( "fmt" @@ -23,28 +23,28 @@ import ( "os" ) -// ProcessState describes the state of a process -type ProcessState rune +// State describes the state of a process +type State rune const ( // Running state - Running ProcessState = 'R' + Running State = 'R' // Sleeping state - Sleeping ProcessState = 'S' + Sleeping State = 'S' // Waiting state - Waiting ProcessState = 'D' + Waiting State = 'D' // Zombie state - Zombie ProcessState = 'Z' + Zombie State = 'Z' // Stopped state - Stopped ProcessState = 'T' + Stopped State = 'T' // TracingStop state - TracingStop ProcessState = 't' + TracingStop State = 't' // Dead state - Dead ProcessState = 'X' + Dead State = 'X' ) -// ProcessInfo describes the information of a running process -type ProcessInfo struct { +// Info describes the information of a running process +type Info struct { Process string Pid int64 Name string @@ -61,11 +61,11 @@ type ProcessInfo struct { Start int64 Vsize int64 RSS int64 - State ProcessState + State State } -// GetProcessInfo retrieve process info from /proc -func GetProcessInfo(pid int) (*ProcessInfo, error) { +// GetInfo retrieve process info from /proc +func GetInfo(pid int) (*Info, error) { processPath := fmt.Sprintf("/proc/%d", pid) exe, err := os.Readlink(processPath + "/exe") if err != nil { @@ -77,7 +77,7 @@ func GetProcessInfo(pid int) (*ProcessInfo, error) { return nil, err } - pi := &ProcessInfo{ + pi := &Info{ Process: exe, } @@ -95,7 +95,7 @@ func GetProcessInfo(pid int) (*ProcessInfo, error) { return nil, err } pi.Name = name[1 : len(name)-1] - pi.State = ProcessState(state) + pi.State = State(state) return pi, nil } diff --git a/topology/probes/runc/runc.go b/topology/probes/runc/runc.go index 6000dd7254..0af5830339 100644 --- a/topology/probes/runc/runc.go +++ b/topology/probes/runc/runc.go @@ -38,6 +38,7 @@ import ( "github.com/skydive-project/skydive/common" "github.com/skydive-project/skydive/graffiti/graph" "github.com/skydive-project/skydive/probe" + "github.com/skydive-project/skydive/process" "github.com/skydive-project/skydive/topology" tp "github.com/skydive-project/skydive/topology/probes" ns "github.com/skydive-project/skydive/topology/probes/netns" @@ -144,11 +145,11 @@ func getStatus(state *containerState) string { return "stopped" } - info, err := common.GetProcessInfo(state.InitProcessPid) + info, err := process.GetInfo(state.InitProcessPid) if err != nil { return "stopped" } - if info.Start != int64(state.InitProcessStart) || info.State == common.Zombie || info.State == common.Dead { + if info.Start != int64(state.InitProcessStart) || info.State == process.Zombie || info.State == process.Dead { return "stopped" } base := path.Base(state.path) diff --git a/topology/probes/socketinfo/socket_info_proc.go b/topology/probes/socketinfo/socket_info_proc.go index f01a1dc16d..39e30abad8 100644 --- a/topology/probes/socketinfo/socket_info_proc.go +++ b/topology/probes/socketinfo/socket_info_proc.go @@ -32,8 +32,8 @@ import ( "syscall" "time" - "github.com/skydive-project/skydive/common" "github.com/skydive-project/skydive/flow" + "github.com/skydive-project/skydive/process" tp "github.com/skydive-project/skydive/topology/probes" ) @@ -61,7 +61,7 @@ type ProcProbe struct { } func getProcessInfo(pid int) (*ProcessInfo, error) { - pi, err := common.GetProcessInfo(pid) + pi, err := process.GetInfo(pid) if err != nil { return nil, err }