htop/unsupported/UnsupportedProcessList.c

91 lines
2.2 KiB
C
Raw Normal View History

/*
htop - UnsupportedProcessList.c
(C) 2014 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text.
*/
2021-01-28 17:19:38 +00:00
#include "UnsupportedProcessList.h"
#include <stdlib.h>
2015-07-12 16:26:33 +00:00
#include <string.h>
2021-01-28 17:19:38 +00:00
#include "ProcessList.h"
#include "UnsupportedProcess.h"
Add a new DynamicMeter class for runtime Meter extension This commit is based on exploratory work by Sohaib Mohamed. The end goal is two-fold - to support addition of Meters we build via configuration files for both the PCP platform and for scripts ( https://github.com/htop-dev/htop/issues/526 ) Here, we focus on generic code and the PCP support. A new class DynamicMeter is introduced - it uses the special case 'param' field handling that previously was used only by the CPUMeter, such that every runtime-configured Meter is given a unique identifier. Unlike with the CPUMeter this is used internally only. When reading/writing to htoprc instead of CPU(N) - where N is an integer param (CPU number) - we use the string name for each meter. For example, if we have a configuration for a DynamicMeter for some Redis metrics, we might read and write "Dynamic(redis)". This identifier is subsequently matched (back) up to the configuration file so we're able to re-create arbitrary user configurations. The PCP platform configuration file format is fairly simple. We expand configs from several directories, including the users homedir alongside htoprc (below htop/meters/) and also /etc/pcp/htop/meters. The format will be described via a new pcp-htop(5) man page, but its basically ini-style and each Meter has one or more metric expressions associated, as well as specifications for labels, color and so on via a dot separated notation for individual metrics within the Meter. A few initial sample configuration files are provided below ./pcp/meters that give the general idea. The PCP "derived" metric specification - see pmRegisterDerived(3) - is used as the syntax for specifying metrics in PCP DynamicMeters.
2021-06-23 07:44:56 +00:00
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* dynamicMeters, Hashtable* pidMatchList, uid_t userId) {
2016-02-02 14:53:02 +00:00
ProcessList* this = xCalloc(1, sizeof(ProcessList));
Add a new DynamicMeter class for runtime Meter extension This commit is based on exploratory work by Sohaib Mohamed. The end goal is two-fold - to support addition of Meters we build via configuration files for both the PCP platform and for scripts ( https://github.com/htop-dev/htop/issues/526 ) Here, we focus on generic code and the PCP support. A new class DynamicMeter is introduced - it uses the special case 'param' field handling that previously was used only by the CPUMeter, such that every runtime-configured Meter is given a unique identifier. Unlike with the CPUMeter this is used internally only. When reading/writing to htoprc instead of CPU(N) - where N is an integer param (CPU number) - we use the string name for each meter. For example, if we have a configuration for a DynamicMeter for some Redis metrics, we might read and write "Dynamic(redis)". This identifier is subsequently matched (back) up to the configuration file so we're able to re-create arbitrary user configurations. The PCP platform configuration file format is fairly simple. We expand configs from several directories, including the users homedir alongside htoprc (below htop/meters/) and also /etc/pcp/htop/meters. The format will be described via a new pcp-htop(5) man page, but its basically ini-style and each Meter has one or more metric expressions associated, as well as specifications for labels, color and so on via a dot separated notation for individual metrics within the Meter. A few initial sample configuration files are provided below ./pcp/meters that give the general idea. The PCP "derived" metric specification - see pmRegisterDerived(3) - is used as the syntax for specifying metrics in PCP DynamicMeters.
2021-06-23 07:44:56 +00:00
ProcessList_init(this, Class(Process), usersTable, dynamicMeters, pidMatchList, userId);
2019-10-31 16:39:12 +00:00
2021-01-28 17:19:38 +00:00
this->cpuCount = 1;
return this;
}
void ProcessList_delete(ProcessList* this) {
ProcessList_done(this);
free(this);
}
void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
// in pause mode only gather global data for meters (CPU/memory/...)
2020-11-01 00:09:51 +00:00
if (pauseProcessUpdate) {
return;
2020-11-01 00:09:51 +00:00
}
2020-10-31 21:14:27 +00:00
bool preExisting = true;
Process* proc;
proc = ProcessList_getProcess(super, 1, &preExisting, UnsupportedProcess_new);
/* Empty values */
proc->time = proc->time + 10;
proc->pid = 1;
proc->ppid = 1;
proc->tgid = 0;
Process_updateComm(proc, "commof16char");
Process_updateCmdline(proc, "<unsupported architecture>", 0, 0);
Process_updateExe(proc, "/path/to/executable");
2021-05-25 17:14:45 +00:00
if (proc->settings->flags & PROCESS_FLAG_CWD) {
proc->procCwd = "/current/working/directory";
}
2020-10-31 21:14:27 +00:00
proc->updated = true;
proc->state = 'R';
proc->isKernelThread = false;
proc->isUserlandThread = false;
2020-10-31 21:14:27 +00:00
proc->show = true; /* Reflected in proc->settings-> "hideXXX" really */
proc->pgrp = 0;
proc->session = 0;
proc->tty_nr = 0;
proc->tty_name = NULL;
2020-10-31 21:14:27 +00:00
proc->tpgid = 0;
proc->processor = 0;
proc->percent_cpu = 2.5;
proc->percent_mem = 2.5;
proc->st_uid = 0;
proc->user = "nobody"; /* Update whenever proc->st_uid is changed */
2020-10-31 21:14:27 +00:00
proc->priority = 0;
proc->nice = 0;
proc->nlwp = 1;
proc->starttime_ctime = 1433116800; // Jun 01, 2015
Process_fillStarttimeBuffer(proc);
proc->m_virt = 100;
2020-10-31 21:14:27 +00:00
proc->m_resident = 100;
proc->minflt = 20;
proc->majflt = 20;
2021-01-28 17:19:38 +00:00
if (!preExisting)
ProcessList_add(super, proc);
2015-07-12 16:26:33 +00:00
}