2014-11-27 18:27:34 +00:00
|
|
|
/*
|
2014-11-27 21:33:37 +00:00
|
|
|
htop - freebsd/Platform.c
|
2014-11-27 18:27:34 +00:00
|
|
|
(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"
|
2014-11-27 21:33:37 +00:00
|
|
|
#include "Meter.h"
|
|
|
|
#include "CPUMeter.h"
|
|
|
|
#include "MemoryMeter.h"
|
|
|
|
#include "SwapMeter.h"
|
|
|
|
#include "TasksMeter.h"
|
|
|
|
#include "LoadAverageMeter.h"
|
|
|
|
#include "UptimeMeter.h"
|
|
|
|
#include "ClockMeter.h"
|
|
|
|
#include "HostnameMeter.h"
|
2015-03-16 06:13:42 +00:00
|
|
|
#include "FreeBSDProcess.h"
|
2014-11-27 18:27:34 +00:00
|
|
|
|
2014-11-27 21:44:20 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/time.h>
|
2014-11-27 22:03:29 +00:00
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <vm/vm_param.h>
|
2014-11-27 21:44:20 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
2014-11-27 18:27:34 +00:00
|
|
|
/*{
|
|
|
|
#include "Action.h"
|
2014-11-27 23:07:42 +00:00
|
|
|
#include "BatteryMeter.h"
|
2015-03-16 06:13:42 +00:00
|
|
|
|
|
|
|
extern ProcessFieldData Process_fields[];
|
|
|
|
|
2014-11-27 18:27:34 +00:00
|
|
|
}*/
|
|
|
|
|
2015-03-16 06:13:42 +00:00
|
|
|
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
|
|
|
|
|
|
|
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
|
|
|
|
2014-11-27 18:27:34 +00:00
|
|
|
void Platform_setBindings(Htop_Action* keys) {
|
|
|
|
(void) keys;
|
|
|
|
}
|
|
|
|
|
2014-11-27 21:33:37 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2014-11-27 21:44:20 +00:00
|
|
|
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);
|
|
|
|
}
|
2014-11-27 22:03:29 +00:00
|
|
|
|
|
|
|
void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
|
|
|
|
struct loadavg loadAverage;
|
|
|
|
int mib[2] = { CTL_VM, VM_LOADAVG };
|
|
|
|
size_t size = sizeof(loadAverage);
|
|
|
|
|
|
|
|
int err = sysctl(mib, 2, &loadAverage, &size, NULL, 0);
|
|
|
|
if (err) {
|
|
|
|
*one = 0;
|
|
|
|
*five = 0;
|
|
|
|
*fifteen = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*one = (double) loadAverage.ldavg[0] / loadAverage.fscale;
|
|
|
|
*five = (double) loadAverage.ldavg[1] / loadAverage.fscale;
|
|
|
|
*fifteen = (double) loadAverage.ldavg[2] / loadAverage.fscale;
|
|
|
|
}
|
2014-11-27 22:18:01 +00:00
|
|
|
|
|
|
|
int Platform_getMaxPid() {
|
|
|
|
int maxPid;
|
|
|
|
size_t size = sizeof(maxPid);
|
|
|
|
int err = sysctlbyname("kern.pid_max", &maxPid, &size, NULL, 0);
|
|
|
|
if (err) {
|
|
|
|
return 99999;
|
|
|
|
}
|
|
|
|
return maxPid;
|
|
|
|
}
|
2014-11-27 23:07:42 +00:00
|
|
|
|
2015-03-16 06:13:42 +00:00
|
|
|
double Platform_setCPUValues(Meter* this, int cpu) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void Platform_setMemoryValues(Meter* this) {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void Platform_setSwapValues(Meter* this) {
|
2014-11-27 23:07:42 +00:00
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2015-03-16 06:13:42 +00:00
|
|
|
void Platform_setTasksValues(Meter* this) {
|
|
|
|
// TODO
|
|
|
|
}
|