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

FreeBSD Fixes & Nvidia GPU Support #157

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/widgets/mem_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ func gatherSwapInfo() (MemoryInfo, error) {
}
}

ss := strings.Split(strings.TrimSuffix(string(output), "\n"), " ")
s := strings.TrimSuffix(string(output), "\n")
s = strings.ReplaceAll(s, "\n", " ")
ss := strings.Split(s, " ")
ss = ss[((len(ss)/3)-1)*3:]

return convert(ss)
}
Expand Down
71 changes: 61 additions & 10 deletions src/widgets/temp_freebsd.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package widgets

import (
"fmt"
"log"
"os/exec"
"strconv"
"strings"

"github.com/cjbassi/gotop/src/utils"
"github.com/rai-project/nvidia-smi"
)

var sensorOIDS = map[string]string{
Expand Down Expand Up @@ -35,31 +34,83 @@ func refineOutput(output []byte) (float64, error) {
return value, nil
}

func collectSensors() ([]sensorMeasurement, error) {
func collectSysctlSensors() []sensorMeasurement {
var measurements []sensorMeasurement
for k, v := range sensorOIDS {
output, err := exec.Command("sysctl", "-n", k).Output()
if err != nil {
return nil, fmt.Errorf("failed to execute 'sysctl' command: %v", err)
continue
}

value, err := refineOutput(output)
if err != nil {
return nil, fmt.Errorf("failed to execute 'sysctl' command: %v", err)
continue
}

measurements = append(measurements, sensorMeasurement{v, value})
}

return measurements
}

func collectNvidiaSensors() []sensorMeasurement {
var measurements []sensorMeasurement

info, _ := nvidiasmi.New()
if info.HasGPU() {
for i := range info.GPUS {
gpu := info.GPUS[i]
var s sensorMeasurement
s.name = gpu.ProductName + " " + strconv.Itoa(i)
s.temperature, _ = strconv.ParseFloat(strings.ReplaceAll(gpu.GpuTemp, " C", ""), 10)
measurements = append(measurements, s)
}
}
return measurements, nil

return measurements
}

func (self *TempWidget) update() {
sensors, err := collectSensors()
if err != nil {
log.Printf("error recieved from gopsutil: %v", err)
func collectAMDGPUSensors() []sensorMeasurement {
var measurments []sensorMeasurement

return measurments
}

func collectGPUSensors() []sensorMeasurement {
var measurements []sensorMeasurement

measurements = append(measurements, collectSysctlSensors()...)
measurements = append(measurements, collectNvidiaSensors()...)
measurements = append(measurements, collectAMDGPUSensors()...)

return measurements
}

func collectSensors() []sensorMeasurement {
var measurements []sensorMeasurement
for k, v := range sensorOIDS {
output, err := exec.Command("sysctl", "-n", k).Output()
if err != nil {
continue
}

value, err := refineOutput(output)
if err != nil {
continue
}

measurements = append(measurements, sensorMeasurement{v, value})
}

measurements = append(measurements, collectGPUSensors()...)

return measurements

}

func (self *TempWidget) update() {
sensors := collectSensors()

for _, sensor := range sensors {
switch self.TempScale {
case Fahrenheit:
Expand Down