Skip to content

Commit 17c4500

Browse files
authored
Merge pull request #3 from Ivlyth/add-kernel-3.x-support
Add kernel 3.x support
2 parents 368deeb + 40ddd89 commit 17c4500

File tree

9 files changed

+44
-43
lines changed

9 files changed

+44
-43
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
it provides a clean terminal UI based on [tview](https://github.com/rivo/tview) (as a CLI tool), and provides a
33
simple API to export data for prometheus (as a long-running task).
44

5-
![screenshot](./screenshots/pb-v0.1.0.gif)
5+
6+
### Screenshots
7+
![screenshot-top](./screenshots/pb-v0.3.1.png)
8+
![screenshot-options](./screenshots/pb-v0.3.1-optons.png)
69

710
### Usage
811
in `top` mode, you can open/close settings by press `F4`, exit by press `ESC` or CTRL+C, and pause/resume the update by
912
press `F5`, and you can click on the table header line (currently only support `In`, `Out`, `Total`) to change the sort
1013
column and order
1114

12-
also you can use `tab` to change focus between process's table and connection's table, and you can use up/down keys to
15+
also you can use `tab` to change focus between process's tableconnection's table and filter input box, and you can use up/down keys to
1316
scroll in the table, press the Enter key to choose current process or connection
1417

1518
### Requirements
16-
linux kernel version >= 4.18
19+
linux kernel version >= 3.10
1720

1821
### Installation
1922
please download through GitHub's release page, or you can build your own by just run `make` under the root
@@ -30,7 +33,7 @@ directory of the project
3033
##### filter both (you should check the both)
3134
> Note: filter processes and connections at the same time it's only meaningful that you filter processes based on connection
3235
and you want see connections only satisfies the filter for process. so we just use `or` to concat two (or more) filter,
33-
but we known that one is for process and another is for connection.
36+
but we know that one is for process and another is for connection.
3437

3538
- GetConnections.ConnectionInfo.LocalPort = 2181 or ConnectionInfo.LocalPort = 2181
3639

commands/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ var (
3737
fmt.Printf("error when get kernel version info: %s\n", err)
3838
os.Exit(1)
3939
}
40-
if kv < kernel.VersionCode(4, 18, 0) {
41-
fmt.Printf("Linux Kernel version %v is not supported. Need > 4.18 .\n", kv)
40+
if kv < kernel.VersionCode(3, 10, 0) {
41+
fmt.Printf("Linux Kernel version %v is not supported. Need >= 3.10 .\n", kv)
4242
os.Exit(1)
4343
}
4444

screenshots/pb-v0.3.1-optons.png

20.2 KB
Loading

screenshots/pb-v0.3.1.png

174 KB
Loading

top/app.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ var pages *tview.Pages
1616

1717
func StartTop() error {
1818

19-
pTable = initProcessTable()
19+
initProcessTable()
2020

21-
cTable = initConnectionTable()
21+
initConnectionTable()
2222

23-
graphView = initGraphView()
23+
initGraphView()
2424

2525
connectionPanel = tview.NewFlex().
2626
SetDirection(tview.FlexRow).
@@ -33,7 +33,7 @@ func StartTop() error {
3333

3434
infoView = tview.NewTextView().SetDynamicColors(true).SetWrap(false)
3535

36-
filterPanel := initFilterPanel()
36+
initFilterPanel()
3737

3838
mainPanel := tview.NewFlex().
3939
SetDirection(tview.FlexRow).
@@ -56,6 +56,8 @@ func StartTop() error {
5656
if event.Key() == tcell.KeyTAB {
5757
if pTable.HasFocus() {
5858
app.SetFocus(connectionPanel).SetFocus(cTable)
59+
} else if cTable.HasFocus() {
60+
app.SetFocus(filterPanel).SetFocus(filterInput)
5961
} else {
6062
app.SetFocus(processPanel).SetFocus(pTable)
6163
}

top/connection_table.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ func initConnectionTableHeader() {
3939
cTable.SetFixed(1, 1)
4040
}
4141

42-
func initConnectionTable() *tview.Table {
43-
table := tview.NewTable().
42+
func initConnectionTable() {
43+
cTable = tview.NewTable().
4444
SetBorders(false).SetSelectable(true, false).SetSeparator(tview.Borders.Vertical)
45-
table.SetBorder(true).SetTitle(" Connection's Bandwidth ")
46-
table.SetEvaluateAllRows(true)
45+
cTable.SetBorder(true).SetTitle(" Connection's Bandwidth ")
46+
cTable.SetEvaluateAllRows(true)
4747

48-
table.SetSelectionChangedFunc(func(row, column int) {
48+
cTable.SetSelectionChangedFunc(func(row, column int) {
4949
lastUserScrollCTableAt = time.Now()
5050

5151
if row == 0 {
@@ -78,8 +78,8 @@ func initConnectionTable() *tview.Table {
7878
})
7979

8080
// set table header
81-
table.SetSelectedFunc(func(row int, column int) {
82-
v, ok := table.GetCell(row, 0).GetReference().(*engine.Connection)
81+
cTable.SetSelectedFunc(func(row int, column int) {
82+
v, ok := cTable.GetCell(row, 0).GetReference().(*engine.Connection)
8383
if ok {
8484
logger.Debugf("select connection inside cTable at row:%d, col:%d, connection fd is %d\n", row, column, v.FD)
8585
selectedConnection = v
@@ -91,8 +91,6 @@ func initConnectionTable() *tview.Table {
9191
refreshConnectionTable()
9292
refreshGraphPanel()
9393
})
94-
95-
return table
9694
}
9795

9896
func refreshConnectionTable() {

top/filter_panel.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ var filterForProcess = true
1212
var filterForConnections = false
1313
var filterErr error
1414

15-
func initFilterPanel() *tview.Flex {
16-
input := tview.NewInputField()
15+
var filterPanel *tview.Flex
16+
var filterInput *tview.InputField
17+
18+
func initFilterPanel() {
19+
filterInput = tview.NewInputField()
1720
filterExpr, filterErr = uni_filter.Parse(filterStr)
18-
input.SetLabel("Filter: ").SetText(filterStr /*default filter*/).SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
21+
filterInput.SetLabel("Filter: ").SetText(filterStr /*default filter*/).SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
1922
if event.Key() == tcell.KeyEnter {
20-
filterStr = input.GetText()
23+
filterStr = filterInput.GetText()
2124
logger.Debugf("enter key pressed, filter text is: %s\n", filterStr)
2225
filterExpr, filterErr = uni_filter.Parse(filterStr)
2326
if filterErr != nil {
@@ -37,13 +40,11 @@ func initFilterPanel() *tview.Flex {
3740
//applyButton := tview.NewButton("<Apply>")
3841
//recentButton := tview.NewButton("<Recent>")
3942

40-
optionsFlex := tview.NewFlex().SetDirection(tview.FlexColumn).
41-
AddItem(input, 0, 40, false).
43+
filterPanel = tview.NewFlex().SetDirection(tview.FlexColumn).
44+
AddItem(filterInput, 0, 40, false).
4245
AddItem(nil, 0, 1, false).
4346
AddItem(filterProcess, 0, 5, false).
4447
AddItem(nil, 0, 1, false).
4548
AddItem(filterConnections, 0, 5, false)
46-
optionsFlex.SetBorder(true)
47-
48-
return optionsFlex
49+
filterPanel.SetBorder(true)
4950
}

top/graph_panel.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ import (
1111
var graphView *tview.TextView
1212
var histories []engine.RWSnapshot
1313

14-
func initGraphView() *tview.TextView {
15-
v := tview.NewTextView().SetDynamicColors(true).SetWrap(false)
16-
v.SetBorder(true).SetTitle(" bandwidth graph ")
17-
_, _ = v.Write([]byte("waiting for select process or connection"))
18-
19-
return v
14+
func initGraphView() {
15+
graphView = tview.NewTextView().SetDynamicColors(true).SetWrap(false)
16+
graphView.SetBorder(true).SetTitle(" bandwidth graph ")
17+
_, _ = graphView.Write([]byte("waiting for select process or connection"))
2018
}
2119

2220
func refreshGraphPanel() {

top/process_table.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ func initProcessTableHeader() {
4040
pTable.SetFixed(1, 1)
4141
}
4242

43-
func initProcessTable() *tview.Table {
44-
table := tview.NewTable().
43+
func initProcessTable() {
44+
pTable = tview.NewTable().
4545
SetBorders(false).SetSelectable(true, false).SetSeparator(tview.Borders.Vertical)
46-
table.SetBorder(true).SetTitle(" Process's Bandwidth ")
47-
table.SetEvaluateAllRows(true)
46+
pTable.SetBorder(true).SetTitle(" Process's Bandwidth ")
47+
pTable.SetEvaluateAllRows(true)
4848

49-
table.SetSelectionChangedFunc(func(row, column int) {
49+
pTable.SetSelectionChangedFunc(func(row, column int) {
5050
lastUserScrollPTableAt = time.Now()
51-
v, ok := table.GetCell(row, 0).GetReference().(*engine.Process)
51+
v, ok := pTable.GetCell(row, 0).GetReference().(*engine.Process)
5252
if ok {
5353
infoView.Clear()
5454
_, _ = infoView.Write([]byte(v.Cmdline))
@@ -86,9 +86,9 @@ func initProcessTable() *tview.Table {
8686
}
8787
})
8888

89-
table.SetSelectedFunc(func(row int, column int) {
89+
pTable.SetSelectedFunc(func(row int, column int) {
9090
logger.Debugf("ptable selected row:%d, column:%d\n", row, column)
91-
v, ok := table.GetCell(row, 0).GetReference().(*engine.Process)
91+
v, ok := pTable.GetCell(row, 0).GetReference().(*engine.Process)
9292
infoView.Clear()
9393
if ok {
9494
selectedProcess = v
@@ -107,7 +107,6 @@ func initProcessTable() *tview.Table {
107107
refreshConnectionTable()
108108
refreshGraphPanel()
109109
})
110-
return table
111110
}
112111

113112
func refreshProcessTable() {

0 commit comments

Comments
 (0)