Skip to content

Commit

Permalink
feat #254: Added overall system resource usage statistics to the TUI
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Oct 4, 2024
1 parent 6576fb2 commit 663b8d0
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,9 @@ const docTemplate = `{
"age": {
"type": "integer"
},
"cpu": {
"type": "number"
},
"exit_code": {
"type": "integer"
},
Expand Down
3 changes: 3 additions & 0 deletions src/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@
"age": {
"type": "integer"
},
"cpu": {
"type": "number"
},
"exit_code": {
"type": "integer"
},
Expand Down
2 changes: 2 additions & 0 deletions src/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ components:
properties:
age:
type: integer
cpu:
type: number
exit_code:
type: integer
is_elevated:
Expand Down
11 changes: 11 additions & 0 deletions src/tui/proc-table.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func (pv *pcView) fillTableData() {
return
}
runningProcCount := 0
totalMem := int64(0)
totalCPU := 0.0
states, err := pv.project.GetProcessesState()
if err != nil {
log.Err(err).Msg("failed to get processes state")
Expand Down Expand Up @@ -64,6 +66,8 @@ func (pv *pcView) fillTableData() {
setRowValues(pv.procTable, row, rowVals)
if state.IsRunning {
runningProcCount += 1
totalMem += state.Mem
totalCPU += state.CPU
}
selectedRow, _ := pv.procTable.GetSelection()
if selectedRow == row && pv.isPassModeNeeded(&state) {
Expand All @@ -89,6 +93,13 @@ func (pv *pcView) fillTableData() {
}
pv.procCountCell.SetText(fmt.Sprintf("%d/%d%s", runningProcCount, len(pv.procNames), nsLbl))
}
if pv.procMemCpuCell != nil {
nsLbl := ""
if !pv.isNsSelected(AllNS) {
nsLbl = " (" + pv.getSelectedNs() + ")"
}
pv.procMemCpuCell.SetText(fmt.Sprintf("%s | %s%s", getStrForMem(totalMem, true), getStrForCPU(totalCPU, true), nsLbl))
}

pv.autoAdjustProcTableHeight()
if showPass {
Expand Down
2 changes: 1 addition & 1 deletion src/tui/proc-table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestMemToString(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getStrForMem(tt.args.mem, false); got != tt.want {
if got := getStrForMem(tt.args.mem, true); got != tt.want {
t.Errorf("getStrForMem() = %v, want %v", got, tt.want)
}
})
Expand Down
7 changes: 7 additions & 0 deletions src/tui/stat-table.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ func (pv *pcView) createStatTable() *tview.Table {
SetSelectable(false).
SetExpansion(1)
table.SetCell(2, 1, pv.procCountCell)
pv.procMemCpuCell = tview.NewTableCell("").
SetSelectable(false).
SetExpansion(1)
table.SetCell(2, 2, tview.NewTableCell(""))
table.SetCell(3, 0, tview.NewTableCell("RAM | CPU:").
SetSelectable(false))
table.SetCell(3, 1, pv.procMemCpuCell)
table.SetCell(0, 2, tview.NewTableCell("").
SetSelectable(false).
SetAlign(tview.AlignCenter).
Expand Down
28 changes: 15 additions & 13 deletions src/tui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type pcView struct {
loggedProc string
shortcuts *ShortCuts
procCountCell *tview.TableCell
procMemCpuCell *tview.TableCell
mainGrid *tview.Grid
logsTextArea *tview.TextArea
project app.IProject
Expand Down Expand Up @@ -91,19 +92,20 @@ type pcView struct {
func newPcView(project app.IProject) *pcView {

pv := &pcView{
appView: tview.NewApplication(),
logsText: NewLogView(project.GetLogLength()),
statusText: tview.NewTextView().SetDynamicColors(true),
logFollow: true,
scrSplitState: LogProcHalf,
helpText: tview.NewTextView().SetDynamicColors(true),
loggedProc: "",
procCountCell: tview.NewTableCell(""),
mainGrid: tview.NewGrid(),
logsTextArea: tview.NewTextArea(),
logSelect: false,
project: project,
refreshRate: time.Second,
appView: tview.NewApplication(),
logsText: NewLogView(project.GetLogLength()),
statusText: tview.NewTextView().SetDynamicColors(true),
logFollow: true,
scrSplitState: LogProcHalf,
helpText: tview.NewTextView().SetDynamicColors(true),
loggedProc: "",
procCountCell: tview.NewTableCell(""),
procMemCpuCell: tview.NewTableCell(""),
mainGrid: tview.NewGrid(),
logsTextArea: tview.NewTextArea(),
logSelect: false,
project: project,
refreshRate: time.Second,
stateSorter: StateSorter{
sortByColumn: ProcessStateName,
isAsc: true,
Expand Down

0 comments on commit 663b8d0

Please sign in to comment.