2014-11-24 20:55:49 +00:00
|
|
|
/*
|
|
|
|
htop - linux/Platform.c
|
|
|
|
(C) 2014 Hisham H. Muhammad
|
|
|
|
Released under the GNU GPL, see the COPYING file
|
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
2014-11-24 21:22:50 +00:00
|
|
|
#include "Platform.h"
|
2014-11-24 20:55:49 +00:00
|
|
|
#include "IOPriority.h"
|
|
|
|
#include "IOPriorityPanel.h"
|
2014-11-24 21:22:50 +00:00
|
|
|
#include "LinuxProcess.h"
|
2014-11-27 21:18:14 +00:00
|
|
|
#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"
|
2014-11-24 21:22:50 +00:00
|
|
|
|
2014-11-27 21:41:14 +00:00
|
|
|
#include <math.h>
|
2014-11-27 21:57:24 +00:00
|
|
|
#include <assert.h>
|
2014-11-27 21:41:14 +00:00
|
|
|
|
2014-11-24 21:22:50 +00:00
|
|
|
/*{
|
|
|
|
#include "Action.h"
|
|
|
|
}*/
|
2014-11-24 20:55:49 +00:00
|
|
|
|
|
|
|
static Htop_Reaction Platform_actionSetIOPriority(Panel* panel, ProcessList* pl, Header* header) {
|
|
|
|
(void) panel, (void) pl;
|
2014-11-24 21:22:50 +00:00
|
|
|
LinuxProcess* p = (LinuxProcess*) Panel_getSelected(panel);
|
2014-11-24 20:55:49 +00:00
|
|
|
if (!p) return HTOP_OK;
|
|
|
|
IOPriority ioprio = p->ioPriority;
|
|
|
|
Panel* ioprioPanel = IOPriorityPanel_new(ioprio);
|
|
|
|
const char* fuFunctions[] = {"Set ", "Cancel ", NULL};
|
2014-11-24 21:22:50 +00:00
|
|
|
void* set = Action_pickFromVector(panel, ioprioPanel, 21, fuFunctions, header);
|
2014-11-24 20:55:49 +00:00
|
|
|
if (set) {
|
|
|
|
IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel);
|
2014-11-24 21:22:50 +00:00
|
|
|
bool ok = Action_foreachProcess(panel, (Action_ForeachProcessFn) LinuxProcess_setIOPriority, (size_t) ioprio, NULL);
|
2014-11-24 20:55:49 +00:00
|
|
|
if (!ok)
|
|
|
|
beep();
|
|
|
|
}
|
|
|
|
Panel_delete((Object*)ioprioPanel);
|
|
|
|
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Platform_setBindings(Htop_Action* keys) {
|
|
|
|
keys['i'] = Platform_actionSetIOPriority;
|
|
|
|
}
|
2014-11-27 21:18:14 +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:41:14 +00:00
|
|
|
int Platform_getUptime() {
|
|
|
|
double uptime = 0;
|
|
|
|
FILE* fd = fopen(PROCDIR "/uptime", "r");
|
|
|
|
if (fd) {
|
|
|
|
fscanf(fd, "%64lf", &uptime);
|
|
|
|
fclose(fd);
|
|
|
|
}
|
2014-11-27 21:46:01 +00:00
|
|
|
return (int) floor(uptime);
|
2014-11-27 21:41:14 +00:00
|
|
|
}
|
2014-11-27 21:57:24 +00:00
|
|
|
|
|
|
|
void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
|
|
|
|
int activeProcs, totalProcs, lastProc;
|
|
|
|
*one = 0; *five = 0; *fifteen = 0;
|
|
|
|
FILE *fd = fopen(PROCDIR "/loadavg", "r");
|
|
|
|
if (fd) {
|
|
|
|
int total = fscanf(fd, "%32lf %32lf %32lf %32d/%32d %32d", one, five, fifteen,
|
|
|
|
&activeProcs, &totalProcs, &lastProc);
|
|
|
|
(void) total;
|
|
|
|
assert(total == 6);
|
|
|
|
fclose(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|