Commit 2636b033 authored by liming6's avatar liming6
Browse files

fix 修改背景信息更新频率

parent b87220dd
......@@ -62,7 +62,7 @@ func Init() error {
if err == nil {
stopCtx, cancelFunc = context.WithCancel(context.Background())
go func() {
ticker := time.NewTicker(time.Second * 20)
ticker := time.NewTicker(time.Second * 8)
for {
select {
case <-ticker.C:
......
......@@ -100,7 +100,8 @@ func (m *ModelDCUInfo) View() string {
borderStr = LowLeightStyle.Render(borderStr)
}
infos := make([]string, 0)
for i := range 64 {
for i := range 32 {
qinfo, haveq := qmap[i]
sinfo, haves := smap[i]
if !(haveq || haves) {
......
......@@ -186,11 +186,10 @@ func (m *ModelProcessDetail) handleModelMsg(msg *ModelMsg) {
m.maxValThreshold[0] = float64(int(math.Ceil(cpu))/50)*50 + 50
}
m.CPU = NewTimeChart(m.w[0], m.h[0], 0, m.maxValThreshold[0], []lipgloss.Color{lipgloss.Color("#00fffbff")})
m.CPU.PutPoint(m.cpuPoints.Values())
m.CPU.Update(MyTimeChartMsg{Reset: false, Points: m.cpuPoints.Values()})
} else {
m.CPU.Update(MyTimeChartMsg{Reset: false, Points: []tchart.TimePoint{{Time: msg.t, Value: cpu}}})
}
}
func (m *ModelProcessDetail) View() string {
......
......@@ -175,7 +175,7 @@ func (m *MyTimeChart) PutPoint(points []tchart.TimePoint) {
func (m *MyTimeChart) ResetPutPoint(points []tchart.TimePoint) {
// 清除原有的点
m.lockPoints.Lock()
m.points = nil
m.points = m.points[:0]
// 排序输入数据
sort.Slice(points, func(i, j int) bool {
......@@ -199,7 +199,6 @@ func (m *MyTimeChart) ResetPutPoint(points []tchart.TimePoint) {
m.points = append(make([]tchart.TimePoint, 0, len(points[index:])), points[index:]...)
} else if first.After(threshold) {
// 需要补充数据
m.points = make([]tchart.TimePoint, 0, len(points)+2*m.width+1)
max := m.width * 2
for i := 1; i < max; i++ {
ta := now.Add(time.Second * time.Duration(-i))
......
......@@ -3,6 +3,8 @@ package tui
import (
"fmt"
"get-container/cmd/hytop/backend"
"get-container/cmd/hytop/tchart"
"math/rand/v2"
"testing"
"time"
......@@ -75,3 +77,17 @@ func TestSysloadInit(t *testing.T) {
t.Logf("%d ms", tt.Sub(ts[0]).Milliseconds())
}
}
func TestTimeChart(t *testing.T) {
chart1 := NewTimeChart(100, 20, 0, 100, nil)
chart2 := NewTimeChart(100, 20, 0, 100, nil)
now := time.Now()
points := make([]tchart.TimePoint, 0, 200)
for i := range 200 {
points = append(points, tchart.TimePoint{Time: now.Add(time.Duration(-i) * time.Second), Value: rand.Float64() * 100})
}
chart1.PutPoint(points)
t.Logf("\n%s", chart1.View())
chart2.PutPoint(points)
t.Logf("\n%s", chart2.View())
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment