Skip to content

Commit

Permalink
More graceful exit handling when calling top processes
Browse files Browse the repository at this point in the history
  • Loading branch information
bakks committed Jan 16, 2023
1 parent cf17a33 commit 9e50f7d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ type PoptopConfig struct {
TileWindows bool
}

// Kong CLI parser option configuration
var cli struct {
Help bool `short:"h" help:"Show help information"`
RedrawInterval int `short:"r" help:"Redraw interval in milliseconds (how often to repaint charts)" default:"500"`
Expand Down
8 changes: 4 additions & 4 deletions top.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func newTopBoxes(ctx context.Context, config *PoptopConfig) ([]container.Option,
interval := config.SampleInterval * 4

go periodic(ctx, interval, func() error {
topCpu, topMem := topProcesses(ctx, config)
topCpu, topMem, err := topProcesses(ctx, config)
if err != nil {
return err
}
Expand Down Expand Up @@ -133,10 +133,10 @@ func (this *PsProcess) String() string {
}

// Create CPU and Memory top lists using output from a shared ps command execution.
func topProcesses(ctx context.Context, config *PoptopConfig) ([]*PsProcess, []*PsProcess) {
func topProcesses(ctx context.Context, config *PoptopConfig) ([]*PsProcess, []*PsProcess, error) {
procs, err := GetPsProcesses(ctx)
if err != nil {
panic(err)
return nil, nil, err
}

sort.Slice(procs, func(i, j int) bool {
Expand All @@ -153,5 +153,5 @@ func topProcesses(ctx context.Context, config *PoptopConfig) ([]*PsProcess, []*P
procsByMem := make([]*PsProcess, min(config.TopRowsShown, len(procs)))
copy(procsByMem, procs)

return procsByCpu, procsByMem
return procsByCpu, procsByMem, nil
}

0 comments on commit 9e50f7d

Please sign in to comment.