Skip to content

Commit 3e5ff5a

Browse files
committed
Use the newer filepath.WalkDir function
1 parent 164dd5a commit 3e5ff5a

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

decoder/cgroup.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package decoder
22

33
import (
44
"fmt"
5+
"io/fs"
56
"log"
6-
"os"
77
"path/filepath"
88
"strconv"
99

@@ -48,7 +48,7 @@ func (c *CGroup) refreshCache() error {
4848

4949
cgroupPath := "/sys/fs/cgroup"
5050

51-
return filepath.Walk(cgroupPath, func(path string, info os.FileInfo, err error) error {
51+
return filepath.WalkDir(cgroupPath, func(path string, info fs.DirEntry, err error) error {
5252
if err != nil {
5353
return err
5454
}

decoder/cgroup_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,15 @@ func TestCgroupDecoder(t *testing.T) {
3838
}
3939
}
4040
}
41+
42+
func BenchmarkCgroupRefresh(b *testing.B) {
43+
d := &CGroup{cache: map[uint64][]byte{}}
44+
b.ResetTimer()
45+
46+
for i := 0; i < b.N; i++ {
47+
err := d.refreshCache()
48+
if err != nil {
49+
b.Errorf("Failed to refresh cgroup cache: %s", err)
50+
}
51+
}
52+
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/cloudflare/ebpf_exporter
22

3-
go 1.14
3+
go 1.16
44

55
require (
66
github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15 // indirect

0 commit comments

Comments
 (0)