-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dead processes from the process cache through handle exit even…
…ts (#79)
- Loading branch information
Showing
12 changed files
with
289 additions
and
51 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
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
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,52 @@ | ||
package consumer | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/mozillazg/ptcpdump/bpf" | ||
"github.com/mozillazg/ptcpdump/internal/metadata" | ||
) | ||
|
||
type ExitEventConsumer struct { | ||
pcache *metadata.ProcessCache | ||
workerNumber int | ||
} | ||
|
||
func NewExitEventConsumer(pcache *metadata.ProcessCache, workerNumber int) *ExitEventConsumer { | ||
return &ExitEventConsumer{ | ||
pcache: pcache, | ||
workerNumber: workerNumber, | ||
} | ||
} | ||
|
||
func (c *ExitEventConsumer) Start(ctx context.Context, ch <-chan bpf.BpfExitEventT) { | ||
wg := sync.WaitGroup{} | ||
for i := 0; i < c.workerNumber; i++ { | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
c.worker(ctx, ch) | ||
}() | ||
} | ||
wg.Wait() | ||
} | ||
|
||
func (c *ExitEventConsumer) worker(ctx context.Context, ch <-chan bpf.BpfExitEventT) { | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case et := <-ch: | ||
c.handleExitEvent(et) | ||
} | ||
} | ||
} | ||
|
||
func (c *ExitEventConsumer) handleExitEvent(et bpf.BpfExitEventT) { | ||
c.pcache.MarkDead(int(et.Pid)) | ||
} | ||
|
||
func (c *ExitEventConsumer) Stop() { | ||
|
||
} |
Oops, something went wrong.