Merge pull request #361 from ablagoev/read-proc-files-with-a-single-read

Read /proc/net files with a single read syscall.
pull/365/head
shirou 8 years ago committed by GitHub
commit f7c38fa2f8

@ -3,6 +3,7 @@
package net
import (
"bytes"
"encoding/hex"
"errors"
"fmt"
@ -613,14 +614,22 @@ func processInet(file string, kind netConnectionKindType, inodes map[string][]in
// IPv6 not supported, return empty.
return []connTmp{}, nil
}
lines, err := common.ReadLines(file)
// Read the contents of the /proc file with a single read sys call.
// This minimizes duplicates in the returned connections
// For more info:
// https://github.com/shirou/gopsutil/pull/361
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
}
@ -667,15 +676,21 @@ 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)
// Read the contents of the /proc file with a single read sys call.
// This minimizes duplicates in the returned connections
// For more info:
// https://github.com/shirou/gopsutil/pull/361
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
}

Loading…
Cancel
Save