summaryrefslogtreecommitdiffstats
path: root/linux/Platform.c
diff options
context:
space:
mode:
Diffstat (limited to 'linux/Platform.c')
-rw-r--r--linux/Platform.c68
1 files changed, 65 insertions, 3 deletions
diff --git a/linux/Platform.c b/linux/Platform.c
index ee5abf81..a5704d23 100644
--- a/linux/Platform.c
+++ b/linux/Platform.c
@@ -9,6 +9,7 @@ in the source distribution for its full text.
#include "IOPriority.h"
#include "IOPriorityPanel.h"
#include "LinuxProcess.h"
+#include "LinuxProcessList.h"
#include "Battery.h"
#include "Meter.h"
@@ -29,14 +30,15 @@ in the source distribution for its full text.
#include "BatteryMeter.h"
}*/
-static Htop_Reaction Platform_actionSetIOPriority(Panel* panel, ProcessList* pl, Header* header) {
- (void) panel, (void) pl;
+static Htop_Reaction Platform_actionSetIOPriority(State* st) {
+ Panel* panel = st->panel;
+
LinuxProcess* p = (LinuxProcess*) Panel_getSelected(panel);
if (!p) return HTOP_OK;
IOPriority ioprio = p->ioPriority;
Panel* ioprioPanel = IOPriorityPanel_new(ioprio);
const char* fuFunctions[] = {"Set ", "Cancel ", NULL};
- void* set = Action_pickFromVector(panel, ioprioPanel, 21, fuFunctions, header);
+ void* set = Action_pickFromVector(st, ioprioPanel, 21, fuFunctions);
if (set) {
IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel);
bool ok = Action_foreachProcess(panel, (Action_ForeachProcessFn) LinuxProcess_setIOPriority, (size_t) ioprio, NULL);
@@ -120,3 +122,63 @@ void Platform_getBatteryLevel(double* level, ACPresence* isOnAC) {
*isOnAC = Battery_isOnAC();
*level = percent;
}
+
+double Platform_setCPUValues(Meter* this, int cpu) {
+ LinuxProcessList* pl = (LinuxProcessList*) this->pl;
+ CPUData* cpuData = &(pl->cpus[cpu]);
+ double total = (double) ( cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod);
+ double percent;
+ double* v = this->values;
+ v[0] = cpuData->nicePeriod / total * 100.0;
+ v[1] = cpuData->userPeriod / total * 100.0;
+ if (this->pl->settings->detailedCPUTime) {
+ v[2] = cpuData->systemPeriod / total * 100.0;
+ v[3] = cpuData->irqPeriod / total * 100.0;
+ v[4] = cpuData->softIrqPeriod / total * 100.0;
+ v[5] = cpuData->stealPeriod / total * 100.0;
+ v[6] = cpuData->guestPeriod / total * 100.0;
+ v[7] = cpuData->ioWaitPeriod / total * 100.0;
+ Meter_setItems(this, 8);
+ if (this->pl->settings->accountGuestInCPUMeter) {
+ percent = v[0]+v[1]+v[2]+v[3]+v[4]+v[5]+v[6];
+ } else {
+ percent = v[0]+v[1]+v[2]+v[3]+v[4];
+ }
+ } else {
+ v[2] = cpuData->systemAllPeriod / total * 100.0;
+ v[3] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0;
+ Meter_setItems(this, 4);
+ percent = v[0]+v[1]+v[2]+v[3];
+ }
+ percent = MIN(100.0, MAX(0.0, percent));
+ if (isnan(percent)) percent = 0.0;
+ return percent;
+}
+
+void Platform_setMemoryValues(Meter* this) {
+ LinuxProcessList* pl = (LinuxProcessList*) this->pl;
+ long int usedMem = pl->usedMem;
+ long int buffersMem = pl->buffersMem;
+ long int cachedMem = pl->cachedMem;
+ usedMem -= buffersMem + cachedMem;
+ this->total = pl->totalMem;
+ this->values[0] = usedMem;
+ this->values[1] = buffersMem;
+ this->values[2] = cachedMem;
+}
+
+void Platform_setSwapValues(Meter* this) {
+ LinuxProcessList* pl = (LinuxProcessList*) this->pl;
+ this->total = pl->totalSwap;
+ this->values[0] = pl->usedSwap;
+}
+
+void Platform_setTasksValues(Meter* this) {
+ LinuxProcessList* pl = (LinuxProcessList*) this->pl;
+ this->values[0] = pl->kernelThreads;
+ this->values[1] = pl->userlandThreads;
+ this->values[2] = pl->totalTasks - pl->kernelThreads - pl->userlandThreads;
+ this->values[3] = pl->runningTasks;
+ if (pl->totalTasks > this->total)
+ this->total = pl->totalTasks;
+}