From 69f439eff387a6ecb52734e400b297a3c85f2285 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Tue, 21 Sep 2021 08:35:19 +0200 Subject: New upstream version 3.1.0 --- freebsd/Platform.c | 69 ++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 36 deletions(-) (limited to 'freebsd/Platform.c') diff --git a/freebsd/Platform.c b/freebsd/Platform.c index c74ab6d..527a455 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -5,7 +5,9 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -#include "Platform.h" +#include "config.h" // IWYU pragma: keep + +#include "freebsd/Platform.h" #include #include @@ -29,20 +31,22 @@ in the source distribution for its full text. #include "DateMeter.h" #include "DateTimeMeter.h" #include "DiskIOMeter.h" -#include "FreeBSDProcess.h" -#include "FreeBSDProcessList.h" #include "HostnameMeter.h" #include "LoadAverageMeter.h" #include "Macros.h" #include "MemoryMeter.h" +#include "MemorySwapMeter.h" #include "Meter.h" #include "NetworkIOMeter.h" #include "ProcessList.h" #include "Settings.h" #include "SwapMeter.h" +#include "SysArchMeter.h" #include "TasksMeter.h" #include "UptimeMeter.h" #include "XUtils.h" +#include "freebsd/FreeBSDProcess.h" +#include "freebsd/FreeBSDProcessList.h" #include "zfs/ZfsArcMeter.h" #include "zfs/ZfsCompressedArcMeter.h" @@ -97,10 +101,12 @@ const MeterClass* const Platform_meterTypes[] = { &LoadMeter_class, &MemoryMeter_class, &SwapMeter_class, + &MemorySwapMeter_class, &TasksMeter_class, &UptimeMeter_class, &BatteryMeter_class, &HostnameMeter_class, + &SysArchMeter_class, &AllCPUsMeter_class, &AllCPUs2Meter_class, &AllCPUs4Meter_class, @@ -136,7 +142,7 @@ void Platform_setBindings(Htop_Action* keys) { int Platform_getUptime() { struct timeval bootTime, currTime; - int mib[2] = { CTL_KERN, KERN_BOOTTIME }; + const int mib[2] = { CTL_KERN, KERN_BOOTTIME }; size_t size = sizeof(bootTime); int err = sysctl(mib, 2, &bootTime, &size, NULL, 0); @@ -150,7 +156,7 @@ int Platform_getUptime() { void Platform_getLoadAverage(double* one, double* five, double* fifteen) { struct loadavg loadAverage; - int mib[2] = { CTL_VM, VM_LOADAVG }; + const int mib[2] = { CTL_VM, VM_LOADAVG }; size_t size = sizeof(loadAverage); int err = sysctl(mib, 2, &loadAverage, &size, NULL, 0); @@ -175,9 +181,9 @@ int Platform_getMaxPid() { return maxPid; } -double Platform_setCPUValues(Meter* this, int cpu) { +double Platform_setCPUValues(Meter* this, unsigned int cpu) { const FreeBSDProcessList* fpl = (const FreeBSDProcessList*) this->pl; - int cpus = this->pl->cpuCount; + unsigned int cpus = this->pl->activeCPUs; const CPUData* cpuData; if (cpus == 1) { @@ -205,26 +211,28 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = CLAMP(percent, 0.0, 100.0); - v[CPU_METER_FREQUENCY] = NAN; - v[CPU_METER_TEMPERATURE] = NAN; + v[CPU_METER_FREQUENCY] = cpuData->frequency; + v[CPU_METER_TEMPERATURE] = cpuData->temperature; return percent; } void Platform_setMemoryValues(Meter* this) { - // TODO const ProcessList* pl = this->pl; this->total = pl->totalMem; this->values[0] = pl->usedMem; this->values[1] = pl->buffersMem; - this->values[2] = pl->cachedMem; + // this->values[2] = "shared memory, like tmpfs and shm" + this->values[3] = pl->cachedMem; + // this->values[4] = "available memory" } void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; this->total = pl->totalSwap; this->values[0] = pl->usedSwap; + this->values[1] = NAN; } void Platform_setZfsArcValues(Meter* this) { @@ -240,7 +248,7 @@ void Platform_setZfsCompressedArcValues(Meter* this) { } char* Platform_getProcessEnv(pid_t pid) { - int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ENV, pid }; + const int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ENV, pid }; size_t capacity = ARG_MAX; char* env = xMalloc(capacity); @@ -261,14 +269,14 @@ char* Platform_getProcessEnv(pid_t pid) { } char* Platform_getInodeFilename(pid_t pid, ino_t inode) { - (void)pid; - (void)inode; - return NULL; + (void)pid; + (void)inode; + return NULL; } FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { - (void)pid; - return NULL; + (void)pid; + return NULL; } bool Platform_getDiskIO(DiskIOData* data) { @@ -285,7 +293,7 @@ bool Platform_getDiskIO(DiskIOData* data) { int count = current.dinfo->numdevs; - unsigned long int bytesReadSum = 0, bytesWriteSum = 0, timeSpendSum = 0; + unsigned long long int bytesReadSum = 0, bytesWriteSum = 0, timeSpendSum = 0; // get data for (int i = 0; i < count; i++) { @@ -311,24 +319,17 @@ bool Platform_getDiskIO(DiskIOData* data) { return true; } -bool Platform_getNetworkIO(unsigned long int* bytesReceived, - unsigned long int* packetsReceived, - unsigned long int* bytesTransmitted, - unsigned long int* packetsTransmitted) { - int r; - +bool Platform_getNetworkIO(NetworkIOData* data) { // get number of interfaces int count; size_t countLen = sizeof(count); const int countMib[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_SYSTEM, IFMIB_IFCOUNT }; - r = sysctl(countMib, ARRAYSIZE(countMib), &count, &countLen, NULL, 0); + int r = sysctl(countMib, ARRAYSIZE(countMib), &count, &countLen, NULL, 0); if (r < 0) return false; - - unsigned long int bytesReceivedSum = 0, packetsReceivedSum = 0, bytesTransmittedSum = 0, packetsTransmittedSum = 0; - + memset(data, 0, sizeof(NetworkIOData)); for (int i = 1; i <= count; i++) { struct ifmibdata ifmd; size_t ifmdLen = sizeof(ifmd); @@ -342,16 +343,12 @@ bool Platform_getNetworkIO(unsigned long int* bytesReceived, if (ifmd.ifmd_flags & IFF_LOOPBACK) continue; - bytesReceivedSum += ifmd.ifmd_data.ifi_ibytes; - packetsReceivedSum += ifmd.ifmd_data.ifi_ipackets; - bytesTransmittedSum += ifmd.ifmd_data.ifi_obytes; - packetsTransmittedSum += ifmd.ifmd_data.ifi_opackets; + data->bytesReceived += ifmd.ifmd_data.ifi_ibytes; + data->packetsReceived += ifmd.ifmd_data.ifi_ipackets; + data->bytesTransmitted += ifmd.ifmd_data.ifi_obytes; + data->packetsTransmitted += ifmd.ifmd_data.ifi_opackets; } - *bytesReceived = bytesReceivedSum; - *packetsReceived = packetsReceivedSum; - *bytesTransmitted = bytesTransmittedSum; - *packetsTransmitted = packetsTransmittedSum; return true; } -- cgit v1.2.3