Switch from smc.c to iSMC.

This commit is contained in:
Sean E. Russell 2020-04-22 13:33:51 -05:00
parent dfa7098ad8
commit 3fcab5a420
7 changed files with 28 additions and 33 deletions

View File

@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Merged fix from @markuspeloquin for custom color scheme loading crash - Merged fix from @markuspeloquin for custom color scheme loading crash
- Memory line colors were inconsistently assigned (#91) - Memory line colors were inconsistently assigned (#91)
- The disk code was truncating values instead of rounding (#90) - The disk code was truncating values instead of rounding (#90)
- Temperatures on Darwin were all over the place, and wrong (#48)
## [3.5.1] - 2020-04-09 ## [3.5.1] - 2020-04-09

View File

@ -38,7 +38,7 @@ const (
var ( var (
// TODO: Set this at compile time; having to check this in sucks. // TODO: Set this at compile time; having to check this in sucks.
Version = "3.6.0" Version = "3.6.dev"
conf gotop.Config conf gotop.Config
help *w.HelpMenu help *w.HelpMenu
bar *w.StatusBar bar *w.StatusBar
@ -51,6 +51,7 @@ var (
// TODO: state:deferred 157 FreeBSD fixes & Nvidia GPU support (kraust/master). Significant CPU use impact for NVidia changes. // TODO: state:deferred 157 FreeBSD fixes & Nvidia GPU support (kraust/master). Significant CPU use impact for NVidia changes.
// TODO: Virtual devices from Prometeus metrics @feature // TODO: Virtual devices from Prometeus metrics @feature
// TODO: Abstract out the UI toolkit. mum4k/termdash, VladimirMarkelov/clui, gcla/gowid, rivo/tview, marcusolsson/tui-go might work better for some OS/Archs. Performance/memory use comparison would be interesting. // TODO: Abstract out the UI toolkit. mum4k/termdash, VladimirMarkelov/clui, gcla/gowid, rivo/tview, marcusolsson/tui-go might work better for some OS/Archs. Performance/memory use comparison would be interesting.
// TODO: Add fans
func parseArgs(conf *gotop.Config) error { func parseArgs(conf *gotop.Config) error {
cds := conf.ConfigDir.QueryFolders(configdir.All) cds := conf.ConfigDir.QueryFolders(configdir.All)
cpaths := make([]string, len(cds)) cpaths := make([]string, len(cds))

View File

@ -2,45 +2,22 @@
package devices package devices
// #cgo LDFLAGS: -framework IOKit import smc "github.com/xxxserxxx/iSMC"
// #include "include/smc.c"
import "C"
func init() { func init() {
RegisterTemp(update) RegisterTemp(update)
ts = make(map[string]float32)
} }
var ts map[string]float32
func update(temps map[string]int) map[string]error { func update(temps map[string]int) map[string]error {
temperatureKeys := map[string]string{ err := smc.GetTemp(ts)
C.AMBIENT_AIR_0: "ambient_air_0", if err != nil {
C.AMBIENT_AIR_1: "ambient_air_1", return map[string]error{"temps": err}
C.CPU_0_DIODE: "cpu_0_diode",
C.CPU_0_HEATSINK: "cpu_0_heatsink",
C.CPU_0_PROXIMITY: "cpu_0_proximity",
C.ENCLOSURE_BASE_0: "enclosure_base_0",
C.ENCLOSURE_BASE_1: "enclosure_base_1",
C.ENCLOSURE_BASE_2: "enclosure_base_2",
C.ENCLOSURE_BASE_3: "enclosure_base_3",
C.GPU_0_DIODE: "gpu_0_diode",
C.GPU_0_HEATSINK: "gpu_0_heatsink",
C.GPU_0_PROXIMITY: "gpu_0_proximity",
C.HARD_DRIVE_BAY: "hard_drive_bay",
C.MEMORY_SLOT_0: "memory_slot_0",
C.MEMORY_SLOTS_PROXIMITY: "memory_slots_proximity",
C.NORTHBRIDGE: "northbridge",
C.NORTHBRIDGE_DIODE: "northbridge_diode",
C.NORTHBRIDGE_PROXIMITY: "northbridge_proximity",
C.THUNDERBOLT_0: "thunderbolt_0",
C.THUNDERBOLT_1: "thunderbolt_1",
C.WIRELESS_MODULE: "wireless_module",
} }
for k, v := range ts {
C.open_smc() temps[k] = int(v + 0.5)
defer C.close_smc()
for key, val := range temperatureKeys {
temps[val] = int(C.get_tmp(C.CString(key), C.CELSIUS))
} }
return nil return nil
} }

1
go.mod
View File

@ -13,6 +13,7 @@ require (
github.com/shirou/gopsutil v2.18.11+incompatible github.com/shirou/gopsutil v2.18.11+incompatible
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
github.com/stretchr/testify v1.4.0 github.com/stretchr/testify v1.4.0
github.com/xxxserxxx/iSMC v1.0.1
howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect
) )

4
go.sum
View File

@ -63,6 +63,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d h1:x3S6kxmy49zXVVyhcnrFqxvNVCBPb2KZ9hV2RBdS840= github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d h1:x3S6kxmy49zXVVyhcnrFqxvNVCBPb2KZ9hV2RBdS840=
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
github.com/panotza/gosmc v0.0.0-20190601191911-810267459a2a h1:P0QSyHOubLI2e6hccBBEjVX0vPWXoXui5QCAVNWdJSk=
github.com/panotza/gosmc v0.0.0-20190601191911-810267459a2a/go.mod h1:u8Q8dpnMAam0MElxP2KjEROzXMk9G8X168RTpAZ9tPc=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@ -98,6 +100,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/xxxserxxx/iSMC v1.0.1 h1:M9Gkwnnkl+evvnugoB5yRYrbUP+cRIVOPM+xrHZc3Hs=
github.com/xxxserxxx/iSMC v1.0.1/go.mod h1:TGgNjU7BF2DZSuxiTft+BdzxzcujFJYqFfMCzcTl/aY=
golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045/go.mod h1:cYlCBUl1MsqxdiKgmc4uh7TxZfWSFLOGSRR090WDxt8= golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045/go.mod h1:cYlCBUl1MsqxdiKgmc4uh7TxZfWSFLOGSRR090WDxt8=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

11
scripts/makeDarwin.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
GOOS=darwin
GOARCH=amd64
CGO_ENABLED=1
MACOSX_DEPLOYMENT_TARGET=10.10.0
CC=o64-clang
CXX=o64-clang++
export GOOS GOARCH CGO_ENABLED MACOSX_DEPLOYMENT_TARGET CC CXX
go build -o gotop.darwin ./cmd/gotop