未验证 提交 c272212b 编写于 作者: A Alessandro Arzilli 提交者: GitHub

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
上级 fbc4623c
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
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册