static struct el * select_procs (int *num)
{
-#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, stack)
-#define PIDS_GETULL(e) PIDS_VAL(EU_ ## e, ull_int, stack)
-#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, stack)
+#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, stack, info)
+#define PIDS_GETULL(e) PIDS_VAL(EU_ ## e, ull_int, stack, info)
+#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, stack, info)
struct pids_info *info=NULL;
struct procps_namespaces nsp;
struct pids_stack *stack;
exe_link = root_link = NULL;
while ((stack = procps_pids_get(info, PIDS_FETCH_TASKS_ONLY))) {
- char *p_cmd = PIDS_VAL(rel_cmd, str, stack),
- **p_cmdline = PIDS_VAL(rel_cmdline, strv, stack);
- int tid = PIDS_VAL(rel_pid, s_int, stack);
+ char *p_cmd = PIDS_VAL(rel_cmd, str, stack, info),
+ **p_cmdline = PIDS_VAL(rel_cmdline, strv, stack, info);
+ int tid = PIDS_VAL(rel_pid, s_int, stack, info);
if (opt_rootdir_check) {
/* get the /proc/<pid>/root symlink value */
#include "xalloc.h"
#include <proc/procps.h>
+static struct pids_info *Pids_info;
+
enum pids_item Pid_items[] = {
PIDS_ID_PID, PIDS_ID_TGID,
PIDS_CMDLINE, PIDS_ADDR_START_STACK };
}
cp = _(" [ anon ]");
- if (PIDS_VAL(start_stack, ul_int, p) >= addr
- && (PIDS_VAL(start_stack, ul_int, p) <= addr + len))
+ if (PIDS_VAL(start_stack, ul_int, p, Pids_info) >= addr
+ && (PIDS_VAL(start_stack, ul_int, p, Pids_info) <= addr + len))
cp = _(" [ stack ]");
return cp;
}
unsigned long long total_shared_dirty = 0ull;
int maxw1=0, maxw2=0, maxw3=0, maxw4=0, maxw5=0;
- printf("%u: %s\n", PIDS_VAL(tgid, s_int, p), PIDS_VAL(cmdline, str, p));
+ printf("%u: %s\n", PIDS_VAL(tgid, s_int, p, Pids_info), PIDS_VAL(cmdline, str, p, Pids_info));
if (x_option || X_option || c_option) {
- sprintf(buf, "/proc/%u/smaps", PIDS_VAL(tgid, s_int, p));
+ sprintf(buf, "/proc/%u/smaps", PIDS_VAL(tgid, s_int, p, Pids_info));
if ((fp = fopen(buf, "r")) == NULL)
return 1;
} else {
- sprintf(buf, "/proc/%u/maps", PIDS_VAL(tgid, s_int, p));
+ sprintf(buf, "/proc/%u/maps", PIDS_VAL(tgid, s_int, p, Pids_info));
if ((fp = fopen(buf, "r")) == NULL)
return 1;
}
int main(int argc, char **argv)
{
- struct pids_info *info = NULL;
struct pids_fetch *pids_fetch;
unsigned *pidlist;
int reap_count, user_count;
}
}
}
- if (procps_pids_new(&info, Pid_items, 4))
+ if (procps_pids_new(&Pids_info, Pid_items, 4))
xerrx(EXIT_FAILURE, _("library failed pids statistics"));
pidlist = xmalloc(sizeof(pid_t) * argc);
discover_shm_minor();
- if (!(pids_fetch = procps_pids_select(info, pidlist, user_count, PIDS_SELECT_PID)))
+ if (!(pids_fetch = procps_pids_select(Pids_info, pidlist, user_count, PIDS_SELECT_PID)))
xerrx(EXIT_FAILURE, _("library failed pids statistics"));
for (reap_count = 0; reap_count < pids_fetch->counts->total; reap_count++) {
}
free(pidlist);
- procps_pids_unref(&info);
+ procps_pids_unref(&Pids_info);
/* cleaning the list used for the -c/-X/-XX modes */
for (listnode = listhead; listnode != NULL ; ) {
/* a 'results stack value' extractor macro
where: E=rel enum, T=data type, S=stack */
-#define rSv(E,T,S) PIDS_VAL(rel_ ## E, T, S)
+#define rSv(E,T,S) PIDS_VAL(rel_ ## E, T, S, Pids_info)
#define namREL(e) rel_ ## e
#define makEXT(e) extern int namREL(e);
bsd_c_option = 0;
bsd_e_option = 0;
cached_euid = geteuid();
- cached_tty = PIDS_VAL(0, s_int, p);
+ cached_tty = PIDS_VAL(0, s_int, p, Pids_info);
/* forest_prefix must be all zero because of POSIX */
forest_type = 0;
format_flags = 0; /* -l -f l u s -j... */
thing##s[thing##_count++] = addme; \
}while(0)
+struct pids_info *Pids_info;
+
enum pids_item items[] = {
PIDS_ID_PID,
PIDS_ID_EUID,
static int ask_user(struct pids_stack *stack)
{
-#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, stack)
-#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, stack)
+#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, stack, Pids_info)
+#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, stack, Pids_info)
char *buf=NULL;
size_t len=0;
static void scan_procs(struct run_time_conf_t *run_time)
{
-#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, reap->stacks[i])
-#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, reap->stacks[i])
- struct pids_info *info=NULL;
+#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, reap->stacks[i], Pids_info)
+#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, reap->stacks[i], Pids_info)
struct pids_fetch *reap;
int i, total_procs;
- if (procps_pids_new(&info, items, 6) < 0)
+ if (procps_pids_new(&Pids_info, items, 6) < 0)
xerrx(EXIT_FAILURE,
- _("Unable to create pid info structure"));
- if ((reap = procps_pids_reap(info, PIDS_FETCH_TASKS_ONLY)) == NULL)
+ _("Unable to create pid Pids_info structure"));
+ if ((reap = procps_pids_reap(Pids_info, PIDS_FETCH_TASKS_ONLY)) == NULL)
xerrx(EXIT_FAILURE,
_("Unable to load process information"));
mem_FRE, mem_USE, mem_TOT, mem_QUE, mem_BUF, mem_AVL,
swp_TOT, swp_FRE, swp_USE };
// mem stack results extractor macro, where e=rel enum
-#define MEM_VAL(e) MEMINFO_VAL(e, ul_int, Mem_stack)
+#define MEM_VAL(e) MEMINFO_VAL(e, ul_int, Mem_stack, Mem_ctx)
// --- <proc/pids.h> --------------------------------------------------
static struct pids_info *Pids_ctx;
static int Pids_itms_cur; // 'current' max (<= Fieldstab)
// pid stack results extractor macro, where e=our EU enum, t=type, s=stack
// ( we'll exploit that <proc/pids.h> provided macro as much as possible )
// ( but many functions use their own unique tailored version for access )
-#define PID_VAL(e,t,s) PIDS_VAL(Fieldstab[ e ].erel, t, s)
+#define PID_VAL(e,t,s) PIDS_VAL(Fieldstab[ e ].erel, t, s, Pids_ctx)
// --- <proc/stat.h> --------------------------------------------------
static struct stat_info *Stat_ctx;
static struct stat_reaped *Stat_reap;
stat_ID, stat_NU, stat_US, stat_SY, stat_NI,
stat_IL, stat_IO, stat_IR, stat_SI, stat_ST };
// cpu/node stack results extractor macros, where e=rel enum, x=index
-#define CPU_VAL(e,x) STAT_VAL(e, s_int, Stat_reap->cpus->stacks[x])
-#define NOD_VAL(e,x) STAT_VAL(e, s_int, Stat_reap->nodes->stacks[x])
+#define CPU_VAL(e,x) STAT_VAL(e, s_int, Stat_reap->cpus->stacks[x], Stat_ctx)
+#define NOD_VAL(e,x) STAT_VAL(e, s_int, Stat_reap->nodes->stacks[x], Stat_ctx)
\f
/*###### Tiny useful routine(s) ########################################*/
* display and thus requiring the cpu summary toggle */
static void summary_hlp (struct stat_stack *this, const char *pfx) {
// a tailored 'results stack value' extractor macro
- #define rSv(E) STAT_VAL(E, sl_int, this)
+ #define rSv(E) STAT_VAL(E, sl_int, this, Stat_ctx)
SIC_t u_frme, s_frme, n_frme, i_frme, w_frme, x_frme, y_frme, z_frme, tot_frme;
float scale;
static void new_format(void)
{
-#define TICv(E) STAT_VAL(E, ull_int, stat_stack)
-#define DTICv(E) STAT_VAL(E, sl_int, stat_stack)
-#define SYSv(E) STAT_VAL(E, ul_int, stat_stack)
-#define MEMv(E) MEMINFO_VAL(E, ul_int, mem_stack)
-#define DSYSv(E) STAT_VAL(E, s_int, stat_stack)
+#define TICv(E) STAT_VAL(E, ull_int, stat_stack, stat_info)
+#define DTICv(E) STAT_VAL(E, sl_int, stat_stack, stat_info)
+#define SYSv(E) STAT_VAL(E, ul_int, stat_stack, stat_info)
+#define MEMv(E) MEMINFO_VAL(E, ul_int, mem_stack, mem_info)
+#define DSYSv(E) STAT_VAL(E, s_int, stat_stack, stat_info)
const char format[] =
"%2lu %2lu %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %4u %2u %2u %2u %2u %2u";
const char wide_format[] =
static void diskpartition_format(const char *partition_name)
{
- #define partVAL(x) DISKSTATS_VAL(x, ul_int, stack)
+ #define partVAL(x) DISKSTATS_VAL(x, ul_int, stack, disk_stat)
struct diskstats_info *disk_stat;
struct diskstats_stack *stack;
struct diskstats_result *got;
static void diskformat(void)
{
-#define diskVAL(e,t) DISKSTATS_VAL(e, t, reap->stacks[j])
+#define diskVAL(e,t) DISKSTATS_VAL(e, t, reap->stacks[j], disk_stat)
struct diskstats_info *disk_stat;
struct diskstats_reap *reap;
int i, j;
static void disksum_format(void)
{
-#define diskVAL(e,t) DISKSTATS_VAL(e, t, reap->stacks[j])
+#define diskVAL(e,t) DISKSTATS_VAL(e, t, reap->stacks[j], disk_stat)
struct diskstats_info *disk_stat;
struct diskstats_reap *reap;
int j, disk_count, part_count;
static void sum_format(void)
{
-#define TICv(E) STAT_VAL(E, ull_int, stat_stack)
-#define SYSv(E) STAT_VAL(E, ul_int, stat_stack)
-#define MEMv(E) unitConvert(STAT_VAL(E, ul_int, mem_stack))
+#define TICv(E) STAT_VAL(E, ull_int, stat_stack, stat_info)
+#define SYSv(E) STAT_VAL(E, ul_int, stat_stack, stat_info)
+#define MEMv(E) unitConvert(MEMINFO_VAL(E, ul_int, mem_stack, mem_info))
struct stat_info *stat_info = NULL;
struct vmstat_info *vm_info = NULL;
struct meminfo_info *mem_info = NULL;
unsigned long long *restrict const pcpu,
char *cmdline)
{
-#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, reap->stacks[i])
-#define PIDS_GETULL(e) PIDS_VAL(EU_ ## e, ull_int, reap->stacks[i])
-#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, reap->stacks[i])
+#define PIDS_GETINT(e) PIDS_VAL(EU_ ## e, s_int, reap->stacks[i], info)
+#define PIDS_GETULL(e) PIDS_VAL(EU_ ## e, ull_int, reap->stacks[i], info)
+#define PIDS_GETSTR(e) PIDS_VAL(EU_ ## e, str, reap->stacks[i], info)
unsigned uid = ~0U;
int found_utpid = 0;
int i, total_procs, line;
}
if (PIDS_GETINT(TTY) != line)
continue;
- (*jcpu) += PIDS_VAL(EU_TICS_ALL, ull_int, reap->stacks[i]);
+ (*jcpu) += PIDS_VAL(EU_TICS_ALL, ull_int, reap->stacks[i], info);
if (!(secondbest_time && PIDS_GETULL(START) <= secondbest_time)) {
secondbest_time = PIDS_GETULL(START);
if (cmdline[0] == '-' && cmdline[1] == '\0') {