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
This commit is contained in:
Alessandro Arzilli 2020-02-15 20:55:19 +01:00 committed by GitHub
parent fbc4623c08
commit c272212baa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,7 @@
package native package native
import ( import (
"bufio"
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
@ -351,6 +352,7 @@ func status(pid int, comm string) rune {
return '\000' return '\000'
} }
defer f.Close() defer f.Close()
rd := bufio.NewReader(f)
var ( var (
p int 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 // 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 // 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 // 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 return state
} }