Skip to content

Commit

Permalink
chore: Show detaching progress always
Browse files Browse the repository at this point in the history
Fix the case that the detaching progress bar does not show when
--output-limit-lines.

Signed-off-by: Leon Hwang <hffilwlqm@gmail.com>
  • Loading branch information
Asphaltt authored and brb committed Mar 4, 2024
1 parent 4ee0356 commit 47a823e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
24 changes: 8 additions & 16 deletions internal/pwru/kprobe.go
Expand Up @@ -115,44 +115,36 @@ func AttachKprobes(ctx context.Context, bar *pb.ProgressBar, kps []Kprobe, batch
}

// DetachKprobes detaches kprobes concurrently.
func DetachKprobes(links []link.Link, showProgressBar bool, batch uint) {
func DetachKprobes(links []link.Link, batch uint) {
log.Println("Detaching kprobes...")

if batch < 2 {
bar := pb.StartNew(len(links))
defer bar.Finish()

if batch == 0 || batch >= uint(len(links)) {
for _, l := range links {
_ = l.Close()
bar.Increment()
}

return
}

var errg errgroup.Group
var bar *pb.ProgressBar

if showProgressBar {
bar = pb.StartNew(len(links))
defer bar.Finish()
}
increment := func() {
if showProgressBar {
bar.Increment()
}
}

var i uint
for i = 0; i+batch < uint(len(links)); i += batch {
l := links[i : i+batch]
errg.Go(func() error {
for _, l := range l {
_ = l.Close()
increment()
bar.Increment()
}
return nil
})
}
for ; i < uint(len(links)); i++ {
_ = links[i].Close()
increment()
bar.Increment()
}

_ = errg.Wait()
Expand Down
12 changes: 2 additions & 10 deletions main.go
Expand Up @@ -199,19 +199,11 @@ func main() {

var kprobes []link.Link
defer func() {
var showProgressBar bool
select {
case <-ctx.Done():
showProgressBar = true

default:
}

batch := uint(1)
batch := uint(0)
if !useKprobeMulti {
batch = flags.FilterKprobeBatch
}
pwru.DetachKprobes(kprobes, showProgressBar, batch)
pwru.DetachKprobes(kprobes, batch)
}()

msg := "kprobe"
Expand Down

0 comments on commit 47a823e

Please sign in to comment.