-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add BPFPerfEventWrites metric (DEBUG)
Enabled only when the build with DEBUG=1. BPFPerfEventWrites counts the number of events processed by the eBPF programs and written to the perf event buffer. It is incremented right before the event is written to the perf buffer, making it possible to measure even if the event is lost. This metric can be used to monitor the performance of individual eBPF events and to detect potential bottlenecks.
- Loading branch information
Showing
7 changed files
with
157 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package ebpf | ||
|
||
import ( | ||
"context" | ||
"encoding/binary" | ||
"time" | ||
"unsafe" | ||
|
||
"github.com/aquasecurity/tracee/pkg/counter" | ||
"github.com/aquasecurity/tracee/pkg/events" | ||
"github.com/aquasecurity/tracee/pkg/logger" | ||
) | ||
|
||
// countPerfEventWrites counts the number of times each event is attempted | ||
// to be written to the perf buffer. | ||
func (t *Tracee) countPerfEventWrites(ctx context.Context) { | ||
logger.Debugw("Starting countPerfEventWrites goroutine") | ||
defer logger.Debugw("Stopped countPerfEventWrites goroutine") | ||
|
||
evtsCountsBPFMap, err := t.bpfModule.GetMap("event_counts") | ||
if err != nil { | ||
logger.Errorw("Failed to get event_counts map", "error", err) | ||
return | ||
} | ||
|
||
for _, id := range t.policyManager.EventsSelected() { | ||
key := uint32(id) | ||
value := uint64(0) | ||
err := evtsCountsBPFMap.Update(unsafe.Pointer(&key), unsafe.Pointer(&value)) | ||
if err != nil { | ||
logger.Errorw("Failed to update event_counts map", "error", err) | ||
} | ||
} | ||
|
||
total := counter.NewCounter(0) | ||
evtsCounts := make(map[uint32]uint64) | ||
ticker := time.NewTicker(10 * time.Second) | ||
defer ticker.Stop() | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case <-ticker.C: | ||
iter := evtsCountsBPFMap.Iterator() | ||
for iter.Next() { | ||
key := binary.LittleEndian.Uint32(iter.Key()) | ||
value, err := evtsCountsBPFMap.GetValue(unsafe.Pointer(&key)) | ||
if err != nil { | ||
logger.Errorw("Failed to get value from event_counts map", "error", err) | ||
continue | ||
} | ||
|
||
evtsCounts[key] = binary.LittleEndian.Uint64(value) | ||
} | ||
|
||
total.Set(0) | ||
for k, v := range evtsCounts { | ||
if v == 0 { | ||
continue | ||
} | ||
err := total.Increment(v) | ||
if err != nil { | ||
logger.Errorw("Failed to increment total counter", "error", err) | ||
} | ||
|
||
logger.Debugw("Event sending attempts", | ||
"event", events.Core.GetDefinitionByID(events.ID(k)).GetName(), | ||
"count", v, | ||
) | ||
} | ||
|
||
logger.Debugw("Event sending attempts", "total", total.Get()) | ||
t.stats.BPFPerfEventWrites.Set(total.Get()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
package version | ||
|
||
var version string | ||
var ( | ||
version string | ||
debug string | ||
) | ||
|
||
func GetVersion() string { | ||
return version | ||
} | ||
|
||
func DebugBuild() bool { | ||
return debug == "1" | ||
} |