Skip to content

Commit

Permalink
Memory hasbeen fixed
Browse files Browse the repository at this point in the history
Signed-off-by: NavinShrinivas <[email protected]>

Along with adding rolling buffers for CPU graph
  • Loading branch information
NavinShrinivas committed Nov 14, 2022
1 parent 7a56832 commit f6288ee
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 18 deletions.
5 changes: 5 additions & 0 deletions SysPerfTUI/Modules/CPU.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func CoreUsageHandler(core_id int32) {
log.Println(err)
}
globals.CpuDataBuf[core_id] = float64(result.GetCpuUsage())
//Move all elements one possistion back and push new value to end
for i := 0;i<len(globals.CpuGraphBuf)-1;i++{
globals.CpuGraphBuf[i] = globals.CpuGraphBuf[i+1]
}
globals.CpuGraphBuf[len(globals.CpuGraphBuf)-1] = float64(result.GetCpuUsage())
time.Sleep(time.Second)
}
}
Expand Down
97 changes: 79 additions & 18 deletions SysPerfTUI/Modules/RenderWidgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strconv"
"time"

"fmt"

"github.com/mum4k/termdash"
"github.com/mum4k/termdash/cell"
"github.com/mum4k/termdash/container"
Expand All @@ -17,10 +19,10 @@ import (
"github.com/mum4k/termdash/widgets/button"
"github.com/mum4k/termdash/widgets/donut"
"github.com/mum4k/termdash/widgets/gauge"
"fmt"
"github.com/mum4k/termdash/widgets/text"
)
func playGauge(ctx context.Context, g *gauge.Gauge, delay time.Duration, percent int32) {
progress := int(percent)
func playGauge(ctx context.Context, g *gauge.Gauge, delay time.Duration, percent *int32) {
progress := int(*percent)

ticker := time.NewTicker(delay)
defer ticker.Stop()
Expand All @@ -30,7 +32,7 @@ func playGauge(ctx context.Context, g *gauge.Gauge, delay time.Duration, percent
if err := g.Percent(progress); err != nil {
panic(err)
}
progress = int(percent)
progress = int(*percent)
case <-ctx.Done():
return
}
Expand Down Expand Up @@ -80,6 +82,13 @@ func playBarChart(ctx context.Context, bc *barchart.BarChart, delay time.Duratio
}
}
}
func writeText(widget *text.Text, time_dur time.Duration, variable *float64){
for{
widget.Reset()
widget.Write(strconv.FormatFloat(*variable,'g',5,64)+" GiB")
time.Sleep(time_dur)
}
}

func RenderWidgets() {
tcell.ColorMode(terminalapi.ColorMode256)
Expand Down Expand Up @@ -142,44 +151,44 @@ func RenderWidgets() {
mem_color[0] = cell.ColorRed

used_ram, err := gauge.New(
gauge.Height(1),
gauge.Color(cell.ColorAqua),
gauge.Height(4),
gauge.Color(mem_color[0]),
gauge.BorderTitle("Used RAM"),
)
if err != nil {
panic(err)
}
go playGauge(ctx, used_ram, time.Second, globals.Mem_used_percent)
go playGauge(ctx, used_ram, time.Second, &globals.Mem_used_percent)

available_ram, err := gauge.New(
gauge.Height(1),
gauge.Height(4),
gauge.Color(mem_color[0]),
gauge.BorderTitle("Available RAM"),
)
if err != nil {
panic(err)
}
go playGauge(ctx, available_ram, time.Second, globals.Mem_available_percentage)
go playGauge(ctx, available_ram, time.Second, &globals.Mem_available_percentage)

cached_ram, err := gauge.New(
gauge.Height(1),
gauge.Height(4),
gauge.Color(mem_color[0]),
gauge.BorderTitle("Cached RAM"),
)
if err != nil {
panic(err)
}
go playGauge(ctx, cached_ram, time.Second, globals.Mem_cached_percentage)
go playGauge(ctx, cached_ram, time.Second, &globals.Mem_cached_percentage)

free_ram, err := gauge.New(
gauge.Height(1),
gauge.Height(4),
gauge.Color(mem_color[0]),
gauge.BorderTitle("Free RAM"),
)
if err != nil {
panic(err)
}
go playGauge(ctx, free_ram, time.Second, globals.Mem_free_percentage)
go playGauge(ctx, free_ram, time.Second, &globals.Mem_free_percentage)

changecolorB, err := button.New("(c)olor", func() error {
for i := int32(0); i < globals.InitCpuData; i++ {
Expand Down Expand Up @@ -209,7 +218,29 @@ if err != nil {
}
go playBarChart(ctx, bc, 1*time.Second)

used_ram_text, err := text.New()
if err != nil {
panic(err)
}
go writeText(used_ram_text, time.Second, &globals.Mem_used)

available_ram_text, err := text.New()
if err != nil {
panic(err)
}
go writeText(available_ram_text, time.Second, &globals.Mem_available)

cached_ram_text, err := text.New()
if err != nil {
panic(err)
}
go writeText(cached_ram_text, time.Second, &globals.Mem_cached)

free_ram_text, err := text.New()
if err != nil {
panic(err)
}
go writeText(free_ram_text, time.Second, &globals.Mem_free)
c, err := container.New(
t,
container.Border(linestyle.Light),
Expand Down Expand Up @@ -248,27 +279,57 @@ c, err := container.New(
container.SplitVertical(
container.Left(
container.Border(linestyle.Light),
container.BorderTitle("Total Used RAM : "+strconv.FormatFloat(globals.Mem_used,'g',5,64)+" GiB"),
container.PlaceWidget(used_ram),
container.BorderTitle("Total Used RAM : "),
container.SplitHorizontal(
container.Top(
container.PlaceWidget(used_ram),
),
container.Bottom(
container.PlaceWidget(used_ram_text),
),
),
),
container.Right(
container.Border(linestyle.Light),
container.BorderTitle("Total Available RAM : "+strconv.FormatFloat(globals.Mem_available,'g',5,64)+" GiB"),
container.BorderTitle("Total Available RAM : "),
container.SplitHorizontal(
container.Top(
container.PlaceWidget(available_ram),

),
container.Bottom(
container.PlaceWidget(available_ram_text),
),
),
),
),
),
container.Bottom(
container.SplitVertical(
container.Left(
container.Border(linestyle.Light),
container.BorderTitle("Total Cached RAM : "+strconv.FormatFloat(globals.Mem_cached,'g',5,64)+" GiB"),
container.BorderTitle("Total Cached RAM : "),
container.SplitHorizontal(
container.Top(
container.PlaceWidget(cached_ram),

),
container.Bottom(
container.PlaceWidget(cached_ram_text),
),
),
),
container.Right(
container.Border(linestyle.Light),
container.BorderTitle("Total Free RAM : "+strconv.FormatFloat(globals.Mem_free,'g',5,64)+" GiB"),
container.BorderTitle("Total Free RAM : "),
container.SplitHorizontal(
container.Top(
container.PlaceWidget(free_ram),
),
container.Bottom(
container.PlaceWidget(free_ram_text),
),
),
),
),
),
Expand Down
Binary file modified SysPerfTUI/SysPerfTUI
Binary file not shown.
1 change: 1 addition & 0 deletions SysPerfTUI/globals/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
var Mainwaitgroup *sync.WaitGroup
var Conn *grpc.ClientConn
var CpuDataBuf []float64
var CpuGraphBuf []float64
var InitCpuData int32

var Mem_total float64
Expand Down
1 change: 1 addition & 0 deletions SysPerfTUI/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func globalConstructors() {
if err != nil {
log.Fatalf("did not connect: %v", err)
}
globals.CpuGraphBuf = make([]float64, 25)
}

func main() {
Expand Down

0 comments on commit f6288ee

Please sign in to comment.