| /* |
| htop - freebsd/Platform.c |
| (C) 2014 Hisham H. Muhammad |
| Released under the GNU GPL, see the COPYING file |
| in the source distribution for its full text. |
| */ |
| |
| #include "Platform.h" |
| #include "Meter.h" |
| #include "CPUMeter.h" |
| #include "MemoryMeter.h" |
| #include "SwapMeter.h" |
| #include "TasksMeter.h" |
| #include "LoadAverageMeter.h" |
| #include "UptimeMeter.h" |
| #include "BatteryMeter.h" |
| #include "ClockMeter.h" |
| #include "HostnameMeter.h" |
| |
| #include <sys/types.h> |
| #include <sys/sysctl.h> |
| #include <sys/time.h> |
| #include <time.h> |
| |
| /*{ |
| #include "Action.h" |
| }*/ |
| |
| void Platform_setBindings(Htop_Action* keys) { |
| (void) keys; |
| } |
| |
| MeterClass* Platform_meterTypes[] = { |
| &CPUMeter_class, |
| &ClockMeter_class, |
| &LoadAverageMeter_class, |
| &LoadMeter_class, |
| &MemoryMeter_class, |
| &SwapMeter_class, |
| &TasksMeter_class, |
| &UptimeMeter_class, |
| &BatteryMeter_class, |
| &HostnameMeter_class, |
| &AllCPUsMeter_class, |
| &AllCPUs2Meter_class, |
| &LeftCPUsMeter_class, |
| &RightCPUsMeter_class, |
| &LeftCPUs2Meter_class, |
| &RightCPUs2Meter_class, |
| &BlankMeter_class, |
| NULL |
| }; |
| |
| int Platform_getUptime() { |
| struct timeval bootTime, currTime; |
| int mib[2] = { CTL_KERN, KERN_BOOTTIME }; |
| size_t size = sizeof(bootTime); |
| |
| int err = sysctl(mib, 2, &bootTime, &size, NULL, 0); |
| if (err) { |
| return -1; |
| } |
| gettimeofday(&currTime, NULL); |
| |
| return (int) difftime(currTime.tv_sec, bootTime.tv_sec); |
| } |