From 1d1f7347cea87c74a40af50f909e6d8c312b5aa6 Mon Sep 17 00:00:00 2001 From: Michael Schubert Date: Wed, 19 Apr 2017 12:43:01 +0200 Subject: [PATCH] proc_linux: don't exec `getNetNamespacePathSuffix()` on every walk --- probe/endpoint/procspy/proc_linux.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/probe/endpoint/procspy/proc_linux.go b/probe/endpoint/procspy/proc_linux.go index d94c8700e..b6a88985c 100644 --- a/probe/endpoint/procspy/proc_linux.go +++ b/probe/endpoint/procspy/proc_linux.go @@ -25,10 +25,11 @@ var ( ) type pidWalker struct { - walker process.Walker - tickc <-chan time.Time // Rate-limit clock. Sets the pace when traversing namespaces and /proc/PID/fd/* files. - stopc chan struct{} // Abort walk - fdBlockSize uint64 // Maximum number of /proc/PID/fd/* files to stat() per tick + walker process.Walker + tickc <-chan time.Time // Rate-limit clock. Sets the pace when traversing namespaces and /proc/PID/fd/* files. + stopc chan struct{} // Abort walk + fdBlockSize uint64 // Maximum number of /proc/PID/fd/* files to stat() per tick + netNamespacePathSuffix string } func newPidWalker(walker process.Walker, tickc <-chan time.Time, fdBlockSize uint64) pidWalker { @@ -37,6 +38,7 @@ func newPidWalker(walker process.Walker, tickc <-chan time.Time, fdBlockSize uin tickc: tickc, fdBlockSize: fdBlockSize, stopc: make(chan struct{}), + netNamespacePathSuffix: getNetNamespacePathSuffix(), } return w } @@ -219,7 +221,7 @@ func (w pidWalker) walk(buf *bytes.Buffer) (map[uint64]*Proc, error) { w.walker.Walk(func(p, _ process.Process) { dirName := strconv.Itoa(p.PID) - netNamespacePath := filepath.Join(procRoot, dirName, getNetNamespacePathSuffix()) + netNamespacePath := filepath.Join(procRoot, dirName, w.netNamespacePathSuffix) if err := fs.Stat(netNamespacePath, &statT); err != nil { return }