From c272212baa3b3ff81408b1c6f323c8ad8b14e93a Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Sat, 15 Feb 2020 20:55:19 +0100 Subject: [PATCH] proc/native: optimize native.status through buffering (#1865) Benchmark before: BenchmarkConditionalBreakpoints-4 1 15649407130 ns/op Benchmark after: BenchmarkConditionalBreakpoints-4 1 14586710018 ns/op Conditional breakpoint evaluation 1.56ms -> 1.45ms Updates #1549 --- pkg/proc/native/proc_linux.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/proc/native/proc_linux.go b/pkg/proc/native/proc_linux.go index 855d399e..c188202a 100644 --- a/pkg/proc/native/proc_linux.go +++ b/pkg/proc/native/proc_linux.go @@ -1,6 +1,7 @@ package native import ( + "bufio" "bytes" "errors" "fmt" @@ -351,6 +352,7 @@ func status(pid int, comm string) rune { return '\000' } defer f.Close() + rd := bufio.NewReader(f) var ( p int @@ -361,7 +363,7 @@ func status(pid int, comm string) rune { // The name of the task is the base name of the executable for this process limited to TASK_COMM_LEN characters // Since both parenthesis and spaces can appear inside the name of the task and no escaping happens we need to read the name of the executable first // See: include/linux/sched.c:315 and include/linux/sched.c:1510 - fmt.Fscanf(f, "%d ("+comm+") %c", &p, &state) + fmt.Fscanf(rd, "%d ("+comm+") %c", &p, &state) return state }