/*
* pg_top - a top PostgreSQL users display for Unix
*
* SYNOPSIS: Linux 1.2.x, 1.3.x, 2.x, using the /proc filesystem
*
* DESCRIPTION:
* This is the machine-dependent module for Linux 1.2.x, 1.3.x or 2.x.
*
* LIBS:
*
* CFLAGS: -DHAVE_GETOPT -DHAVE_STRERROR -DORDER
*
* TERMCAP: -lcurses
*
* AUTHOR: Richard Henderson <rth@tamu.edu>
* Order support added by Alexey Klimkin <kad@klon.tme.mcst.ru>
* Ported to 2.4 by William LeFebvre
*/
#include "config.h"
#include <sys/types.h>
#include <time.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <bsd/stdlib.h>
#include <bsd/sys/tree.h>
#include <errno.h>
#include <dirent.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/vfs.h>
#include <sys/param.h> /* for HZ */
#if 0
#include <linux/proc_fs.h> /* for PROC_SUPER_MAGIC */
#else
#define PROC_SUPER_MAGIC 0x9fa0
#endif
#define BUFFERLEN 255
#define GET_VALUE(v) \
p = strchr(p, ':'); \
++p; \
++p; \
q = strchr(p, '\n'); \
len = q - p; \
if (len >= BUFFERLEN) \
{ \
printf("ERROR - value is larger than the buffer: %d\n", __LINE__); \
exit(1); \
} \
strncpy(value, p, len); \
value[len] = '\0'; \
v = atoll(value);
#include "machine.h"
#include "utils.h"
#define PROCFS "/proc"
extern char *myname;
/*=PROCESS INFORMATION==================================================*/
struct top_proc
{
RB_ENTRY(top_proc) entry;
pid_t pid;
/* index for which element is current in data arrays */
int index;
/* Data from /proc/<pid>/stat. */
char *name;
char *usename;
unsigned long size,
rss; /* in k */
int state;
int pgstate;
unsigned long time;
unsigned long start_time;
unsigned long xtime;
unsigned long qtime;
unsigned int locks;
double pcpu;
/* Data from /proc/<pid>/io. */
long long iops[2]; /* syscr + syscw */
long long syscr[2];
long long syscw[2];
long long read_bytes[2];
long long write_bytes[2];
/* Replication data */
char *application_name;
char *client_addr;
char *repstate;
char *primary;
char *sent;
char *write;