htop/ProcessList.h

128 lines
3.5 KiB
C
Raw Permalink Normal View History

2006-03-04 18:16:49 +00:00
#ifndef HEADER_ProcessList
#define HEADER_ProcessList
/*
2006-06-06 20:28:42 +00:00
htop - ProcessList.h
(C) 2004,2005 Hisham H. Muhammad
Released under the GNU GPLv2+, see the COPYING file
2006-03-04 18:16:49 +00:00
in the source distribution for its full text.
*/
#include "config.h" // IWYU pragma: keep
2021-08-24 15:27:43 +00:00
#include <limits.h>
#include <stdbool.h>
2021-04-29 15:12:43 +00:00
#include <stdint.h>
#include <sys/time.h>
#include <sys/types.h>
2006-03-04 18:16:49 +00:00
#include "Hashtable.h"
#include "Object.h"
#include "Panel.h"
2011-12-26 21:35:57 +00:00
#include "Process.h"
#include "RichString.h"
#include "Settings.h"
2020-09-18 17:23:04 +00:00
#include "UsersTable.h"
#include "Vector.h"
2016-02-14 21:57:29 +00:00
#ifdef HAVE_LIBHWLOC
#include <hwloc.h>
#endif
2006-03-04 18:16:49 +00:00
#ifndef MAX_NAME
#define MAX_NAME 128
#endif
#ifndef MAX_READ
#define MAX_READ 2048
#endif
typedef unsigned long long int memory_t;
#define MEMORY_MAX ULLONG_MAX
2006-03-04 18:16:49 +00:00
typedef struct ProcessList_ {
const Settings* settings;
Vector* processes; /* all known processes; sort order can vary and differ from display order */
Vector* displayList; /* process tree flattened in display order (borrowed);
updated in ProcessList_updateDisplayList when rebuilding panel */
Hashtable* processTable; /* fast known process lookup by PID */
2006-03-04 18:16:49 +00:00
UsersTable* usersTable;
bool needsSort;
2020-11-18 11:19:42 +00:00
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
Hashtable* dynamicMeters; /* runtime-discovered meters */
Hashtable* dynamicColumns; /* runtime-discovered Columns */
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
struct timeval realtime; /* time of the current sample */
uint64_t realtimeMs; /* current time in milliseconds */
uint64_t monotonicMs; /* same, but from monotonic clock */
Panel* panel;
int following;
uid_t userId;
const char* incFilter;
Hashtable* pidMatchList;
#ifdef HAVE_LIBHWLOC
hwloc_topology_t topology;
bool topologyOk;
#endif
unsigned int totalTasks;
unsigned int runningTasks;
unsigned int userlandThreads;
unsigned int kernelThreads;
2015-03-17 02:01:48 +00:00
memory_t totalMem;
memory_t usedMem;
memory_t buffersMem;
memory_t cachedMem;
memory_t sharedMem;
memory_t availableMem;
memory_t totalSwap;
memory_t usedSwap;
memory_t cachedSwap;
unsigned int activeCPUs;
unsigned int existingCPUs;
2006-03-04 18:16:49 +00:00
} ProcessList;
2021-06-12 20:04:37 +00:00
/* Implemented by platforms */
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* dynamicMeters, Hashtable* dynamicColumns, Hashtable* pidMatchList, uid_t userId);
void ProcessList_delete(ProcessList* pl);
void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate);
2021-06-12 20:04:37 +00:00
bool ProcessList_isCPUonline(const ProcessList* super, unsigned int id);
ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* dynamicMeters, Hashtable* dynamicColumns, Hashtable* pidMatchList, uid_t userId);
2006-03-04 18:16:49 +00:00
void ProcessList_done(ProcessList* this);
2006-03-04 18:16:49 +00:00
void ProcessList_setPanel(ProcessList* this, Panel* panel);
void ProcessList_printHeader(const ProcessList* this, RichString* header);
2006-03-04 18:16:49 +00:00
void ProcessList_add(ProcessList* this, Process* p);
void ProcessList_updateDisplayList(ProcessList* this);
2006-03-04 18:16:49 +00:00
2020-11-04 16:46:11 +00:00
ProcessField ProcessList_keyAt(const ProcessList* this, int at);
void ProcessList_expandTree(ProcessList* this);
void ProcessList_collapseAllBranches(ProcessList* this);
void ProcessList_rebuildPanel(ProcessList* this);
Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting, Process_New constructor);
2015-03-17 02:01:48 +00:00
void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate);
static inline Process* ProcessList_findProcess(ProcessList* this, pid_t pid) {
return (Process*) Hashtable_get(this->processTable, pid);
}
2006-03-04 18:16:49 +00:00
#endif