From 53b6dfd3acef1b4c6ec09acced916a3c0ca96975 Mon Sep 17 00:00:00 2001 From: apoorv Date: Sat, 24 Jun 2017 14:23:56 +0530 Subject: [PATCH] Read /proc/net files with a single read syscall. As per https://github.com/shirou/gopsutil/pull/361 --- net/net_linux.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/net/net_linux.go b/net/net_linux.go index c1ae46cf4..2b8a412ad 100644 --- a/net/net_linux.go +++ b/net/net_linux.go @@ -3,6 +3,7 @@ package net import ( + "bytes" "encoding/hex" "errors" "fmt" @@ -610,14 +611,18 @@ func processInet(file string, kind netConnectionKindType, inodes map[string][]in // IPv6 not supported, return empty. return []connTmp{}, nil } - lines, err := common.ReadLines(file) + + contents, err := ioutil.ReadFile(file) if err != nil { return nil, err } + + lines := bytes.Split(contents, []byte("\n")) + var ret []connTmp // skip first line for _, line := range lines[1:] { - l := strings.Fields(line) + l := strings.Fields(string(line)) if len(l) < 10 { continue } @@ -664,15 +669,17 @@ func processInet(file string, kind netConnectionKindType, inodes map[string][]in } func processUnix(file string, kind netConnectionKindType, inodes map[string][]inodeMap, filterPid int32) ([]connTmp, error) { - lines, err := common.ReadLines(file) + contents, err := ioutil.ReadFile(file) if err != nil { return nil, err } + lines := bytes.Split(contents, []byte("\n")) + var ret []connTmp // skip first line for _, line := range lines[1:] { - tokens := strings.Fields(line) + tokens := strings.Fields(string(line)) if len(tokens) < 6 { continue }