Skip to content

feat(profiler): follow forked process trees#386

Open
btlqql wants to merge 2 commits into
ccfos:mainfrom
btlqql:agent/fork-process-tracking
Open

feat(profiler): follow forked process trees#386
btlqql wants to merge 2 commits into
ccfos:mainfrom
btlqql:agent/fork-process-tracking

Conversation

@btlqql

@btlqql btlqql commented Jul 18, 2026

Copy link
Copy Markdown

Summary

Resolves #335 by adding opt-in automatic process-tree tracking to the native profiler.

  • track forked and cloned descendants through sched_process_fork, sched_process_exec, and sched_process_exit
  • inherit the root profiler's tracking eligibility for descendants
  • keep surviving descendants traceable after parent/root exit, including non-leader thread exec PID migration
  • add configurable process limits, global fork-rate protection, dynamic BPF map sizing, cleanup, and coverage telemetry
  • wire the feature into native CPU and all native memory modes
  • add CLI validation, bilingual documentation, and a deterministic lifecycle reference model with concurrency tests

Issue acceptance coverage

  • Fork/clone tracking: descendants are added automatically from scheduler lifecycle events.
  • Context inheritance: tracked descendants use the same native profiler configuration and filters as the root target.
  • Batch-creation stability: bounded maps, reservation-based capacity enforcement, and fork-rate protection prevent unbounded growth during fork storms.
  • Lifecycle cleanup: exit events remove process state; exec migration handles Linux PID changes without leaving stale keys.
  • Observability: final coverage statistics report accepted, rejected, active, exited, limited, and migration counts.

Compatibility and safety

  • preserves Linux 4.18 and BPF -mcpu=v1 compatibility by using discarded-result legacy XADD operations
  • enforces the configured process cap through reservation plus the kernel map capacity
  • uses non-preallocated PID storage and shrinks the disabled map to one entry
  • detaches programs before reading final coverage statistics

Validation

  • go test -count=10 ./internal/profiler/forktrack
  • go vet ./internal/profiler/forktrack
  • Linux cross-compilation of tests for ./internal/bpf, ./cmd/profiler/provider, and ./cmd/profiler
  • git diff --check

Runtime eBPF attachment was not executed locally because the development host is Windows; Linux compilation and static BPF compatibility checks pass.

Preserve descendant tracking while adopting the current thread-group filter
semantics and native profiler constant loader.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[功能建议]: Fork 进程自动跟踪

2 participants