Skip to content

Commit

Permalink
proc/native: optimize native.status through buffering (go-delve#1865)
Browse files Browse the repository at this point in the history
Benchmark before:

BenchmarkConditionalBreakpoints-4              1        15649407130 ns/op

Benchmark after:

BenchmarkConditionalBreakpoints-4   	       1	14586710018 ns/op

Conditional breakpoint evaluation 1.56ms -> 1.45ms

Updates go-delve#1549
  • Loading branch information
aarzilli authored and abner-chenc committed Nov 23, 2020
1 parent 787a4f0 commit f30ec25
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/proc/native/proc_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package native

import (
"bufio"
"bytes"
"errors"
"fmt"
Expand Down Expand Up @@ -351,6 +352,7 @@ func status(pid int, comm string) rune {
return '\000'
}
defer f.Close()
rd := bufio.NewReader(f)

var (
p int
Expand All @@ -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
}

Expand Down

0 comments on commit f30ec25

Please sign in to comment.