Skip to content

Commit

Permalink
Merge pull request #32 from pesos/master
Browse files Browse the repository at this point in the history
Release v1.0.0
  • Loading branch information
metonymic-smokey authored Aug 7, 2020
2 parents 0df2cf3 + 8484730 commit 8b00c40
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Please delete options that are not relevant.

# Checklist:

- [ ] I have read the [contribution guidelines](https://github.com/pesos/grofer/blob/master/CONTRIBUTING.md) and followed it as far as possible.
- [ ] I have performed a self-review of my own code (if applicable)
- [ ] I have commented my code, particularly in hard-to-understand areas (if applicable)
- [ ] I have run `go fmt` on my code ([reference](https://blog.golang.org/gofmt))
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- Look for issues in the repository. Identify an issue you would like to work on.
- Once you have done that, leave a comment on the issue saying that you want to work on it. The maintainers will give you the go-ahead.
- Fork the repository, make your changes on the `master` branch, or on the appropriate feature branch if applicable
- Fork the repository. Your changes will be made on its `master` branch, or on the appropriate feature branch if applicable
- Clone the fork on your system. Add a remote to the original `pesos/grofer` repository called `upstream`
```
git clone https://github.com/<your-github-username>/grofer.git
Expand All @@ -14,14 +14,14 @@ git add <names of all the modified files>
git commit
```

- Make your commit descriptive. The above command will open your text editor. Write the commit message on the first line and a short description about your change. Save and quit the editor to commit your change.
- Make your commit descriptive. The above command will open your text editor. Write the commit message on the first line and a short description about your change. Save and quit the editor to commit your change.

- Before pushing your changes, make sure that the changes from upstream are included (use `--rebase` to make sure that your changes stay on top of the latest changes in the upstream repository)
```
git pull --rebase upstream
git pull --rebase upstream master # if you are working on a feature branch, use that branch name instead of master
```

- In the *extremely* small chance that you run into a conflict, just open the files having the conflict and remove the markers and edit the file to the one you want to push. After editing, run `git rebase --continue` and repeat till no conflict remains
- In the *extremely* small chance that you run into a conflict, just open the files having the conflict and remove the markers and edit the file to the one you want to push. After editing, run `git rebase --continue` and repeat till no conflict remains

- Verify that your program builds and passes all the tests, and your change actually works in general
- Push your changes to your fork
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Available Commands:
Flags:
--config string config file (default is $HOME/.grofer.yaml)
-h, --help help for grofer
-r, --refresh int32 Overall stats UI refreshes rate in milliseconds greater than 1000 (default 1000)
-t, --toggle Help message for toggle
Use "grofer [command] --help" for more information about a command.
Expand All @@ -49,9 +50,9 @@ Use "grofer [command] --help" for more information about a command.
Examples
--------

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

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

![grofer](images/README/grofer.png)

Expand All @@ -62,6 +63,9 @@ 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`

Expand All @@ -71,7 +75,7 @@ This lists all running processes and relevant information.

---

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

This gives information specific to a process, specified by a valid PID.

Expand Down
21 changes: 16 additions & 5 deletions cmd/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ import (
"os"
"sync"

"github.com/pesos/grofer/src/utils"
proc "github.com/shirou/gopsutil/process"
"github.com/spf13/cobra"

procGraph "github.com/pesos/grofer/src/display/process"
"github.com/pesos/grofer/src/process"
proc "github.com/shirou/gopsutil/process"
"github.com/spf13/cobra"
"github.com/pesos/grofer/src/utils"
)

const (
DefaultProcRefreshRate = 1000
)

// procCmd represents the proc command
Expand All @@ -48,6 +52,12 @@ Syntax:
}

pid, _ := cmd.Flags().GetInt32("pid")
procRefreshRate, _ := cmd.Flags().GetInt32("refresh")

if procRefreshRate < 1000 {
return fmt.Errorf("invalid refresh rate: minimum refresh rate is 1000(ms)")
}

var wg sync.WaitGroup

if pid != -1 {
Expand All @@ -71,8 +81,8 @@ Syntax:

wg.Add(2)

go process.ServeProcs(dataChannel, endChannel, &wg)
go procGraph.AllProcVisuals(dataChannel, endChannel, &wg)
go process.ServeProcs(dataChannel, endChannel, procRefreshRate, &wg)
go procGraph.AllProcVisuals(dataChannel, endChannel, procRefreshRate, &wg)
wg.Wait()
}

Expand All @@ -92,5 +102,6 @@ func init() {
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// procCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
procCmd.Flags().Int32P("refresh", "r", DefaultProcRefreshRate, "Process information UI refreshes rate in milliseconds greater than 1000")
procCmd.Flags().Int32P("pid", "p", -1, "specify pid of process")
}
23 changes: 18 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,31 @@ import (
"os"
"sync"

"github.com/spf13/cobra"

homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"

overallGraph "github.com/pesos/grofer/src/display/general"
"github.com/pesos/grofer/src/general"
)

const (
DefaultOverallRefreshRate = 1000
)

var cfgFile string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "grofer",
Short: "grofer is a system profiler written in golang",
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {

overallRefreshRate, _ := cmd.Flags().GetInt32("refresh")
if overallRefreshRate < 1000 {
return fmt.Errorf("invalid refresh rate: minimum refresh rate is 1000(ms)")
}

var wg sync.WaitGroup
endChannel := make(chan os.Signal, 1)
memChannel := make(chan []float64, 1)
Expand All @@ -45,10 +54,12 @@ var rootCmd = &cobra.Command{

wg.Add(2)

go general.GlobalStats(endChannel, cpuChannel, memChannel, diskChannel, netChannel, &wg)
go overallGraph.RenderCharts(endChannel, memChannel, cpuChannel, diskChannel, netChannel, &wg)
go general.GlobalStats(endChannel, cpuChannel, memChannel, diskChannel, netChannel, overallRefreshRate, &wg)
go overallGraph.RenderCharts(endChannel, memChannel, cpuChannel, diskChannel, netChannel, overallRefreshRate, &wg)

wg.Wait()

return nil
},
}

Expand All @@ -62,6 +73,8 @@ func Execute() {
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.grofer.yaml)")

rootCmd.Flags().Int32P("refresh", "r", DefaultOverallRefreshRate, "Overall stats UI refreshes rate in milliseconds greater than 1000")
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

Expand Down
3 changes: 2 additions & 1 deletion src/display/general/overallGraphs.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func RenderCharts(endChannel chan os.Signal,
cpuChannel chan []float64,
diskChannel chan [][]string,
netChannel chan map[string][]float64,
refreshRate int32,
wg *sync.WaitGroup) {

if err := ui.Init(); err != nil {
Expand Down Expand Up @@ -65,7 +66,7 @@ func RenderCharts(endChannel chan os.Signal,
}

uiEvents := ui.PollEvents()
tick := time.Tick(1000 * time.Millisecond)
tick := time.Tick(time.Duration(refreshRate) * time.Millisecond)
for {
select {
case e := <-uiEvents: // For keyboard events
Expand Down
3 changes: 2 additions & 1 deletion src/display/process/allProcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func getData(procs []*proc.Process) []string {

func AllProcVisuals(dataChannel chan []*proc.Process,
endChannel chan os.Signal,
refreshRate int32,
wg *sync.WaitGroup) {

if err := ui.Init(); err != nil {
Expand All @@ -137,7 +138,7 @@ func AllProcVisuals(dataChannel chan []*proc.Process,
}

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

previousKey := ""
selectedStyle := ui.NewStyle(ui.ColorYellow, ui.ColorClear, ui.ModifierBold)
Expand Down
3 changes: 2 additions & 1 deletion src/general/generalStats.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func GlobalStats(endChannel chan os.Signal,
memChannel chan []float64,
diskChannel chan [][]string,
netChannel chan map[string][]float64,
refreshRate int32,
wg *sync.WaitGroup) {

for {
Expand All @@ -41,7 +42,7 @@ func GlobalStats(endChannel chan os.Signal,
go PrintMemRates(memChannel)
go PrintDiskRates(diskChannel)
PrintNetRates(netChannel)
time.Sleep(1000 * time.Millisecond)
time.Sleep(time.Duration(refreshRate) * time.Millisecond)
}
}
}
4 changes: 2 additions & 2 deletions src/process/serveData.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Serve(process *Process, dataChannel chan *Process, endChannel chan os.Signa

}

func ServeProcs(dataChannel chan []*proc.Process, endChannel chan os.Signal, wg *sync.WaitGroup) {
func ServeProcs(dataChannel chan []*proc.Process, endChannel chan os.Signal, refreshRate int32, wg *sync.WaitGroup) {
for {
select {
case <-endChannel:
Expand All @@ -50,7 +50,7 @@ func ServeProcs(dataChannel chan []*proc.Process, endChannel chan os.Signal, wg
procs, err := proc.Processes()
if err == nil {
dataChannel <- procs
time.Sleep(1000 * time.Millisecond)
time.Sleep(time.Duration(refreshRate) * time.Millisecond)
}
}
}
Expand Down

0 comments on commit 8b00c40

Please sign in to comment.