From 3fcab5a42054c84895c4f6da5097360d35414fde Mon Sep 17 00:00:00 2001 From: "Sean E. Russell" Date: Wed, 22 Apr 2020 13:33:51 -0500 Subject: [PATCH] Switch from smc.c to iSMC. --- CHANGELOG.md | 1 + cmd/gotop/main.go | 3 ++- devices/temp_darwin.go | 41 +++++++++----------------------------- go.mod | 1 + go.sum | 4 ++++ make.sh => scripts/make.sh | 0 scripts/makeDarwin.sh | 11 ++++++++++ 7 files changed, 28 insertions(+), 33 deletions(-) rename make.sh => scripts/make.sh (100%) create mode 100755 scripts/makeDarwin.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d2670e..f61b2c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 - Memory line colors were inconsistently assigned (#91) - 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 diff --git a/cmd/gotop/main.go b/cmd/gotop/main.go index 5728128..f44d7a2 100644 --- a/cmd/gotop/main.go +++ b/cmd/gotop/main.go @@ -38,7 +38,7 @@ const ( var ( // TODO: Set this at compile time; having to check this in sucks. - Version = "3.6.0" + Version = "3.6.dev" conf gotop.Config help *w.HelpMenu 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: 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: Add fans func parseArgs(conf *gotop.Config) error { cds := conf.ConfigDir.QueryFolders(configdir.All) cpaths := make([]string, len(cds)) diff --git a/devices/temp_darwin.go b/devices/temp_darwin.go index e60b4be..4e068a4 100644 --- a/devices/temp_darwin.go +++ b/devices/temp_darwin.go @@ -2,45 +2,22 @@ package devices -// #cgo LDFLAGS: -framework IOKit -// #include "include/smc.c" -import "C" +import smc "github.com/xxxserxxx/iSMC" func init() { RegisterTemp(update) + ts = make(map[string]float32) } +var ts map[string]float32 + func update(temps map[string]int) map[string]error { - temperatureKeys := map[string]string{ - C.AMBIENT_AIR_0: "ambient_air_0", - C.AMBIENT_AIR_1: "ambient_air_1", - 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", + err := smc.GetTemp(ts) + if err != nil { + return map[string]error{"temps": err} } - - C.open_smc() - defer C.close_smc() - - for key, val := range temperatureKeys { - temps[val] = int(C.get_tmp(C.CString(key), C.CELSIUS)) + for k, v := range ts { + temps[k] = int(v + 0.5) } - return nil } diff --git a/go.mod b/go.mod index 2b53f3a..c81ba92 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/shirou/gopsutil v2.18.11+incompatible github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect github.com/stretchr/testify v1.4.0 + github.com/xxxserxxx/iSMC v1.0.1 howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect ) diff --git a/go.sum b/go.sum index 0a20cb4..c3bef32 100644 --- a/go.sum +++ b/go.sum @@ -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/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/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.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= 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.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= 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/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= diff --git a/make.sh b/scripts/make.sh similarity index 100% rename from make.sh rename to scripts/make.sh diff --git a/scripts/makeDarwin.sh b/scripts/makeDarwin.sh new file mode 100755 index 0000000..638f58a --- /dev/null +++ b/scripts/makeDarwin.sh @@ -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