From 640b2404695cc7d903e56f9426bc1455957c5563 Mon Sep 17 00:00:00 2001 From: Alban Crequy Date: Fri, 21 Apr 2017 15:02:51 +0200 Subject: [PATCH] proc walker: optimize open file counter Golang's ReadDirNames is expensive and better avoided when we don't care about the names. --- probe/process/walker_linux.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/probe/process/walker_linux.go b/probe/process/walker_linux.go index 6c7d1f09c..a748d2bee 100644 --- a/probe/process/walker_linux.go +++ b/probe/process/walker_linux.go @@ -102,7 +102,7 @@ func (w *walker) Walk(f func(Process, Process)) error { continue } - openFiles, err := fs.ReadDirNames(path.Join(w.procRoot, filename, "fd")) + openFilesCount, err := fs.ReadDirCount(path.Join(w.procRoot, filename, "fd")) if err != nil { continue } @@ -139,7 +139,7 @@ func (w *walker) Walk(f func(Process, Process)) error { Jiffies: jiffies, RSSBytes: rss, RSSBytesLimit: rssLimit, - OpenFilesCount: len(openFiles), + OpenFilesCount: openFilesCount, OpenFilesLimit: openFilesLimit, }, Process{}) }