Skip to content

Commit

Permalink
Increase Stat() buffer size
Browse files Browse the repository at this point in the history
Increase the /proc/stat scanner tokens size from the default of 65k to
1024k. This allows for scanning of large `intr` lines with > 65k
columns.
* Increase the scanner buffer from the default 4kB to 8kB bytes at a time.

Fixes: #546

Signed-off-by: SuperQ <superq@gmail.com>
  • Loading branch information
SuperQ committed Jul 10, 2023
1 parent 46aea31 commit dbd0bc5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions stat.go
Expand Up @@ -187,6 +187,9 @@ func parseStat(r io.Reader, fileName string) (Stat, error) {
err error
)

buf := make([]byte, 0, 8*1024)
scanner.Buffer(buf, 1024*1024)

for scanner.Scan() {
line := scanner.Text()
parts := strings.Fields(scanner.Text())
Expand Down
2 changes: 1 addition & 1 deletion stat_test.go
Expand Up @@ -30,7 +30,7 @@ func TestStat(t *testing.T) {
}

// intr
if want, have := uint64(8885917), s.IRQTotal; want != have {
if want, have := uint64(73777505), s.IRQTotal; want != have {
t.Errorf("want irq/total %d, have %d", want, have)
}
if want, have := uint64(1), s.IRQ[8]; want != have {
Expand Down
2 changes: 1 addition & 1 deletion testdata/fixtures.ttar

Large diffs are not rendered by default.

0 comments on commit dbd0bc5

Please sign in to comment.