[process][linux] get name from /proc/(pid)/comm

pull/1112/head
xuyang2
parent 7203001e29
commit a9757c7de9

@ -66,11 +66,11 @@ func Test_Process_splitProcStat_fromFile(t *testing.T) {
defer f() defer f()
for _, pid := range pids { for _, pid := range pids {
pid, err := strconv.ParseInt(pid.Name(), 0, 32) pid, err := strconv.ParseInt(pid.Name(), 0, 32)
if err != nil{ if err != nil {
continue continue
} }
statFile := fmt.Sprintf("testdata/linux/%d/stat", pid) statFile := fmt.Sprintf("testdata/linux/%d/stat", pid)
if _, err := os.Stat(statFile); err != nil{ if _, err := os.Stat(statFile); err != nil {
continue continue
} }
contents, err := ioutil.ReadFile(statFile) contents, err := ioutil.ReadFile(statFile)
@ -125,10 +125,10 @@ func Test_fillFromStatusWithContext(t *testing.T) {
defer f() defer f()
for _, pid := range pids { for _, pid := range pids {
pid, err := strconv.ParseInt(pid.Name(), 0, 32) pid, err := strconv.ParseInt(pid.Name(), 0, 32)
if err != nil{ if err != nil {
continue continue
} }
if _, err := os.Stat(fmt.Sprintf("testdata/linux/%d/status", pid)); err != nil{ if _, err := os.Stat(fmt.Sprintf("testdata/linux/%d/status", pid)); err != nil {
continue continue
} }
p, _ := NewProcess(int32(pid)) p, _ := NewProcess(int32(pid))
@ -138,6 +138,26 @@ func Test_fillFromStatusWithContext(t *testing.T) {
} }
} }
func Benchmark_fillFromCommWithContext(b *testing.B) {
f := common.MockEnv("HOST_PROC", "testdata/linux")
defer f()
pid := 1060
for i := 0; i < b.N; i++ {
p, _ := NewProcess(int32(pid))
p.fillFromCommWithContext(context.Background())
}
}
func Benchmark_fillFromStatusWithContext(b *testing.B) {
f := common.MockEnv("HOST_PROC", "testdata/linux")
defer f()
pid := 1060
for i := 0; i < b.N; i++ {
p, _ := NewProcess(int32(pid))
p.fillFromStatusWithContext(context.Background())
}
}
func Test_fillFromTIDStatWithContext_lx_brandz(t *testing.T) { func Test_fillFromTIDStatWithContext_lx_brandz(t *testing.T) {
pids, err := ioutil.ReadDir("testdata/lx_brandz/") pids, err := ioutil.ReadDir("testdata/lx_brandz/")
if err != nil { if err != nil {

Loading…
Cancel
Save