Skip to content

Commit 4b2218e

Browse files
authored
Increase Stat() buffer size (prometheus#547)
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: prometheus#546 Signed-off-by: SuperQ <[email protected]>
1 parent 46aea31 commit 4b2218e

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

stat.go

+4
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ func parseStat(r io.Reader, fileName string) (Stat, error) {
187187
err error
188188
)
189189

190+
// Increase default scanner buffer to handle very long `intr` lines.
191+
buf := make([]byte, 0, 8*1024)
192+
scanner.Buffer(buf, 1024*1024)
193+
190194
for scanner.Scan() {
191195
line := scanner.Text()
192196
parts := strings.Fields(scanner.Text())

stat_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestStat(t *testing.T) {
3030
}
3131

3232
// intr
33-
if want, have := uint64(8885917), s.IRQTotal; want != have {
33+
if want, have := uint64(73777505), s.IRQTotal; want != have {
3434
t.Errorf("want irq/total %d, have %d", want, have)
3535
}
3636
if want, have := uint64(1), s.IRQ[8]; want != have {

testdata/fixtures.ttar

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)