Skip to content

Commit b8dc0ee

Browse files
authored
program: add RecursionMisses to access ProgramInfo recursion misses counter
RecursionMisses is increased by one whenever a program is not executed due to recursion. This value is always measured on supported kernels, regardless of statistics being enabled or not. Signed-off-by: Lorenz Bauer <[email protected]> Signed-off-by: Jiri Olsa <[email protected]>
1 parent f82b29b commit b8dc0ee

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

info.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ type programStats struct {
8383
runtime time.Duration
8484
// Total number of times the program was called.
8585
runCount uint64
86+
// Total number of times the programm was NOT called.
87+
// Added in commit 9ed9e9ba2337 ("bpf: Count the number of times recursion was prevented").
88+
recursionMisses uint64
8689
}
8790

8891
// ProgramInfo describes a program.
@@ -125,8 +128,9 @@ func newProgramInfoFromFd(fd *sys.FD) (*ProgramInfo, error) {
125128
Name: unix.ByteSliceToString(info.Name[:]),
126129
btf: btf.ID(info.BtfId),
127130
stats: &programStats{
128-
runtime: time.Duration(info.RunTimeNs),
129-
runCount: info.RunCnt,
131+
runtime: time.Duration(info.RunTimeNs),
132+
runCount: info.RunCnt,
133+
recursionMisses: info.RecursionMisses,
130134
},
131135
}
132136

@@ -259,6 +263,16 @@ func (pi *ProgramInfo) Runtime() (time.Duration, bool) {
259263
return time.Duration(0), false
260264
}
261265

266+
// RecursionMisses returns the total number of times the program was NOT called.
267+
// This can happen when another bpf program is already running on the cpu, which
268+
// is likely to happen for example when you interrupt bpf program execution.
269+
func (pi *ProgramInfo) RecursionMisses() (uint64, bool) {
270+
if pi.stats != nil {
271+
return pi.stats.recursionMisses, true
272+
}
273+
return 0, false
274+
}
275+
262276
// Instructions returns the 'xlated' instruction stream of the program
263277
// after it has been verified and rewritten by the kernel. These instructions
264278
// cannot be loaded back into the kernel as-is, this is mainly used for

info_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ func TestStats(t *testing.T) {
262262
t.Errorf("expected a runtime of 0ns but got %v", rt)
263263
}
264264

265+
rm, ok := pi.RecursionMisses()
266+
if !ok {
267+
t.Errorf("expected recursion misses info to be available")
268+
}
269+
if rm != 0 {
270+
t.Errorf("expected a recursion misses of 0 but got %v", rm)
271+
}
272+
265273
if err := testStats(prog); err != nil {
266274
t.Error(err)
267275
}

0 commit comments

Comments
 (0)