diff --git a/Makefile b/Makefile index 058bd243..251cf571 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ PMPATH1 = /usr/lib/pm-utils/sleep.d PMPATH2 = /usr/lib64/pm-utils/sleep.d PMPATHD = /usr/lib/systemd/system-sleep -CFLAGS += -O2 -I. -Wall -Wno-stringop-truncation # -DNOPERFEVENT # -DHTTPSTATS +CFLAGS += -O2 -I. -Wall -Wno-stringop-truncation -Wmissing-prototypes -Wmissing-declarations # -DNOPERFEVENT # -DHTTPSTATS OBJMOD0 = version.o OBJMOD1 = various.o deviate.o procdbase.o OBJMOD2 = acctproc.o photoproc.o photosyst.o rawlog.o ifprop.o parseable.o diff --git a/acctproc.c b/acctproc.c index 75a06562..201d8424 100644 --- a/acctproc.c +++ b/acctproc.c @@ -61,7 +61,7 @@ static char *pacctdir = PACCTDIR; static count_t acctexp (comp_t ct); static int acctvers(int); -static void acctrestarttrial(); +static void acctrestarttrial(void); static void switchshadow(void); /* @@ -956,7 +956,7 @@ acctphotoproc(struct tstat *accproc, int nrprocs) ** that is currently using the accounting file */ static void -acctrestarttrial() +acctrestarttrial(void) { struct stat statacc; int sematopid; diff --git a/atop.c b/atop.c index 663e4f90..de880549 100644 --- a/atop.c +++ b/atop.c @@ -113,162 +113,6 @@ ** flags. In this way various representation-layers (ASCII, graphical, ...) ** can be linked with 'atop'; the one to use can eventually be chosen ** at runtime. -** -** $Log: atop.c,v $ -** Revision 1.49 2010/10/23 14:01:00 gerlof -** Show counters for total number of running and sleep (S and D) threads. -** -** Revision 1.48 2010/10/23 08:18:15 gerlof -** Catch signal SIGUSR2 to take a final sample and stop. -** Needed for improved of suspend/hibernate. -** -** Revision 1.47 2010/04/23 12:20:19 gerlof -** Modified mail-address in header. -** -** Revision 1.46 2010/04/23 09:57:28 gerlof -** Version (flag -V) handled earlier after startup. -** -** Revision 1.45 2010/04/17 17:19:41 gerlof -** Allow modifying the layout of the columns in the system lines. -** -** Revision 1.44 2010/04/16 13:00:23 gerlof -** Automatically start another version of atop if the logfile to -** be read has not been created by the current version. -** -** Revision 1.43 2010/03/04 10:51:10 gerlof -** Support I/O-statistics on logical volumes and MD devices. -** -** Revision 1.42 2009/12/31 11:33:33 gerlof -** Sanity-check to bypass kernel-bug showing 497 days of CPU-consumption. -** -** Revision 1.41 2009/12/17 10:51:31 gerlof -** Allow own defined process line with key 'o' and a definition -** in the atoprc file. -** -** Revision 1.40 2009/12/17 08:15:15 gerlof -** Introduce branch-key to go to specific time in raw file. -** -** Revision 1.39 2009/12/10 13:34:32 gerlof -** Cosmetical changes. -** -** Revision 1.38 2009/12/10 11:55:38 gerlof -** Introduce -L flag for line length. -** -** Revision 1.37 2009/12/10 10:43:33 gerlof -** Correct calculation of node name. -** -** Revision 1.36 2009/12/10 09:19:06 gerlof -** Various changes related to redesign of user-interface. -** Made by JC van Winkel. -** -** Revision 1.35 2009/11/27 15:11:55 gerlof -** *** empty log message *** -** -** Revision 1.34 2009/11/27 15:07:25 gerlof -** Give up root-privileges at a earlier stage. -** -** Revision 1.33 2009/11/27 14:01:01 gerlof -** Introduce system-wide configuration file /etc/atoprc -** -** Revision 1.32 2008/01/07 10:16:13 gerlof -** Implement summaries for atopsar. -** -** Revision 1.31 2007/11/06 09:16:05 gerlof -** Add keyword atopsarflags to configuration-file ~/.atoprc -** -** Revision 1.30 2007/08/16 11:58:35 gerlof -** Add support for atopsar reporting. -** -** Revision 1.29 2007/03/20 13:01:36 gerlof -** Introduction of variable supportflags. -** -** Revision 1.28 2007/03/20 12:13:00 gerlof -** Be sure that all tstat struct's are initialized with binary zeroes. -** -** Revision 1.27 2007/02/19 11:55:04 gerlof -** Bug-fix: flag -S was not recognized any more. -** -** Revision 1.26 2007/02/13 10:34:20 gerlof -** Support parseable output with flag -P -** -** Revision 1.25 2007/01/26 12:10:40 gerlof -** Add configuration-value 'swoutcritsec'. -** -** Revision 1.24 2007/01/18 10:29:22 gerlof -** Improved syntax-checking for ~/.atoprc file. -** Support for network-interface busy-percentage. -** -** Revision 1.23 2006/02/07 08:27:04 gerlof -** Cosmetic changes. -** -** Revision 1.22 2005/10/28 09:50:29 gerlof -** All flags/subcommands are defined as macro's. -** -** Revision 1.21 2005/10/21 09:48:48 gerlof -** Per-user accumulation of resource consumption. -** -** Revision 1.20 2004/12/14 15:05:38 gerlof -** Implementation of patch-recognition for disk and network-statistics. -** -** Revision 1.19 2004/10/26 13:42:49 gerlof -** Also lock current physical pages in memory. -** -** Revision 1.18 2004/09/15 08:23:42 gerlof -** Set resource limit for locked memory to infinite, because -** in certain environments it is set to 32K (causes atop-malloc's -** to fail). -** -** Revision 1.17 2004/05/06 09:45:44 gerlof -** Ported to kernel-version 2.6. -** -** Revision 1.16 2003/07/07 09:18:22 gerlof -** Cleanup code (-Wall proof). -** -** Revision 1.15 2003/07/03 11:16:14 gerlof -** Implemented subcommand `r' (reset). -** -** Revision 1.14 2003/06/30 11:29:12 gerlof -** Handle configuration file ~/.atoprc -** -** Revision 1.13 2003/01/14 09:01:10 gerlof -** Explicit clearing of malloced space for exited processes. -** -** Revision 1.12 2002/10/30 13:44:51 gerlof -** Generate notification for statistics since boot. -** -** Revision 1.11 2002/10/08 11:34:52 gerlof -** Modified storage of raw filename. -** -** Revision 1.10 2002/09/26 13:51:47 gerlof -** Limit header lines by not showing disks. -** -** Revision 1.9 2002/09/17 10:42:00 gerlof -** Copy functions rawread() and rawwrite() to separate source-file rawlog.c -** -** Revision 1.8 2002/08/30 07:49:35 gerlof -** Implement possibility to store and retrieve atop-data in raw format. -** -** Revision 1.7 2002/08/27 12:09:16 gerlof -** Allow raw data file to be written and to be read (with compression). -** -** Revision 1.6 2002/07/24 11:12:07 gerlof -** Redesigned to ease porting to other UNIX-platforms. -** -** Revision 1.5 2002/07/11 09:15:53 root -** *** empty log message *** -** -** Revision 1.4 2002/07/08 09:20:45 root -** Bug solution: flag list overflow. -** -** Revision 1.3 2001/11/07 09:17:41 gerlof -** Use /proc instead of /dev/kmem for process-level statistics. -** -** Revision 1.2 2001/10/04 13:03:15 gerlof -** Separate kopen() function called i.s.o. implicit with first kmem-read -** -** Revision 1.1 2001/10/02 10:43:19 gerlof -** Initial revision -** */ #include @@ -294,6 +138,7 @@ #include "photoproc.h" #include "photosyst.h" #include "showgeneric.h" +#include "showlinux.h" #include "parseable.h" #include "json.h" #include "gpucom.h" @@ -353,53 +198,8 @@ static char rawwriteflag; */ static void readrc(char *, int); -void do_flags(char *, char *); -void do_interval(char *, char *); -void do_linelength(char *, char *); -void do_username(char *, char *); -void do_procname(char *, char *); -void do_maxcpu(char *, char *); -void do_maxgpu(char *, char *); -void do_maxdisk(char *, char *); -void do_maxmdd(char *, char *); -void do_maxlvm(char *, char *); -void do_maxintf(char *, char *); -void do_maxifb(char *, char *); -void do_maxnfsm(char *, char *); -void do_maxcont(char *, char *); -void do_maxnuma(char *, char *); -void do_maxllc(char *, char *); -void do_colinfo(char *, char *); -void do_colalmost(char *, char *); -void do_colcrit(char *, char *); -void do_colthread(char *, char *); -void do_ownsysprcline(char *, char *); -void do_ownallcpuline(char *, char *); -void do_ownindivcpuline(char *, char *); -void do_owncplline(char *, char *); -void do_ownmemline(char *, char *); -void do_ownswpline(char *, char *); -void do_ownpagline(char *, char *); -void do_ownmemnumaline(char *, char *); -void do_owncpunumaline(char *, char *); -void do_ownllcline(char *, char *); -void do_owndskline(char *, char *); -void do_ownnettransportline(char *, char *); -void do_ownnetnetline(char *, char *); -void do_ownnetinterfaceline(char *, char *); -void do_owninfinibandline(char *, char *); -void do_ownprocline(char *, char *); -void do_cpucritperc(char *, char *); -void do_gpucritperc(char *, char *); -void do_memcritperc(char *, char *); -void do_swpcritperc(char *, char *); -void do_dskcritperc(char *, char *); -void do_netcritperc(char *, char *); -void do_swoutcritsec(char *, char *); -void do_almostcrit(char *, char *); -void do_atopsarflags(char *, char *); -void do_pacctdir(char *, char *); -void do_perfevents(char *, char *); +static void do_interval(char *, char *); +static void do_linelength(char *, char *); static struct { char *tag; @@ -764,7 +564,6 @@ engine(void) { struct sigaction sigact; static time_t timelimit; - void getusr1(int), getusr2(int); /* ** reserve space for system-level statistics @@ -1164,15 +963,13 @@ getusr2(int sig) /* ** functions to handle a particular tag in the .atoprc file */ -extern int get_posval(char *name, char *val); - -void +static void do_interval(char *name, char *val) { interval = get_posval(name, val); } -void +static void do_linelength(char *name, char *val) { linelen = get_posval(name, val); diff --git a/atop.h b/atop.h index b2f50873..40c50a79 100644 --- a/atop.h +++ b/atop.h @@ -207,3 +207,10 @@ void netatop_exithash(char); void netatop_exitfind(unsigned long, struct tstat *, struct tstat *); void set_oom_score_adj(void); int run_in_guest(void); + +void getusr1(int), getusr2(int); +void do_pacctdir(char *, char *); +void do_atopsarflags(char *, char *); + +int netlink_open(void); +int netlink_recv(int, int); diff --git a/atopacctd.c b/atopacctd.c index 3ea0002e..d4578c24 100644 --- a/atopacctd.c +++ b/atopacctd.c @@ -123,10 +123,6 @@ static int acctsize(struct acct *); static void cleanup(int); -int netlink_open(void); // from netlink.c -int netlink_recv(int, int); // from netlink.c - - int main(int argc, char *argv[]) { diff --git a/atopconvert.c b/atopconvert.c index 4d58b8f5..13216182 100644 --- a/atopconvert.c +++ b/atopconvert.c @@ -82,6 +82,25 @@ #include "prev/photosyst_28.h" #include "prev/photoproc_28.h" +void justcopy(void *, void *, count_t, count_t); + +void scpu_to_21(void *, void *, count_t, count_t); +void sdsk_to_21(void *, void *, count_t, count_t); +void sint_to_22(void *, void *, count_t, count_t); +void scpu_to_27(void *, void *, count_t, count_t); +void smem_to_27(void *, void *, count_t, count_t); +void sdsk_to_27(void *, void *, count_t, count_t); +void smem_to_28(void *, void *, count_t, count_t); +void sdsk_to_28(void *, void *, count_t, count_t); +void smnu_to_28(void *, void *, count_t, count_t); +void scnu_to_28(void *, void *, count_t, count_t); +void tgen_to_21(void *, void *, count_t, count_t); +void tmem_to_21(void *, void *, count_t, count_t); +void tgen_to_22(void *, void *, count_t, count_t); +void tcpu_to_26(void *, void *, count_t, count_t); +void tmem_to_26(void *, void *, count_t, count_t); +void tcpu_to_28(void *, void *, count_t, count_t); +void tmem_to_28(void *, void *, count_t, count_t); /////////////////////////////////////////////////////////////// // Conversion functions diff --git a/atopsar.c b/atopsar.c index b1a48dcc..10bf35f8 100644 --- a/atopsar.c +++ b/atopsar.c @@ -407,7 +407,6 @@ static void engine(void) { struct sigaction sigact; - void getusr1(int); int nrgpus; /* number of GPUs */ int nrgpuproc, /* number of GPU procs */ diff --git a/json.c b/json.c index 8e68db0f..09ddbf99 100644 --- a/json.c +++ b/json.c @@ -49,35 +49,36 @@ #include "atop.h" #include "photosyst.h" #include "photoproc.h" +#include "json.h" #define LEN_HP_SIZE 64 #define LINE_BUF_SIZE 1024 -static void json_print_CPU(); -static void json_print_cpu(); -static void json_print_CPL(); -static void json_print_GPU(); -static void json_print_MEM(); -static void json_print_SWP(); -static void json_print_PAG(); -static void json_print_PSI(); -static void json_print_LVM(); -static void json_print_MDD(); -static void json_print_DSK(); -static void json_print_NFM(); -static void json_print_NFC(); -static void json_print_NFS(); -static void json_print_NET(); -static void json_print_IFB(); -static void json_print_NUM(); -static void json_print_NUC(); -static void json_print_LLC(); -static void json_print_PRG(); -static void json_print_PRC(); -static void json_print_PRM(); -static void json_print_PRD(); -static void json_print_PRN(); -static void json_print_PRE(); +static void json_print_CPU(char *, struct sstat *, struct tstat *, int); +static void json_print_cpu(char *, struct sstat *, struct tstat *, int); +static void json_print_CPL(char *, struct sstat *, struct tstat *, int); +static void json_print_GPU(char *, struct sstat *, struct tstat *, int); +static void json_print_MEM(char *, struct sstat *, struct tstat *, int); +static void json_print_SWP(char *, struct sstat *, struct tstat *, int); +static void json_print_PAG(char *, struct sstat *, struct tstat *, int); +static void json_print_PSI(char *, struct sstat *, struct tstat *, int); +static void json_print_LVM(char *, struct sstat *, struct tstat *, int); +static void json_print_MDD(char *, struct sstat *, struct tstat *, int); +static void json_print_DSK(char *, struct sstat *, struct tstat *, int); +static void json_print_NFM(char *, struct sstat *, struct tstat *, int); +static void json_print_NFC(char *, struct sstat *, struct tstat *, int); +static void json_print_NFS(char *, struct sstat *, struct tstat *, int); +static void json_print_NET(char *, struct sstat *, struct tstat *, int); +static void json_print_IFB(char *, struct sstat *, struct tstat *, int); +static void json_print_NUM(char *, struct sstat *, struct tstat *, int); +static void json_print_NUC(char *, struct sstat *, struct tstat *, int); +static void json_print_LLC(char *, struct sstat *, struct tstat *, int); +static void json_print_PRG(char *, struct sstat *, struct tstat *, int); +static void json_print_PRC(char *, struct sstat *, struct tstat *, int); +static void json_print_PRM(char *, struct sstat *, struct tstat *, int); +static void json_print_PRD(char *, struct sstat *, struct tstat *, int); +static void json_print_PRN(char *, struct sstat *, struct tstat *, int); +static void json_print_PRE(char *, struct sstat *, struct tstat *, int); /* ** table with possible labels and the corresponding diff --git a/netlink.c b/netlink.c index cd87b52d..eb3a7ca0 100644 --- a/netlink.c +++ b/netlink.c @@ -31,6 +31,8 @@ #include #include +#include "atop.h" + /* ** generic macro's */ diff --git a/parseable.c b/parseable.c index e103d6d7..ebf2207c 100644 --- a/parseable.c +++ b/parseable.c @@ -39,33 +39,34 @@ #include "photoproc.h" #include "parseable.h" -void print_CPU(); -void print_cpu(); -void print_CPL(); -void print_GPU(); -void print_MEM(); -void print_SWP(); -void print_PAG(); -void print_PSI(); -void print_LVM(); -void print_MDD(); -void print_DSK(); -void print_NFM(); -void print_NFC(); -void print_NFS(); -void print_NET(); -void print_IFB(); -void print_NUM(); -void print_NUC(); -void print_LLC(); - -void print_PRG(); -void print_PRC(); -void print_PRM(); -void print_PRD(); -void print_PRN(); -void print_PRE(); - +void print_CPU(char *, struct sstat *, struct tstat *, int); +void print_cpu(char *, struct sstat *, struct tstat *, int); +void print_CPL(char *, struct sstat *, struct tstat *, int); +void print_GPU(char *, struct sstat *, struct tstat *, int); +void print_MEM(char *, struct sstat *, struct tstat *, int); +void print_SWP(char *, struct sstat *, struct tstat *, int); +void print_PAG(char *, struct sstat *, struct tstat *, int); +void print_PSI(char *, struct sstat *, struct tstat *, int); +void print_LVM(char *, struct sstat *, struct tstat *, int); +void print_MDD(char *, struct sstat *, struct tstat *, int); +void print_DSK(char *, struct sstat *, struct tstat *, int); +void print_NFM(char *, struct sstat *, struct tstat *, int); +void print_NFC(char *, struct sstat *, struct tstat *, int); +void print_NFS(char *, struct sstat *, struct tstat *, int); +void print_NET(char *, struct sstat *, struct tstat *, int); +void print_IFB(char *, struct sstat *, struct tstat *, int); +void print_NUM(char *, struct sstat *, struct tstat *, int); +void print_NUC(char *, struct sstat *, struct tstat *, int); +void print_LLC(char *, struct sstat *, struct tstat *, int); + +void print_PRG(char *, struct sstat *, struct tstat *, int); +void print_PRC(char *, struct sstat *, struct tstat *, int); +void print_PRM(char *, struct sstat *, struct tstat *, int); +void print_PRD(char *, struct sstat *, struct tstat *, int); +void print_PRN(char *, struct sstat *, struct tstat *, int); +void print_PRE(char *, struct sstat *, struct tstat *, int); + +static void calc_freqscale(count_t, count_t, count_t, count_t *, int *); static char *spaceformat(char *, char *); static int cgroupv2max(int, int); @@ -238,7 +239,7 @@ parseout(time_t curtime, int numsecs, /* ** print functions for system-level statistics */ -void +static void calc_freqscale(count_t maxfreq, count_t cnt, count_t ticks, count_t *freq, int *freqperc) { diff --git a/photosyst.c b/photosyst.c index 8179b6aa..ef508356 100644 --- a/photosyst.c +++ b/photosyst.c @@ -93,6 +93,8 @@ enum { }; static int perfevents = PERF_EVENTS_AUTO; +static long perf_event_open(struct perf_event_attr *, pid_t, + int, int, unsigned long); static void getperfevents(struct cpustat *); #endif @@ -103,6 +105,10 @@ static int get_zswap(struct sstat *); static int isdisk(unsigned int, unsigned int, char *, struct perdsk *, int); +static struct bitmask *numa_allocate_cpumask(void); +static void numa_bitmask_free(struct bitmask *); +static int numa_parse_bitmap_v2(char *, struct bitmask *); + static struct ipv6_stats ipv6_tmp; static struct icmpv6_stats icmpv6_tmp; static struct udpv6_stats udpv6_tmp; @@ -202,8 +208,8 @@ struct bitmask { * Allocate a bitmask for cpus, of a size large enough to * match the kernel's cpumask_t. */ -struct bitmask * -numa_allocate_cpumask() +static struct bitmask * +numa_allocate_cpumask(void) { int ncpus = CPUMASK_SZ; struct bitmask *bmp; @@ -219,7 +225,7 @@ numa_allocate_cpumask() return bmp; } -void +static void numa_bitmask_free(struct bitmask *bmp) { if (bmp == 0) @@ -230,7 +236,7 @@ numa_bitmask_free(struct bitmask *bmp) return; } -int +static int numa_parse_bitmap_v2(char *line, struct bitmask *mask) { int i; @@ -2129,68 +2135,6 @@ isdisk(unsigned int major, unsigned int minor, return NONTYPE; } -/* -** LINUX SPECIFIC: -** Determine boot-time of this system (as number of jiffies since 1-1-1970). -*/ -unsigned long long -getbootlinux(long hertz) -{ - int cpid; - char tmpbuf[1280]; - FILE *fp; - unsigned long startticks; - unsigned long long bootjiffies = 0; - struct timespec ts; - - /* - ** dirty hack to get the boottime, since the - ** Linux 2.6 kernel (2.6.5) does not return a proper - ** boottime-value with the times() system call :-( - */ - if ( (cpid = fork()) == 0 ) - { - /* - ** child just waiting to be killed by parent - */ - pause(); - } - else - { - /* - ** parent determines start-time (in jiffies since boot) - ** of the child and calculates the boottime in jiffies - ** since 1-1-1970 - */ - (void) clock_gettime(CLOCK_REALTIME, &ts); // get current - bootjiffies = 1LL * ts.tv_sec * hertz + - 1LL * ts.tv_nsec * hertz / 1000000000LL; - - snprintf(tmpbuf, sizeof tmpbuf, "/proc/%d/stat", cpid); - - if ( (fp = fopen(tmpbuf, "r")) != NULL) - { - if ( fscanf(fp, "%*d (%*[^)]) %*c %*d %*d %*d %*d " - "%*d %*d %*d %*d %*d %*d %*d %*d " - "%*d %*d %*d %*d %*d %*d %lu", - &startticks) == 1) - { - bootjiffies -= startticks; - } - - fclose(fp); - } - - /* - ** kill the child and get rid of the zombie - */ - kill(cpid, SIGKILL); - (void) wait((int *)0); - } - - return bootjiffies; -} - /* ** get stats of all InfiniBand ports below @@ -2716,7 +2660,7 @@ enable_perfevents() return perfevents == PERF_EVENTS_ENABLE; } -long +static long perf_event_open(struct perf_event_attr *hwevent, pid_t pid, int cpu, int groupfd, unsigned long flags) { diff --git a/photosyst.h b/photosyst.h index 0193bd67..2ed884a2 100644 --- a/photosyst.h +++ b/photosyst.h @@ -449,4 +449,5 @@ struct sstat { void photosyst (struct sstat *); void deviatsyst(struct sstat *, struct sstat *, struct sstat *, long); void totalsyst (char, struct sstat *, struct sstat *); +void do_perfevents(char *, char *); #endif diff --git a/procdbase.c b/procdbase.c index e55b012b..0cf59613 100644 --- a/procdbase.c +++ b/procdbase.c @@ -30,32 +30,6 @@ ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** -------------------------------------------------------------------------- -** -** $Log: procdbase.c,v $ -** Revision 1.8 2010/04/23 12:19:35 gerlof -** Modified mail-address in header. -** -** Revision 1.7 2007/11/05 12:12:31 gerlof -** Match processes not only on pid, but also on start time. -** -** Revision 1.6 2005/10/21 09:50:19 gerlof -** Per-user accumulation of resource consumption. -** -** Revision 1.5 2003/07/07 09:26:40 gerlof -** Cleanup code (-Wall proof). -** -** Revision 1.4 2002/10/03 11:19:58 gerlof -** Modify (effective) uid/gid to real uid/gid. -** -** Revision 1.3 2002/07/24 11:13:50 gerlof -** Changed to ease porting to other UNIX-platforms. -** -** Revision 1.2 2002/07/08 09:29:07 root -** Call to calloc i.s.o. malloc + memset. -** -** Revision 1.1 2001/10/02 10:43:33 gerlof -** Initial revision -** */ #include diff --git a/showgeneric.c b/showgeneric.c index 5a6aff4f..5553bda1 100644 --- a/showgeneric.c +++ b/showgeneric.c @@ -3242,9 +3242,6 @@ do_procname(char *name, char *val) } } -extern int get_posval(char *name, char *val); - - void do_maxcpu(char *name, char *val) { diff --git a/showgeneric.h b/showgeneric.h index 8ec8e41c..c659c0c6 100644 --- a/showgeneric.h +++ b/showgeneric.h @@ -161,3 +161,22 @@ int prisyst(struct sstat *, int, int, int, int, struct sselection *, int priproc(struct tstat **, int, int, int, int, int, char, char, struct syscap *, int, int); void priphead(int, int, char *, char *, char, count_t); + +void do_username(char *, char *); +void do_procname(char *, char *); +void do_maxcpu(char *, char *); +void do_maxgpu(char *, char *); +void do_maxdisk(char *, char *); +void do_maxmdd(char *, char *); +void do_maxlvm(char *, char *); +void do_maxintf(char *, char *); +void do_maxifb(char *, char *); +void do_maxnfsm(char *, char *); +void do_maxcont(char *, char *); +void do_maxnuma(char *, char *); +void do_maxllc(char *, char *); +void do_colinfo(char *, char *); +void do_colalmost(char *, char *); +void do_colcrit(char *, char *); +void do_colthread(char *, char *); +void do_flags(char *, char *); diff --git a/showlinux.c b/showlinux.c index 8d89cadc..cba40980 100644 --- a/showlinux.c +++ b/showlinux.c @@ -32,233 +32,6 @@ ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** -------------------------------------------------------------------------- -** -** $Log: showlinux.c,v $ -** Revision 1.70 2010/10/23 14:04:12 gerlof -** Counters for total number of running and sleep threads (JC van Winkel). -** -** Revision 1.69 2010/05/18 19:20:08 gerlof -** Introduce CPU frequency and scaling (JC van Winkel). -** -** Revision 1.68 2010/04/23 12:19:35 gerlof -** Modified mail-address in header. -** -** Revision 1.67 2010/04/17 17:20:33 gerlof -** Allow modifying the layout of the columns in the system lines. -** -** Revision 1.66 2010/03/16 21:14:46 gerlof -** Program and user selection can be combined with program and user -** accumulation. -** -** Revision 1.65 2010/03/04 10:53:26 gerlof -** Support I/O-statistics on logical volumes and MD devices. -** -** Revision 1.64 2010/01/18 18:06:28 gerlof -** Modified priorities for system-level columns. -** -** Revision 1.63 2010/01/16 12:54:33 gerlof -** Corrected order of columns. -** -** Revision 1.62 2010/01/16 11:38:02 gerlof -** Corrected counters for patched kernels (JC van Winkel). -** -** Revision 1.61 2010/01/08 11:25:56 gerlof -** Corrected column-width and priorities of network-stats. -** -** Revision 1.60 2010/01/03 18:27:19 gerlof -** *** empty log message *** -** -** Revision 1.59 2009/12/19 21:01:28 gerlof -** Improved syntax checking for ownprocline keyword (JC van Winkel). -** -** Revision 1.58 2009/12/17 11:59:28 gerlof -** Gather and display new counters: dirty cache and guest cpu usage. -** -** Revision 1.57 2009/12/17 10:51:19 gerlof -** Allow own defined process line with key 'o' and a definition -** in the atoprc file. -** -** Revision 1.56 2009/12/17 09:13:19 gerlof -** Reformatted some fields for better grouping of info. -** -** Revision 1.55 2009/12/12 10:11:18 gerlof -** Register and display end date and end time for process. -** -** Revision 1.54 2009/12/12 09:06:48 gerlof -** \Corrected cumulated disk I/O per user/program (JC van Winkel). -** -** Revision 1.53 2009/12/10 14:02:39 gerlof -** Add EUID, SUID and FSUID (and similar for GID's). -** -** Revision 1.52 2009/12/10 11:56:34 gerlof -** Various bug-solutions. -** -** Revision 1.51 2009/12/10 10:08:01 gerlof -** Major redesign for improved user interface (variable number of columns). -** Made by JC van Winkel. -** -** Revision 1.49 2008/03/06 08:38:28 gerlof -** Register/show ppid of a process. -** -** Revision 1.48 2008/01/18 07:37:05 gerlof -** Show information about the state of the individual threads -** in the scheduling report shown with keystroke 's'. -** -** Revision 1.47 2008/01/07 11:34:18 gerlof -** Correct the sort-order of network-interfaces (on busy-percentage). -** -** Revision 1.46 2007/11/07 09:23:29 gerlof -** Modified format for avg1, avg5 and avg15 (CPL) when counters too large. -** -** Revision 1.45 2007/11/05 11:43:25 gerlof -** Bug-solution for new-process indicator on 64-bits machines. -** -** Revision 1.44 2007/11/05 10:57:56 gerlof -** Bug-solution for huge exit code on 64-bits machines. -** -** Revision 1.43 2007/08/17 09:45:57 gerlof -** Experimental: gather info about HTTP statistics. -** -** Revision 1.42 2007/08/16 12:02:04 gerlof -** Add support for atopsar reporting. -** Concerns modification of networking-counters. -** -** Revision 1.41 2007/07/04 10:18:16 gerlof -** Bug-solution for division by zero. -** -** Revision 1.40 2007/07/03 09:02:29 gerlof -** Support Apache-statistics. -** -** Revision 1.39 2007/03/22 10:12:54 gerlof -** Support for io counters (>= kernel 2.6.20). -** -** Revision 1.38 2007/03/21 14:22:24 gerlof -** Handle io counters maintained from 2.6.20 -** -** Revision 1.37 2007/02/13 10:36:09 gerlof -** Removal of external declarations. -** Use of hertz variable instead of HZ. -** -** Revision 1.36 2007/01/26 12:11:07 gerlof -** Add configuration-value 'swoutcritsec'. -** -** Revision 1.35 2007/01/26 10:25:42 gerlof -** Introduce steal percentage for virtual machines. -** Correct bug: when one interface is colored all subsequent interfaces -** are colored. -** -** Revision 1.34 2007/01/18 10:58:45 gerlof -** Only check for committed limit if it is not zero. -** -** Revision 1.33 2007/01/18 10:37:09 gerlof -** Add support for colors. -** Add support for automatic determination of most critical resource. -** Add support for parsing of new arguments in ~/.atoprc -** -** Revision 1.32 2006/11/13 13:48:46 gerlof -** Implement load-average counters, context-switches and interrupts. -** -** Revision 1.31 2006/02/07 08:38:49 gerlof -** Swapped the zombie counter and exit counter in the PRC-line. -** -** Revision 1.30 2006/02/07 08:30:07 gerlof -** Add possibility to show counters per second. -** Ease parsing of output-lines by fixed number of columns per line. -** -** Revision 1.29 2006/01/30 09:24:12 gerlof -** PRC-line: 'exits' modified to 'exit' to save space. -** -** Revision 1.28 2006/01/30 09:14:26 gerlof -** Extend memory counters (a.o. page scans). -** -** Revision 1.27 2005/11/04 14:16:45 gerlof -** Minor bug-solutions. -** -** Revision 1.26 2005/10/28 09:51:29 gerlof -** All flags/subcommands are defined as macro's. -** Subcommand 'p' has been changed to 'z' (pause). -** -** Revision 1.25 2005/10/21 09:51:11 gerlof -** Per-user accumulation of resource consumption. -** -** Revision 1.24 2004/12/14 15:06:48 gerlof -** Implementation of patch-recognition for disk and network-statistics. -** -** Revision 1.23 2004/10/28 08:31:41 gerlof -** New counter: vm committed space -** -** Revision 1.22 2004/09/24 10:02:46 gerlof -** Wrong cpu-numbers for system level statistics. -** -** Revision 1.21 2004/09/23 08:21:10 gerlof -** Added wait-percentage per cpu. -** -** Revision 1.20 2004/09/23 07:37:34 gerlof -** Consistent handling of CPU percentages on system-level and process-level. -** -** Revision 1.19 2004/09/13 09:20:21 gerlof -** Modify subcommands (former 's' -> 'v', 'v' -> 'V', new 's'). -** -** Revision 1.18 2004/09/02 10:55:21 root -** Added sleep-average to process-info. -** -** Revision 1.17 2004/08/31 09:53:31 gerlof -** Show information about underlying threads. -** -** Revision 1.16 2004/06/01 11:58:34 gerlof -** Regular expressions for selections on process-name and user-name. -** -** Revision 1.15 2004/05/06 09:47:59 gerlof -** Ported to kernel-version 2.6. -** -** Revision 1.14 2003/07/07 09:27:34 gerlof -** Cleanup code (-Wall proof). -** -** Revision 1.13 2003/07/03 12:04:25 gerlof -** Minor bug fixes. -** -** Revision 1.12 2003/06/30 11:29:57 gerlof -** Enlarge counters to 'long long'. -** -** Revision 1.11 2003/06/24 06:22:10 gerlof -** Limit number of system resource lines. -** -** Revision 1.10 2003/02/07 10:43:22 gerlof -** Solved a division-by-zero bug for process-percentage. -** -** Revision 1.9 2003/01/24 14:20:57 gerlof -** If possible, also show commandline when process has exited. -** -** Revision 1.8 2003/01/17 07:32:49 gerlof -** Show the full command-line per process (option 'c'). -** -** Revision 1.7 2002/10/04 10:05:54 gerlof -** Bug-solution: New process indicator in static output set when needed. -** -** Revision 1.6 2002/10/03 11:14:42 gerlof -** Modify (effective) uid/gid to real uid/gid. -** -** Revision 1.5 2002/09/26 13:52:51 gerlof -** Limit header lines by not showing disks. -** Limit header lines by not showing disks. -** -** Revision 1.4 2002/09/16 08:59:13 gerlof -** Change field EXCODE to STATUS for support of indicator of newly created -** processes. -** -** Revision 1.3 2002/09/02 08:42:44 gerlof -** Bug-solution: blank line after header when more than 999 screens of -** process-list information. -** -** Revision 1.2 2002/08/30 07:11:20 gerlof -** Minor changes in the header-line of the process list. -** -** Revision 1.1 2002/07/24 11:14:16 gerlof -** Initial revision -** -** -** Initial -** */ #include @@ -285,6 +58,9 @@ #include "showlinux.h" static void make_proc_dynamicgen(void); +static int get_perc(char *, char *); +static void make_proc_prints(proc_printpair *, int, const char *, + const char *); /* ** critical percentages for occupation-percentage; @@ -922,12 +698,12 @@ init_proc_prints(count_t numcpu) } /* - * make_proc_prints: make array of proc_printpairs - * input: string, proc_printpair array, maxentries - */ -void +** make_proc_prints: make array of proc_printpairs +** input: string, proc_printpair array, maxentries +*/ +static void make_proc_prints(proc_printpair *ar, int maxn, const char *pairs, -const char *linename) + const char *linename) { name_prio items[MAXITEMS]; int n=strlen(pairs); @@ -3059,7 +2835,7 @@ get_posval(char *name, char *val) return value; } -int +static int get_perc(char *name, char *val) { int value = get_posval(name, val); diff --git a/showlinux.h b/showlinux.h index 88ee9a07..ad4ab514 100644 --- a/showlinux.h +++ b/showlinux.h @@ -27,13 +27,8 @@ ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** -------------------------------------------------------------------------- -** -** $Log: showlinux.h,v $ -** Initial revision -** -** Initial -** */ + #define MAXITEMS 80 /* The maximum number of items per line */ /* @@ -128,6 +123,34 @@ void showhdrline(proc_printpair* elemptr, int curlist, int totlist, void showprocline(proc_printpair* elemptr, struct tstat *curstat, double perc, int nsecs, int avgval); +void do_cpucritperc(char *, char *); +void do_gpucritperc(char *, char *); +void do_memcritperc(char *, char *); +void do_swpcritperc(char *, char *); +void do_dskcritperc(char *, char *); +void do_netcritperc(char *, char *); +void do_swoutcritsec(char *, char *); +void do_almostcrit(char *, char *); +void do_ownsysprcline(char *, char *); +void do_ownallcpuline(char *, char *); +void do_ownindivcpuline(char *, char *); +void do_owncplline(char *, char *); +void do_owngpuline(char *, char *); +void do_ownmemline(char *, char *); +void do_ownswpline(char *, char *); +void do_ownpagline(char *, char *); +void do_ownmemnumaline(char *, char *); +void do_owncpunumaline(char *, char *); +void do_ownllcline(char *, char *); +void do_owndskline(char *, char *); +void do_ownnettransportline(char *, char *); +void do_ownnetnetline(char *, char *); +void do_ownnetinterfaceline(char *, char *); +void do_owninfinibandline(char *, char *); +void do_ownprocline(char *, char *); + +int get_posval(char *, char *); + extern sys_printdef *prcsyspdefs[]; extern sys_printdef *cpusyspdefs[]; extern sys_printdef *cpisyspdefs[]; diff --git a/showprocs.c b/showprocs.c index 5d854987..2ee7dbf3 100644 --- a/showprocs.c +++ b/showprocs.c @@ -53,6 +53,134 @@ #include "showlinux.h" static void format_bandw(char *, count_t); +static void gettotwidth(proc_printpair *, int *, int *, int *); +static int *getspacings(proc_printpair *); + +char *procprt_TID_ae(struct tstat *, int, int); +char *procprt_PID_a(struct tstat *, int, int); +char *procprt_PID_e(struct tstat *, int, int); +char *procprt_PPID_a(struct tstat *, int, int); +char *procprt_PPID_e(struct tstat *, int, int); +char *procprt_VPID_a(struct tstat *, int, int); +char *procprt_VPID_e(struct tstat *, int, int); +char *procprt_CTID_a(struct tstat *, int, int); +char *procprt_CTID_e(struct tstat *, int, int); +char *procprt_CID_a(struct tstat *, int, int); +char *procprt_CID_e(struct tstat *, int, int); +char *procprt_SYSCPU_ae(struct tstat *, int, int); +char *procprt_USRCPU_ae(struct tstat *, int, int); +char *procprt_VGROW_a(struct tstat *, int, int); +char *procprt_VGROW_e(struct tstat *, int, int); +char *procprt_RGROW_a(struct tstat *, int, int); +char *procprt_RGROW_e(struct tstat *, int, int); +char *procprt_MINFLT_ae(struct tstat *, int, int); +char *procprt_MAJFLT_ae(struct tstat *, int, int); +char *procprt_VSTEXT_a(struct tstat *, int, int); +char *procprt_VSTEXT_e(struct tstat *, int, int); +char *procprt_VSIZE_a(struct tstat *, int, int); +char *procprt_VSIZE_e(struct tstat *, int, int); +char *procprt_RSIZE_a(struct tstat *, int, int); +char *procprt_RSIZE_e(struct tstat *, int, int); +char *procprt_PSIZE_a(struct tstat *, int, int); +char *procprt_PSIZE_e(struct tstat *, int, int); +char *procprt_VSLIBS_a(struct tstat *, int, int); +char *procprt_VSLIBS_e(struct tstat *, int, int); +char *procprt_VDATA_a(struct tstat *, int, int); +char *procprt_VDATA_e(struct tstat *, int, int); +char *procprt_VSTACK_a(struct tstat *, int, int); +char *procprt_VSTACK_e(struct tstat *, int, int); +char *procprt_SWAPSZ_a(struct tstat *, int, int); +char *procprt_SWAPSZ_e(struct tstat *, int, int); +char *procprt_LOCKSZ_a(struct tstat *, int, int); +char *procprt_LOCKSZ_e(struct tstat *, int, int); +char *procprt_CMD_a(struct tstat *, int, int); +char *procprt_CMD_e(struct tstat *, int, int); +char *procprt_RUID_ae(struct tstat *, int, int); +char *procprt_EUID_a(struct tstat *, int, int); +char *procprt_EUID_e(struct tstat *, int, int); +char *procprt_SUID_a(struct tstat *, int, int); +char *procprt_SUID_e(struct tstat *, int, int); +char *procprt_FSUID_a(struct tstat *, int, int); +char *procprt_FSUID_e(struct tstat *, int, int); +char *procprt_RGID_ae(struct tstat *, int, int); +char *procprt_EGID_a(struct tstat *, int, int); +char *procprt_EGID_e(struct tstat *, int, int); +char *procprt_SGID_a(struct tstat *, int, int); +char *procprt_SGID_e(struct tstat *, int, int); +char *procprt_FSGID_a(struct tstat *, int, int); +char *procprt_FSGID_e(struct tstat *, int, int); +char *procprt_STDATE_ae(struct tstat *, int, int); +char *procprt_STTIME_ae(struct tstat *, int, int); +char *procprt_ENDATE_a(struct tstat *, int, int); +char *procprt_ENDATE_e(struct tstat *, int, int); +char *procprt_ENTIME_a(struct tstat *, int, int); +char *procprt_ENTIME_e(struct tstat *, int, int); +char *procprt_THR_a(struct tstat *, int, int); +char *procprt_THR_e(struct tstat *, int, int); +char *procprt_TRUN_a(struct tstat *, int, int); +char *procprt_TRUN_e(struct tstat *, int, int); +char *procprt_TSLPI_a(struct tstat *, int, int); +char *procprt_TSLPI_e(struct tstat *, int, int); +char *procprt_TSLPU_a(struct tstat *, int, int); +char *procprt_TSLPU_e(struct tstat *, int, int); +char *procprt_POLI_a(struct tstat *, int, int); +char *procprt_POLI_e(struct tstat *, int, int); +char *procprt_NICE_a(struct tstat *, int, int); +char *procprt_NICE_e(struct tstat *, int, int); +char *procprt_PRI_a(struct tstat *, int, int); +char *procprt_PRI_e(struct tstat *, int, int); +char *procprt_RTPR_a(struct tstat *, int, int); +char *procprt_RTPR_e(struct tstat *, int, int); +char *procprt_CURCPU_a(struct tstat *, int, int); +char *procprt_CURCPU_e(struct tstat *, int, int); +char *procprt_ST_a(struct tstat *, int, int); +char *procprt_ST_e(struct tstat *, int, int); +char *procprt_EXC_a(struct tstat *, int, int); +char *procprt_EXC_e(struct tstat *, int, int); +char *procprt_S_a(struct tstat *, int, int); +char *procprt_S_e(struct tstat *, int, int); +char *procprt_COMMAND_LINE_ae(struct tstat *, int, int); +char *procprt_NPROCS_ae(struct tstat *, int, int); +char *procprt_RDDSK_a(struct tstat *, int, int); +char *procprt_RDDSK_e(struct tstat *, int, int); +char *procprt_WRDSK_a(struct tstat *, int, int); +char *procprt_WRDSK_e(struct tstat *, int, int); +char *procprt_CWRDSK_a(struct tstat *, int, int); +char *procprt_WCANCEL_a(struct tstat *, int, int); +char *procprt_WCANCEL_e(struct tstat *, int, int); +char *procprt_BANDWI_a(struct tstat *, int, int); +char *procprt_BANDWI_e(struct tstat *, int, int); +char *procprt_BANDWO_a(struct tstat *, int, int); +char *procprt_BANDWO_e(struct tstat *, int, int); +char *procprt_GPULIST_ae(struct tstat *, int, int); +char *procprt_GPUMEMNOW_ae(struct tstat *, int, int); +char *procprt_GPUMEMAVG_ae(struct tstat *, int, int); +char *procprt_GPUGPUBUSY_ae(struct tstat *, int, int); +char *procprt_GPUMEMBUSY_ae(struct tstat *, int, int); +char *procprt_WCHAN_a(struct tstat *, int, int); +char *procprt_WCHAN_e(struct tstat *, int, int); +char *procprt_RUNDELAY_a(struct tstat *, int, int); +char *procprt_RUNDELAY_e(struct tstat *, int, int); +char *procprt_BLKDELAY_a(struct tstat *, int, int); +char *procprt_BLKDELAY_e(struct tstat *, int, int); +char *procprt_CGROUP_PATH_a(struct tstat *, int, int); +char *procprt_CGROUP_PATH_e(struct tstat *, int, int); +char *procprt_CGRCPUWGT_a(struct tstat *, int, int); +char *procprt_CGRCPUWGT_e(struct tstat *, int, int); +char *procprt_CGRCPUMAX_a(struct tstat *, int, int); +char *procprt_CGRCPUMAX_e(struct tstat *, int, int); +char *procprt_CGRCPUMAXR_a(struct tstat *, int, int); +char *procprt_CGRCPUMAXR_e(struct tstat *, int, int); +char *procprt_CGRMEMMAX_a(struct tstat *, int, int); +char *procprt_CGRMEMMAX_e(struct tstat *, int, int); +char *procprt_CGRMEMMAXR_a(struct tstat *, int, int); +char *procprt_CGRMEMMAXR_e(struct tstat *, int, int); +char *procprt_CGRSWPMAX_a(struct tstat *, int, int); +char *procprt_CGRSWPMAX_e(struct tstat *, int, int); +char *procprt_CGRSWPMAXR_a(struct tstat *, int, int); +char *procprt_CGRSWPMAXR_e(struct tstat *, int, int); +char *procprt_SORTITEM_ae(struct tstat *, int, int); + static char *columnhead[] = { [MSORTCPU]= "CPU", [MSORTMEM]= "MEM", @@ -84,7 +212,7 @@ static proc_printpair newelems[MAXITEMS]; * sumwidth: (ref) returns the total width of the printitems in the array * varwidth: (ref) returns the number of variable width items in the array */ -void +static void gettotwidth(proc_printpair* elemptr, int *nitems, int *sumwidth, int* varwidth) { int i; @@ -116,7 +244,7 @@ gettotwidth(proc_printpair* elemptr, int *nitems, int *sumwidth, int* varwidth) * * Note: this function is only to be called when screen is true. */ -int * +static int * getspacings(proc_printpair* elemptr) { static int spacings[MAXITEMS]; diff --git a/showsys.c b/showsys.c index 74476a6d..4948db7a 100644 --- a/showsys.c +++ b/showsys.c @@ -52,6 +52,11 @@ #include "showgeneric.h" #include "showlinux.h" +static void addblanks(double *, double *); +static void sumscaling(struct sstat *, count_t *, count_t *, count_t *); +static void psiformatavg(struct psi *, char *, char *, int); +static void psiformattot(struct psi *, char *, extraparam *, int *, char *, int); + /*******************************************************************/ /* ** print the label of a system-statistics line and switch on @@ -112,7 +117,7 @@ syscolorlabel(char *labeltext, unsigned int badness) static char *sysprt_BLANKBOX(struct sstat *sstat, extraparam *notused, int, int *); -void +static void addblanks(double *charslackused, double *charslackover) { *charslackused+=*charslackover; @@ -588,10 +593,10 @@ dofmt_cpufreq(char *buf, count_t maxfreq, count_t cnt, count_t ticks) /* - * sumscaling: sum scaling info for all processors - * - */ -void sumscaling(struct sstat *sstat, count_t *maxfreq, +** sumscaling: sum scaling info for all processors +*/ +static void +sumscaling(struct sstat *sstat, count_t *maxfreq, count_t *cnt, count_t *ticks) { count_t mymaxfreq = 0; @@ -2044,7 +2049,7 @@ sysprt_NUMLLC(struct sstat *sstat, extraparam *as, int badness, int *color) sys_printdef syspdef_NUMLLC = {"NUMLLC", sysprt_NUMLLC, NULL}; /*******************************************************************/ // general formatting of PSI field in avg10/avg60/avg300 -void +static void psiformatavg(struct psi *p, char *head, char *buf, int bufsize) { static char formats[] = "%.0f/%.0f/%.0f"; @@ -2118,7 +2123,7 @@ sys_printdef syspdef_PSIIOF = {"PSIIOF", sysprt_PSIIOF, NULL}; /*******************************************************************/ // general formatting of PSI field in total percentage -void +static void psiformattot(struct psi *p, char *head, extraparam *as, int *color, char *buf, int bufsize) { diff --git a/various.c b/various.c index dd56cb2c..6a57144e 100644 --- a/various.c +++ b/various.c @@ -28,74 +28,6 @@ ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** -------------------------------------------------------------------------- -** -** $Log: various.c,v $ -** Revision 1.21 2010/11/12 06:16:16 gerlof -** Show all parts of timestamp in header line, even when zero. -** -** Revision 1.20 2010/05/18 19:21:08 gerlof -** Introduce CPU frequency and scaling (JC van Winkel). -** -** Revision 1.19 2010/04/28 18:21:11 gerlof -** Cast value larger than 4GB to long long. -** -** Revision 1.18 2010/04/23 12:19:35 gerlof -** Modified mail-address in header. -** -** Revision 1.17 2010/03/26 11:52:45 gerlof -** Introduced unit of Tbytes for memory-usage. -** -** Revision 1.16 2009/12/17 08:28:38 gerlof -** Express CPU-time usage in days and hours for large values. -** -** Revision 1.15 2009/12/10 08:50:39 gerlof -** Introduction of a new function to convert number of seconds -** to a string indicating days, hours, minutes and seconds. -** -** Revision 1.14 2007/02/13 10:32:47 gerlof -** Removal of external declarations. -** Removal of function getpagesz(). -** -** Revision 1.13 2006/02/07 08:27:21 gerlof -** Add possibility to show counters per second. -** Modify presentation of CPU-values. -** -** Revision 1.12 2005/10/31 12:26:09 gerlof -** Modified date-format to yyyy/mm/dd. -** -** Revision 1.11 2005/10/21 09:51:29 gerlof -** Per-user accumulation of resource consumption. -** -** Revision 1.10 2004/05/06 09:46:24 gerlof -** Ported to kernel-version 2.6. -** -** Revision 1.9 2003/07/07 09:27:46 gerlof -** Cleanup code (-Wall proof). -** -** Revision 1.8 2003/07/03 11:16:59 gerlof -** Minor bug solutions. -** -** Revision 1.7 2003/06/30 11:31:17 gerlof -** Enlarge counters to 'long long'. -** -** Revision 1.6 2003/06/24 06:22:24 gerlof -** Limit number of system resource lines. -** -** Revision 1.5 2002/08/30 07:49:09 gerlof -** Convert a hh:mm string into a number of seconds since 00:00. -** -** Revision 1.4 2002/08/27 12:08:37 gerlof -** Modified date format (from yyyy/mm/dd to mm/dd/yyyy). -** -** Revision 1.3 2002/07/24 11:14:05 gerlof -** Changed to ease porting to other UNIX-platforms. -** -** Revision 1.2 2002/07/11 09:43:36 root -** Modified HZ into sysconf(_SC_CLK_TCK). -** -** Revision 1.1 2001/10/02 10:43:36 gerlof -** Initial revision -** */ #include @@ -113,10 +45,14 @@ #include #include #include +#include #include "atop.h" #include "acctproc.h" + +static unsigned long long getbootlinux(long); + /* ** Function convtime() converts a value (number of seconds since ** 1-1-1970) to an ascii-string in the format hh:mm:ss, stored in @@ -711,7 +647,6 @@ unsigned long long getboot(void) { static unsigned long long boottime; - unsigned long long getbootlinux(long); if (!boottime) /* do this only once */ boottime = getbootlinux(hertz); @@ -719,6 +654,70 @@ getboot(void) return boottime; } + +/* +** LINUX SPECIFIC: +** Determine boot-time of this system (as number of jiffies since 1-1-1970). +*/ +static unsigned long long +getbootlinux(long hertz) +{ + int cpid; + char tmpbuf[1280]; + FILE *fp; + unsigned long startticks; + unsigned long long bootjiffies = 0; + struct timespec ts; + + /* + ** dirty hack to get the boottime, since the + ** Linux 2.6 kernel (2.6.5) does not return a proper + ** boottime-value with the times() system call :-( + */ + if ( (cpid = fork()) == 0 ) + { + /* + ** child just waiting to be killed by parent + */ + pause(); + } + else + { + /* + ** parent determines start-time (in jiffies since boot) + ** of the child and calculates the boottime in jiffies + ** since 1-1-1970 + */ + (void) clock_gettime(CLOCK_REALTIME, &ts); // get current + bootjiffies = 1LL * ts.tv_sec * hertz + + 1LL * ts.tv_nsec * hertz / 1000000000LL; + + snprintf(tmpbuf, sizeof tmpbuf, "/proc/%d/stat", cpid); + + if ( (fp = fopen(tmpbuf, "r")) != NULL) + { + if ( fscanf(fp, "%*d (%*[^)]) %*c %*d %*d %*d %*d " + "%*d %*d %*d %*d %*d %*d %*d %*d " + "%*d %*d %*d %*d %*d %*d %lu", + &startticks) == 1) + { + bootjiffies -= startticks; + } + + fclose(fp); + } + + /* + ** kill the child and get rid of the zombie + */ + kill(cpid, SIGKILL); + (void) wait((int *)0); + } + + return bootjiffies; +} + + /* ** generic pointer verification after malloc */ diff --git a/version.h b/version.h index 026a956f..3a4142b4 100644 --- a/version.h +++ b/version.h @@ -1 +1,4 @@ #define ATOPVERS "2.8.1" + +char *getstrvers(void); +unsigned short getnumvers(void);