Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Add Error function; improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbassi committed Apr 11, 2018
1 parent 96596fe commit 8b7b7bb
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package utils

import (
"fmt"
"math"

ui "github.com/cjbassi/termui"
)

func BytesToKB(b uint64) float64 {
Expand All @@ -15,3 +18,14 @@ func BytesToMB(b uint64) float64 {
func BytesToGB(b uint64) float64 {
return float64(b) / math.Pow10(9)
}

func Error(issue, diagnostics string) {
ui.Close()
fmt.Println("Error caught. Exiting program.")
fmt.Println()
fmt.Println("Issue with " + issue + ".")
fmt.Println()
fmt.Println("Diagnostics:\n" + diagnostics)
fmt.Println()
panic(1)
}
2 changes: 1 addition & 1 deletion vendor/github.com/cjbassi/termui/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/cjbassi/termui/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions vendor/github.com/cjbassi/termui/sparkline.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions vendor/github.com/cjbassi/termui/table.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions vendor/github.com/cjbassi/termui/utils.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions widgets/cpu.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package widgets

import (
"log"
"fmt"
"strconv"
"time"

"github.com/cjbassi/gotop/utils"
ui "github.com/cjbassi/termui"
psCPU "github.com/shirou/gopsutil/cpu"
)
Expand Down Expand Up @@ -50,7 +51,14 @@ func (self *CPU) update() {
percents, _ := psCPU.Percent(self.interval, true)
if len(percents) != self.Count {
count, _ := psCPU.Counts(false)
log.Fatalf("\nself.Count: %d\ngopsutil.Counts(): %d\nlen(percents): %d\npercents: %v\nself.interval: %v", self.Count, count, len(percents), percents, self.interval)
utils.Error("CPU percentages",
fmt.Sprint(
"self.Count: ", self.Count, "\n",
"gopsutil.Counts(): ", count, "\n",
"len(percents): ", len(percents), "\n",
"percents: ", percents, "\n",
"self.interval: ", self.interval,
))
}
for i := 0; i < self.Count; i++ {
key := "CPU" + strconv.Itoa(i)
Expand Down

0 comments on commit 8b7b7bb

Please sign in to comment.