mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-13 04:34:35 +03:00
Builds on Linux again!
This commit is contained in:
@ -6,9 +6,17 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Process.h"
|
||||
#include "ProcessList.h"
|
||||
#include "LinuxProcess.h"
|
||||
#include "CRT.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
/*{
|
||||
|
||||
#include "IOPriority.h"
|
||||
|
||||
typedef struct LinuxProcess_ {
|
||||
Process super;
|
||||
IOPriority ioPriority;
|
||||
@ -24,26 +32,29 @@ effort class. The priority within the best effort class will be
|
||||
dynamically derived from the cpu nice level of the process:
|
||||
io_priority = (cpu_nice + 20) / 5. -- From ionice(1) man page
|
||||
*/
|
||||
#define LinuxProcess_effectiveIOPriority(p_) (IOPriority_class(p_->ioPriority) == IOPRIO_CLASS_NONE ? IOPriority_tuple(IOPRIO_CLASS_BE, (p_->nice + 20) / 5) : p_->ioPriority)
|
||||
#define LinuxProcess_effectiveIOPriority(p_) (IOPriority_class(p_->ioPriority) == IOPRIO_CLASS_NONE ? IOPriority_tuple(IOPRIO_CLASS_BE, (p_->super.nice + 20) / 5) : p_->ioPriority)
|
||||
|
||||
IOPriority LinuxProcess_updateIOPriority(Process* this) {
|
||||
IOPriority ioprio = syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, this->pid);
|
||||
IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this) {
|
||||
IOPriority ioprio = syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, this->super.pid);
|
||||
this->ioPriority = ioprio;
|
||||
return ioprio;
|
||||
}
|
||||
|
||||
bool LinuxProcess_setIOPriority(Process* this, IOPriority ioprio) {
|
||||
syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, this->pid, ioprio);
|
||||
return (Process_updateIOPriority(this) == ioprio);
|
||||
bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio) {
|
||||
syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, this->super.pid, ioprio);
|
||||
return (LinuxProcess_updateIOPriority(this) == ioprio);
|
||||
}
|
||||
|
||||
void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
void LinuxProcess_writeField(LinuxProcess* this, RichString* str, ProcessField field) {
|
||||
char buffer[256]; buffer[255] = '\0';
|
||||
int attr = CRT_colors[DEFAULT_COLOR];
|
||||
int n = sizeof(buffer) - 1;
|
||||
switch (field) {
|
||||
case IO_PRIORITY: {
|
||||
int klass = IOPriority_class(this->ioPriority);
|
||||
if (klass == IOPRIO_CLASS_NONE) {
|
||||
// see note [1] above
|
||||
snprintf(buffer, n, "B%1d ", (int) (this->nice + 20) / 5);
|
||||
snprintf(buffer, n, "B%1d ", (int) (this->super.nice + 20) / 5);
|
||||
} else if (klass == IOPRIO_CLASS_BE) {
|
||||
snprintf(buffer, n, "B%1d ", IOPriority_data(this->ioPriority));
|
||||
} else if (klass == IOPRIO_CLASS_RT) {
|
||||
@ -61,7 +72,6 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field)
|
||||
snprintf(buffer, n, "- ");
|
||||
}
|
||||
RichString_append(str, attr, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
long LinuxProcess_compare(const void* v1, const void* v2) {
|
||||
@ -76,10 +86,8 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
|
||||
}
|
||||
switch (pl->sortKey) {
|
||||
case IO_PRIORITY:
|
||||
return Process_effectiveIOPriority(p1) - Process_effectiveIOPriority(p2);
|
||||
return LinuxProcess_effectiveIOPriority(p1) - LinuxProcess_effectiveIOPriority(p2);
|
||||
default:
|
||||
return (p1->pid - p2->pid);
|
||||
return (p1->super.pid - p2->super.pid);
|
||||
}
|
||||
test_diff:
|
||||
return (diff > 0) ? 1 : (diff < 0 ? -1 : 0);
|
||||
}
|
||||
|
@ -5,10 +5,32 @@ Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "ProcessList.h"
|
||||
#include "LinuxProcessList.h"
|
||||
#include "LinuxProcess.h"
|
||||
#include "CRT.h"
|
||||
#include "String.h"
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
/*{
|
||||
|
||||
#include "ProcessList.h"
|
||||
|
||||
#ifndef PROCDIR
|
||||
#define PROCDIR "/proc"
|
||||
#endif
|
||||
@ -463,7 +485,7 @@ static bool LinuxProcessList_processEntries(ProcessList* this, const char* dirna
|
||||
if (! LinuxProcessList_readStatFile(process, dirname, name, command))
|
||||
goto errorReadingProcess;
|
||||
if (this->flags & PROCESS_FLAG_IOPRIO)
|
||||
Process_updateIOPriority(process);
|
||||
LinuxProcess_updateIOPriority((LinuxProcess*)process);
|
||||
float percent_cpu = (process->utime + process->stime - lasttimes) / period * 100.0;
|
||||
process->percent_cpu = MAX(MIN(percent_cpu, cpus*100.0), 0.0);
|
||||
if (isnan(process->percent_cpu)) process->percent_cpu = 0.0;
|
||||
|
@ -5,20 +5,26 @@ Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Platform.h"
|
||||
#include "IOPriority.h"
|
||||
#include "IOPriorityPanel.h"
|
||||
#include "LinuxProcess.h"
|
||||
|
||||
/*{
|
||||
#include "Action.h"
|
||||
}*/
|
||||
|
||||
static Htop_Reaction Platform_actionSetIOPriority(Panel* panel, ProcessList* pl, Header* header) {
|
||||
(void) panel, (void) pl;
|
||||
Process* p = (Process*) Panel_getSelected(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 = pickFromVector(panel, ioprioPanel, 21, fuFunctions, header);
|
||||
void* set = Action_pickFromVector(panel, ioprioPanel, 21, fuFunctions, header);
|
||||
if (set) {
|
||||
IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel);
|
||||
bool ok = Action_foreachProcess(panel, (Action_ForeachProcessFn) Process_setIOPriority, (size_t) ioprio, NULL);
|
||||
bool ok = Action_foreachProcess(panel, (Action_ForeachProcessFn) LinuxProcess_setIOPriority, (size_t) ioprio, NULL);
|
||||
if (!ok)
|
||||
beep();
|
||||
}
|
||||
|
Reference in New Issue
Block a user