Skip to content

Commit

Permalink
Merge pull request #43 from pesos/master
Browse files Browse the repository at this point in the history
Minor bug fixes
  • Loading branch information
metonymic-smokey authored Aug 16, 2020
2 parents daf4742 + 336be63 commit 78f9b7b
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 43 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ go get -u github.com/pesos/grofer
```

As an executable:

```
curl -sSL https://github.com/pesos/grofer/releases/download/<version tag>/grofer --output grofer
chmod +x grofer
```

For system wide usage, install `grofer` to a location on `$PATH`, e.g. `/usr/local/bin`

```
mv grofer /usr/local/bin
```

Building from source:

```
Expand Down Expand Up @@ -57,7 +63,8 @@ Use "grofer [command] --help" for more information about a command.
Examples
--------

## `grofer [-r refreshRate]`
`grofer [-r refreshRate]`
-------------------------

This gives overall utilization stats refreshed every `refreshRate` milliseconds. Default and minimum value of the refresh rate is `1000 ms`.

Expand All @@ -70,9 +77,11 @@ Information provided:
- Disk storage

---
## `grofer proc [-p PID] [-r refreshRate]`

If the `-r` flag is specified then the UI will refresh and display new information every `refreshRate` milliseconds. The minimum and default value for `refreshRate` is `1000 ms`.
`grofer proc [-p PID] [-r refreshRate]`
---------------------------------------

If the `-r` flag is specified then the UI will refresh and display new information every `refreshRate` milliseconds. The minimum and default value for `refreshRate` is `1000 ms`.

### `grofer proc`

Expand Down
8 changes: 4 additions & 4 deletions cmd/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

const (
DefaultProcRefreshRate = 1000
DefaultProcRefreshRate = 3000
)

// procCmd represents the proc command
Expand Down Expand Up @@ -72,16 +72,16 @@ Syntax:
return fmt.Errorf("invalid pid")
}

go process.Serve(proc, dataChannel, endChannel, &wg)
go procGraph.ProcVisuals(endChannel, dataChannel, &wg)
go process.Serve(proc, dataChannel, endChannel, int32(4*procRefreshRate/5), &wg)
go procGraph.ProcVisuals(endChannel, dataChannel, procRefreshRate, &wg)
wg.Wait()
} else {
dataChannel := make(chan []*proc.Process, 1)
endChannel := make(chan os.Signal, 1)

wg.Add(2)

go process.ServeProcs(dataChannel, endChannel, procRefreshRate, &wg)
go process.ServeProcs(dataChannel, endChannel, int32(4*procRefreshRate/5), &wg)
go procGraph.AllProcVisuals(dataChannel, endChannel, procRefreshRate, &wg)
wg.Wait()
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var rootCmd = &cobra.Command{

wg.Add(2)

go general.GlobalStats(endChannel, dataChannel, overallRefreshRate, &wg)
go general.GlobalStats(endChannel, dataChannel, int32(4*overallRefreshRate/5), &wg)
go overallGraph.RenderCharts(endChannel, dataChannel, overallRefreshRate, &wg)

wg.Wait()
Expand Down
55 changes: 33 additions & 22 deletions src/display/general/overallGraphs.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ func RenderCharts(endChannel chan os.Signal,
run = !run
}

updateUI := func() {

// Get Terminal Dimensions adn clear the UI
w, h := ui.TerminalDimensions()
ui.Clear()

// Calculate Heigth offset
height := int(h / numCores)
heightOffset := h - (height * numCores)

// Adjust Memory Bar graph values
myPage.MemoryChart.BarGap = ((w / 2) - (4 * myPage.MemoryChart.BarWidth)) / 4

// Adjust CPU Gauge dimensions
if isCPUSet {
for i := 0; i < numCores; i++ {
myPage.CPUCharts[i].SetRect(0, i*height, w/2, (i+1)*height)
ui.Render(myPage.CPUCharts[i])
}
}

// Adjust Grid dimensions
myPage.Grid.SetRect(w/2, 0, w, h-heightOffset)

ui.Render(myPage.Grid)
}

updateUI() // Initialize empty UI

uiEvents := ui.PollEvents()
tick := time.Tick(time.Duration(refreshRate) * time.Millisecond)
for {
Expand All @@ -74,6 +103,9 @@ func RenderCharts(endChannel chan os.Signal,
wg.Done()
return

case "<Resize>":
updateUI()

case "s": // s to stop
pause()
}
Expand Down Expand Up @@ -147,28 +179,7 @@ func RenderCharts(endChannel chan os.Signal,
}

case <-tick: // Update page with new values
w, h := ui.TerminalDimensions()
ui.Clear()

height := int(h / numCores)
heightOffset := h - (height * numCores)

// Adjust Grid dimensions
myPage.Grid.SetRect(w/2, 0, w, h-heightOffset)

// Adjust Memory Bar graph values
myPage.MemoryChart.BarGap = ((w / 2) - (4 * myPage.MemoryChart.BarWidth)) / 4

// Adjust CPU Gauge dimensions
if isCPUSet {
for i := 0; i < numCores; i++ {
myPage.CPUCharts[i].SetRect(0, i*height, w/2, (i+1)*height)
ui.Render(myPage.CPUCharts[i])
}
}

ui.Render(myPage.Grid)

updateUI()
}
}
}
24 changes: 20 additions & 4 deletions src/display/process/allProcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
)

var runAllProc = true
var on1 sync.Once

func getData(procs []*proc.Process) []string {
var data []string
Expand Down Expand Up @@ -133,6 +134,15 @@ func AllProcVisuals(dataChannel chan []*proc.Process,

myPage := NewAllProcsPage()

updateUI := func() {
w, h := ui.TerminalDimensions()
ui.Clear()
myPage.Grid.SetRect(0, 0, w, h)
ui.Render(myPage.Grid)
}

updateUI() // Render empty UI

pause := func() {
runAllProc = !runAllProc
}
Expand All @@ -152,6 +162,8 @@ func AllProcVisuals(dataChannel chan []*proc.Process,
ui.Close()
wg.Done()
return
case "<Resize>":
updateUI() // updateUI only during resize event
case "s": //s to pause
pause()
case "j", "<Down>":
Expand All @@ -176,6 +188,7 @@ func AllProcVisuals(dataChannel chan []*proc.Process,
myPage.BodyList.ScrollBottom()
}

ui.Render(myPage.Grid)
if previousKey == "g" {
previousKey = ""
} else {
Expand All @@ -185,13 +198,16 @@ func AllProcVisuals(dataChannel chan []*proc.Process,
case data := <-dataChannel:
myPage.BodyList.SelectedRowStyle = selectedStyle
if runAllProc {

myPage.BodyList.Rows = getData(data)

on1.Do(func() {
w, h := ui.TerminalDimensions()
ui.Clear()
myPage.Grid.SetRect(0, 0, w, h)
ui.Render(myPage.Grid)
})
}
case <-tick: // Update page with new values
w, h := ui.TerminalDimensions()
ui.Clear()
myPage.Grid.SetRect(0, 0, w, h)
ui.Render(myPage.Grid)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/display/process/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (page *PerProcPage) InitPerProc() {
page.CTXSwitchesChart.Title = " Ctx switches "
page.CTXSwitchesChart.BorderStyle.Fg = ui.ColorCyan
page.CTXSwitchesChart.TitleStyle.Fg = ui.ColorWhite
page.CTXSwitchesChart.BarWidth = 10
page.CTXSwitchesChart.BarWidth = 9
page.CTXSwitchesChart.BarColors = []ui.Color{ui.ColorGreen, ui.ColorCyan}
page.CTXSwitchesChart.LabelStyles = []ui.Style{ui.NewStyle(ui.ColorWhite)}
page.CTXSwitchesChart.NumStyles = []ui.Style{ui.NewStyle(ui.ColorBlack)}
Expand All @@ -94,7 +94,7 @@ func (page *PerProcPage) InitPerProc() {
page.PageFaultsChart.Title = " Page Faults "
page.PageFaultsChart.BorderStyle.Fg = ui.ColorCyan
page.PageFaultsChart.TitleStyle.Fg = ui.ColorWhite
page.PageFaultsChart.BarWidth = 10
page.PageFaultsChart.BarWidth = 9
page.PageFaultsChart.BarColors = []ui.Color{ui.ColorGreen, ui.ColorCyan}
page.PageFaultsChart.LabelStyles = []ui.Style{ui.NewStyle(ui.ColorWhite)}
page.PageFaultsChart.NumStyles = []ui.Style{ui.NewStyle(ui.ColorBlack)}
Expand All @@ -105,7 +105,7 @@ func (page *PerProcPage) InitPerProc() {
page.MemStatsChart.Title = " Mem Stats (mb) "
page.MemStatsChart.BorderStyle.Fg = ui.ColorCyan
page.MemStatsChart.TitleStyle.Fg = ui.ColorWhite
page.MemStatsChart.BarWidth = 10
page.MemStatsChart.BarWidth = 9
page.MemStatsChart.BarColors = []ui.Color{ui.ColorGreen, ui.ColorMagenta, ui.ColorYellow, ui.ColorCyan}
page.MemStatsChart.LabelStyles = []ui.Style{ui.NewStyle(ui.ColorWhite)}
page.MemStatsChart.NumStyles = []ui.Style{ui.NewStyle(ui.ColorBlack)}
Expand Down
51 changes: 46 additions & 5 deletions src/display/process/procGraphs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
)

var runProc = true
var on sync.Once

func getChildProcs(proc *process.Process) []string {
childProcs := []string{"PID Command"}
Expand All @@ -51,6 +52,7 @@ func getChildProcs(proc *process.Process) []string {
// ProcVisuals renders graphs and charts for per-process stats.
func ProcVisuals(endChannel chan os.Signal,
dataChannel chan *process.Process,
refreshRate int32,
wg *sync.WaitGroup) {

if err := ui.Init(); err != nil {
Expand All @@ -74,8 +76,28 @@ func ProcVisuals(endChannel chan os.Signal,
runProc = !runProc
}

updateUI := func() {

// Get Terminal Dimensions adn clear the UI
w, h := ui.TerminalDimensions()
ui.Clear()

// Adjust Memory Stats Bar graph values
myPage.MemStatsChart.BarGap = ((w / 2) - (4 * myPage.MemStatsChart.BarWidth)) / 4

// Adjust Page Faults Bar graph values
myPage.PageFaultsChart.BarGap = ((w / 4) - (2 * myPage.PageFaultsChart.BarWidth)) / 2

// Adjust Context Switches Bar graph values
myPage.CTXSwitchesChart.BarGap = ((w / 4) - (2 * myPage.CTXSwitchesChart.BarWidth)) / 2

// Adjust Grid dimensions
myPage.Grid.SetRect(0, 0, w, h)
ui.Render(myPage.Grid)
}

uiEvents := ui.PollEvents()
tick := time.Tick(1 * time.Second)
tick := time.Tick(time.Duration(refreshRate) * time.Millisecond)

previousKey := ""
for {
Expand All @@ -89,6 +111,9 @@ func ProcVisuals(endChannel chan os.Signal,
return
case "s": //s to pause
pause()
case "<Resize>":
updateUI()

case "j", "<Down>":
myPage.ChildProcsList.ScrollDown()
case "k", "<Up>":
Expand Down Expand Up @@ -160,13 +185,29 @@ func ProcVisuals(endChannel chan os.Signal,
myPage.PageFaultsChart.Data = faults
myPage.PageFaultsChart.Title = " Page Faults" + units
myPage.ChildProcsList.Rows = getChildProcs(data)

on.Do(func() {
// Get Terminal Dimensions adn clear the UI
w, h := ui.TerminalDimensions()
ui.Clear()

// Adjust Memory Stats Bar graph values
myPage.MemStatsChart.BarGap = ((w / 2) - (4 * myPage.MemStatsChart.BarWidth)) / 4

// Adjust Page Faults Bar graph values
myPage.PageFaultsChart.BarGap = ((w / 4) - (2 * myPage.PageFaultsChart.BarWidth)) / 2

// Adjust Context Switches Bar graph values
myPage.CTXSwitchesChart.BarGap = ((w / 4) - (2 * myPage.CTXSwitchesChart.BarWidth)) / 2

// Adjust Grid dimensions
myPage.Grid.SetRect(0, 0, w, h)
ui.Render(myPage.Grid)
})
}

case <-tick:
w, h := ui.TerminalDimensions()
ui.Clear()
myPage.Grid.SetRect(0, 0, w, h)
ui.Render(myPage.Grid)
updateUI()
}
}
}
3 changes: 2 additions & 1 deletion src/process/serveData.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

// Serve serves data on a per process basis
func Serve(process *Process, dataChannel chan *Process, endChannel chan os.Signal, wg *sync.WaitGroup) {
func Serve(process *Process, dataChannel chan *Process, endChannel chan os.Signal, refreshRate int32, wg *sync.WaitGroup) {
for {
select {
case <-endChannel:
Expand All @@ -34,6 +34,7 @@ func Serve(process *Process, dataChannel chan *Process, endChannel chan os.Signa
default:
process.UpdateProcInfo()
dataChannel <- process
time.Sleep(time.Duration(refreshRate) * time.Millisecond)
}
}

Expand Down

0 comments on commit 78f9b7b

Please sign in to comment.