Skip to content

Commit

Permalink
Revert "perf: benchmark improve sig GetMetadata"
Browse files Browse the repository at this point in the history
This reverts commit 330a34e.
  • Loading branch information
rscampos committed Sep 23, 2024
1 parent 1571d31 commit 60d4176
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 196 deletions.
53 changes: 0 additions & 53 deletions pkg/signatures/benchmark/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/stretchr/testify/require"

"github.com/aquasecurity/tracee/pkg/events"
"github.com/aquasecurity/tracee/pkg/signatures/benchmark/signature/golang"
"github.com/aquasecurity/tracee/pkg/signatures/benchmark/signature/rego"
"github.com/aquasecurity/tracee/pkg/signatures/engine"
Expand Down Expand Up @@ -231,58 +230,6 @@ func BenchmarkEngineWithNSignatures(b *testing.B) {
}
}

func BenchmarkEngineMultipleMethodsGetMetadata(b *testing.B) {
benches := []struct {
name string
sigFuncs []func() (detect.Signature, error)
Enabled bool
}{
{
name: "Performance sig GetMetadata() - static",
sigFuncs: []func() (detect.Signature, error){golang.NewPerformanceStatic},
},
}

for _, bc := range benches {
b.Run(bc.name, func(b *testing.B) {
var sigs []detect.Signature
for _, sig := range bc.sigFuncs {
s, _ := sig()
sigs = append(sigs, s)
}

for i := 0; i < b.N; i++ {
// Produce events without timing it
b.StopTimer()
inputs := ProduceEventsInMemory(inputEventsCount)
output := make(chan *detect.Finding, inputEventsCount*len(sigs))

config := engine.Config{
Signatures: sigs,
Enabled: true,
SigNameToEventID: allocateEventIdsForSigs(events.StartSignatureID, sigs),
ShouldDispatchEvent: func(int32) bool { return true },
}

e, err := engine.NewEngine(config, inputs, output)
require.NoError(b, err, "constructing engine")

err = e.Init()
require.NoError(b, err, "initializing engine")
b.StartTimer()

// Start signatures engine and wait until all events are processed
e.Start(waitForEventsProcessed(inputs.Tracee))

b.StopTimer()

// Set engine to nil to help with garbage collection
e = nil
runtime.GC()
}
})
}
}
func waitForEventsProcessed(eventsCh chan protocol.Event) context.Context {
ctx, cancel := context.WithCancel(context.Background())
go func() {
Expand Down
20 changes: 0 additions & 20 deletions pkg/signatures/benchmark/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import (
_ "embed"
"math/rand"

"github.com/aquasecurity/tracee/pkg/events"
"github.com/aquasecurity/tracee/pkg/logger"
"github.com/aquasecurity/tracee/pkg/signatures/engine"
"github.com/aquasecurity/tracee/types/detect"
"github.com/aquasecurity/tracee/types/protocol"
"github.com/aquasecurity/tracee/types/trace"
)
Expand Down Expand Up @@ -174,20 +171,3 @@ func ProduceEventsInMemoryRandom(n int, seed ...trace.Event) engine.EventSources
Tracee: eventsCh,
}
}

func allocateEventIdsForSigs(startId events.ID, sigs []detect.Signature) map[string]int32 {
namesToIds := make(map[string]int32)
newEventDefID := startId
// First allocate event IDs to all signatures
for _, s := range sigs {
m, err := s.GetMetadata()
if err != nil {
logger.Warnw("Failed to allocate id for signature", "error", err)
continue
}

namesToIds[m.EventName] = int32(newEventDefID)
newEventDefID++
}
return namesToIds
}
123 changes: 0 additions & 123 deletions pkg/signatures/benchmark/signature/golang/performance_static.go

This file was deleted.

0 comments on commit 60d4176

Please sign in to comment.