Sam Fredrickson
270534c0d5
All checks were successful
Build & Test / Main (push) Successful in 59s
Also, add a quick-and-dirty model for displaying basic performance stats, currently just the number of calls to the root Update() and View() methods.
43 lines
626 B
Go
43 lines
626 B
Go
package perf
|
|
|
|
import (
|
|
"fmt"
|
|
"sync/atomic"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
type Model struct {
|
|
updates *atomic.Int64
|
|
views *atomic.Int64
|
|
}
|
|
|
|
func New() (m Model) {
|
|
m.updates = new(atomic.Int64)
|
|
m.views = new(atomic.Int64)
|
|
return
|
|
}
|
|
|
|
func (m Model) Init() tea.Cmd {
|
|
return nil
|
|
}
|
|
|
|
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
|
return m, nil
|
|
}
|
|
|
|
func (m Model) View() string {
|
|
updates := m.updates.Load()
|
|
views := m.views.Load()
|
|
s := fmt.Sprintf("updates: %d\tviews: %d", updates, views)
|
|
return s
|
|
}
|
|
|
|
func (m Model) AddUpdate() {
|
|
m.updates.Add(1)
|
|
}
|
|
|
|
func (m Model) AddView() {
|
|
m.views.Add(1)
|
|
}
|