mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-24 08:01:03 +00:00
reduce cpu usage caused by tickers
This commit is contained in:
parent
012f8d6e08
commit
cea67bc570
4 changed files with 28 additions and 19 deletions
|
|
@ -107,6 +107,7 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Translat
|
||||||
|
|
||||||
// MonitorContainerStats is a function
|
// MonitorContainerStats is a function
|
||||||
func (c *DockerCommand) MonitorContainerStats() {
|
func (c *DockerCommand) MonitorContainerStats() {
|
||||||
|
// TODO: pass in a stop channel to these so we don't restart every time we come back from a subprocess
|
||||||
go c.MonitorCLIContainerStats()
|
go c.MonitorCLIContainerStats()
|
||||||
go c.MonitorClientContainerStats()
|
go c.MonitorClientContainerStats()
|
||||||
}
|
}
|
||||||
|
|
@ -150,7 +151,9 @@ func (c *DockerCommand) MonitorCLIContainerStats() {
|
||||||
func (c *DockerCommand) MonitorClientContainerStats() {
|
func (c *DockerCommand) MonitorClientContainerStats() {
|
||||||
// periodically loop through running containers and see if we need to create a monitor goroutine for any
|
// periodically loop through running containers and see if we need to create a monitor goroutine for any
|
||||||
// every second we check if we need to spawn a new goroutine
|
// every second we check if we need to spawn a new goroutine
|
||||||
for range time.Tick(time.Second) {
|
ticker := time.NewTicker(time.Second)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for range ticker.C {
|
||||||
for _, container := range c.Containers {
|
for _, container := range c.Containers {
|
||||||
if !container.MonitoringStats {
|
if !container.MonitoringStats {
|
||||||
go c.createClientStatMonitor(container)
|
go c.createClientStatMonitor(container)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package gui
|
package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/utils"
|
"github.com/jesseduffield/lazydocker/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
@ -49,15 +51,25 @@ func (m *statusManager) getStatusString() string {
|
||||||
// WithWaitingStatus wraps a function and shows a waiting status while the function is still executing
|
// WithWaitingStatus wraps a function and shows a waiting status while the function is still executing
|
||||||
func (gui *Gui) WithWaitingStatus(name string, f func() error) error {
|
func (gui *Gui) WithWaitingStatus(name string, f func() error) error {
|
||||||
go func() {
|
go func() {
|
||||||
gui.g.Update(func(g *gocui.Gui) error {
|
gui.statusManager.addWaitingStatus(name)
|
||||||
gui.statusManager.addWaitingStatus(name)
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
defer gui.g.Update(func(g *gocui.Gui) error {
|
defer func() {
|
||||||
gui.statusManager.removeStatus(name)
|
gui.statusManager.removeStatus(name)
|
||||||
return nil
|
}()
|
||||||
})
|
|
||||||
|
go func() {
|
||||||
|
ticker := time.NewTicker(time.Millisecond * 50)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for range ticker.C {
|
||||||
|
appStatus := gui.statusManager.getStatusString()
|
||||||
|
if appStatus == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := gui.renderString(gui.g, "appStatus", appStatus); err != nil {
|
||||||
|
gui.Log.Warn(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if err := f(); err != nil {
|
if err := f(); err != nil {
|
||||||
gui.g.Update(func(g *gocui.Gui) error {
|
gui.g.Update(func(g *gocui.Gui) error {
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ func (gui *Gui) prepareConfirmationPanel(currentView *gocui.View, title, prompt
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
confirmationView.HasLoader = hasLoader
|
confirmationView.HasLoader = hasLoader
|
||||||
|
gui.g.StartTicking()
|
||||||
confirmationView.Title = title
|
confirmationView.Title = title
|
||||||
confirmationView.Wrap = true
|
confirmationView.Wrap = true
|
||||||
confirmationView.FgColor = gocui.ColorWhite
|
confirmationView.FgColor = gocui.ColorWhite
|
||||||
|
|
|
||||||
|
|
@ -214,14 +214,6 @@ func (gui *Gui) promptAnonymousReporting() error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) renderAppStatus() error {
|
|
||||||
appStatus := gui.statusManager.getStatusString()
|
|
||||||
if appStatus != "" {
|
|
||||||
return gui.renderString(gui.g, "appStatus", appStatus)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) renderGlobalOptions() error {
|
func (gui *Gui) renderGlobalOptions() error {
|
||||||
return gui.renderOptionsMap(map[string]string{
|
return gui.renderOptionsMap(map[string]string{
|
||||||
"PgUp/PgDn": gui.Tr.Scroll,
|
"PgUp/PgDn": gui.Tr.Scroll,
|
||||||
|
|
@ -236,7 +228,9 @@ func (gui *Gui) goEvery(interval time.Duration, function func() error) {
|
||||||
currentSessionIndex := gui.State.SessionIndex
|
currentSessionIndex := gui.State.SessionIndex
|
||||||
_ = function() // time.Tick doesn't run immediately so we'll do that here // TODO: maybe change
|
_ = function() // time.Tick doesn't run immediately so we'll do that here // TODO: maybe change
|
||||||
go func() {
|
go func() {
|
||||||
for range time.Tick(interval) {
|
ticker := time.NewTicker(interval)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for range ticker.C {
|
||||||
if gui.State.SessionIndex > currentSessionIndex {
|
if gui.State.SessionIndex > currentSessionIndex {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -276,7 +270,6 @@ func (gui *Gui) Run() error {
|
||||||
dockerRefreshInterval := gui.Config.UserConfig.Update.DockerRefreshInterval
|
dockerRefreshInterval := gui.Config.UserConfig.Update.DockerRefreshInterval
|
||||||
go func() {
|
go func() {
|
||||||
gui.waitForIntro.Wait()
|
gui.waitForIntro.Wait()
|
||||||
gui.goEvery(time.Millisecond*50, gui.renderAppStatus)
|
|
||||||
gui.goEvery(time.Millisecond*30, gui.reRenderMain)
|
gui.goEvery(time.Millisecond*30, gui.reRenderMain)
|
||||||
gui.goEvery(dockerRefreshInterval, gui.refreshProject)
|
gui.goEvery(dockerRefreshInterval, gui.refreshProject)
|
||||||
gui.goEvery(dockerRefreshInterval, gui.refreshContainersAndServices)
|
gui.goEvery(dockerRefreshInterval, gui.refreshContainersAndServices)
|
||||||
|
|
@ -285,7 +278,7 @@ func (gui *Gui) Run() error {
|
||||||
gui.goEvery(time.Millisecond*1000, gui.checkForContextChange)
|
gui.goEvery(time.Millisecond*1000, gui.checkForContextChange)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go gui.DockerCommand.MonitorContainerStats()
|
gui.DockerCommand.MonitorContainerStats()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for err := range gui.ErrorChan {
|
for err := range gui.ErrorChan {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue