Skip to content

Commit

Permalink
Actually commit the example
Browse files Browse the repository at this point in the history
Signed-off-by: Alun Evans <[email protected]>
  • Loading branch information
alxn committed Nov 3, 2023
1 parent 89805d9 commit 29a6cd0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions examples/kprobe_percpu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/cilium/ebpf"
"github.com/cilium/ebpf/internal"
"github.com/cilium/ebpf/link"
"github.com/cilium/ebpf/rlimit"
)
Expand Down Expand Up @@ -51,18 +52,22 @@ func main() {

log.Println("Waiting for events..")

possibleCPUs, err := internal.PossibleCPUs()
if err != nil {
log.Fatalf("possible cpus: %v", err)
}
batch := true
for range ticker.C {
var all_cpu_value []uint64
if batch {
var nextKeyOut uint32
lookupKeys := make([]uint32, 2)
lookupValues := make([][]uint64, 2)
lookupValues := make([]uint64, 2*possibleCPUs)
count, err := objs.KprobeMap.BatchLookup(nil, &nextKeyOut, lookupKeys, lookupValues, &ebpf.BatchOptions{})
if count != 1 {
log.Fatalf("batch reading map: %v", err)
}
all_cpu_value = lookupValues[0]
all_cpu_value = lookupValues[0:possibleCPUs]
} else {
if err := objs.KprobeMap.Lookup(mapKey, &all_cpu_value); err != nil {
log.Fatalf("reading map: %v", err)
Expand Down

0 comments on commit 29a6cd0

Please sign in to comment.