Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proctree refactor #4362

Closed
wants to merge 5 commits into from
Closed

Conversation

geyslan
Copy link
Member

@geyslan geyslan commented Oct 21, 2024

1. Explain what the PR does

2. Explain how to test it

3. Other comments

Running tool: /home/gg/.goenv/versions/1.22.4/bin/go test -benchmem
-run=^$ -tags ebpf -bench ^Benchmark_newProcStatus$
github.com/aquasecurity/tracee/pkg/utils/proc -benchtime=10000000x

goos: linux
goarch: amd64
pkg: github.com/aquasecurity/tracee/pkg/utils/proc
cpu: AMD Ryzen 9 7950X 16-Core Processor
Benchmark_newProcStatus-32 10000000  13203 ns/op  17851 B/op  137 allocs/op
PASS
ok  	github.com/aquasecurity/tracee/pkg/utils/proc	132.033s
This short-circuits the status parsing by avoiding fully parsing all
status fields. It also makes ProcStatus a concrete type that contains
only the fields we are interested in, what reduces the memory footprint.

To reduce the size of the function it now uses a map to lookup the field
handler functions.

---

Running tool: /home/gg/.goenv/versions/1.22.4/bin/go test -benchmem
-run=^$ -tags ebpf -bench ^Benchmark_newProcStatus$
github.com/aquasecurity/tracee/pkg/utils/proc -benchtime=10000000x

goos: linux
goarch: amd64
pkg: github.com/aquasecurity/tracee/pkg/utils/proc
cpu: AMD Ryzen 9 7950X 16-Core Processor
Benchmark_newProcStatus-32 10000000  5551 ns/op  5136 B/op  29 allocs/op
PASS
ok  	github.com/aquasecurity/tracee/pkg/utils/proc	55.516s

---

| Metric                   | Old Bench. | New Bench. | Improvement (%) |
|--------------------------|------------|------------|-----------------|
| Execution Time (ns/op)   | 13203      | 5551       | ~57.9% faster   |
| Memory Allocations (B/op)| 17851      | 5136       | ~71.2% reduction|
| Allocations (allocs/op)  | 137        | 29         | ~78.8% reduction|
| Total Time (seconds)     | 132.033    | 55.516     | ~57.9% faster   |
Running tool: /home/gg/.goenv/versions/1.22.4/bin/go test -benchmem
-run=^$ -tags ebpf -bench ^Benchmark_newProcStat$
github.com/aquasecurity/tracee/pkg/utils/proc -benchtime=10000000x

goos: linux
goarch: amd64
pkg: github.com/aquasecurity/tracee/pkg/utils/proc
cpu: AMD Ryzen 9 7950X 16-Core Processor
Benchmark_newProcStat-32 10000000  14336 ns/op  2976 B/op   45 allocs/op
PASS
ok  	github.com/aquasecurity/tracee/pkg/utils/proc	143.369s
This short-circuits the stat parsing by avoiding fully parsing all
stat fields. It also removed ProcStat unused fields leaving the
unique we are interested in, what reduces the memory footprint.

To reduce the size of the function it now uses a array to lookup the
field handler functions.

---

Running tool: /home/gg/.goenv/versions/1.22.4/bin/go test -benchmem
-run=^$ -tags ebpf -bench ^Benchmark_newProcStat$
github.com/aquasecurity/tracee/pkg/utils/proc -benchtime=10000000x

goos: linux
goarch: amd64
pkg: github.com/aquasecurity/tracee/pkg/utils/proc
cpu: AMD Ryzen 9 7950X 16-Core Processor
Benchmark_newProcStat-32 10000000  5591 ns/op  2657 B/op  13 allocs/op
PASS
ok  	github.com/aquasecurity/tracee/pkg/utils/proc	55.915s

---

| Metric                  - | Old Bench. | New Bench.| Improvement (%) |
|---------------------------|------------|-----------|-----------------|
| Execution Time (ns/op)    | 14336      | 5591      | ~61.0% faster   |
| Memory Allocations (B/op) | 2976       | 2657      | ~10.7% reduction|
| Allocations (allocs/op)   | 45         | 13        | ~71.1% reduction|
| Total Time (seconds)      | 143.369    | 55.915    | ~61.0% faster   |
The field started_time fetched from /proc stat file and passed as ticks
to ClockTicksToNsSinceBootTime() is an uint64.
@geyslan
Copy link
Member Author

geyslan commented Oct 28, 2024

This was tackled by #4364.

@geyslan geyslan closed this Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant