Skip to content

Commit

Permalink
Add routine statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
becheran committed Aug 18, 2022
1 parent 94a5d28 commit a47d657
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ type UI struct {
legend *widgets.Paragraph
help *widgets.Paragraph

grid *termui.Grid
filtered bool
origData []model.Goroutine
filteredData []model.Goroutine
grid *termui.Grid
filtered bool
origData []model.Goroutine
filteredData []model.Goroutine
minGoRoutines int
maxGoRoutines int
avgGoRoutines float64
}

// NewUI creates a new console user interface
Expand All @@ -53,7 +56,6 @@ func NewUI() *UI {
filter.PaddingBottom = padding

plot := widgets.NewPlot()
plot.Title = "History # goroutines"
plot.Data = make([][]float64, 1)
plot.Data[0] = make([]float64, 2, keepRoutineHist)
plot.AxesColor = termui.ColorWhite
Expand Down Expand Up @@ -154,9 +156,16 @@ func NewUI() *UI {
),
)

ui.updatePlotTitle()

return &ui
}

func (ui *UI) updatePlotTitle() {
ui.routineHist.Title = fmt.Sprintf("History # goroutines (Min: %d Avg: %0.2f Max: %d)",
ui.minGoRoutines, ui.avgGoRoutines, ui.maxGoRoutines)
}

func (ui *UI) updateStatus() {
typeCount := make(map[string]float64)
for i := 0; i < len(ui.origData); i++ {
Expand Down Expand Up @@ -301,6 +310,18 @@ func (ui *UI) Run(terminate chan<- error, routinesUpdate <-chan []model.Goroutin
}
ui.routineHist.Data[0] = append(ui.routineHist.Data[0], float64(len(routines)))

if ui.minGoRoutines == 0 || len(routines) < ui.minGoRoutines {
ui.minGoRoutines = len(routines)
}
if len(routines) > ui.maxGoRoutines {
ui.maxGoRoutines = len(routines)
}
if ui.avgGoRoutines > 0 {
ui.avgGoRoutines = (ui.avgGoRoutines + float64(len(routines))) / 2.0
} else {
ui.avgGoRoutines = float64(len(routines))
}
ui.updatePlotTitle()
ui.updateList()
ui.updateStatus()
}
Expand Down

0 comments on commit a47d657

Please sign in to comment.