Skip to content

Commit

Permalink
common: move ProcessInfo to its own 'process' package
Browse files Browse the repository at this point in the history
  • Loading branch information
lebauce committed Mar 2, 2020
1 parent f16fed3 commit 432beda
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
34 changes: 17 additions & 17 deletions common/proc.go → process/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,36 @@
*
*/

package common
package process

import (
"fmt"
"io/ioutil"
"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
Expand All @@ -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 {
Expand All @@ -77,7 +77,7 @@ func GetProcessInfo(pid int) (*ProcessInfo, error) {
return nil, err
}

pi := &ProcessInfo{
pi := &Info{
Process: exe,
}

Expand All @@ -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
}
5 changes: 3 additions & 2 deletions topology/probes/runc/runc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions topology/probes/socketinfo/socket_info_proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 432beda

Please sign in to comment.