From 931a2684938bc53e809380cedf977b397319b3b5 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sat, 6 Jul 2013 15:47:16 +0200 Subject: [PATCH] Use a lightweight static library to compile some sysstat commands Create two versions of the "librdstats.a" static library: one having all the functions to read stats and which will be used by sadc, the other having only a minimal subset of functions used by other commands like iostat or pidstat. The result is a much smaller binary file for iostat (size is 29% smaller than before), pidstat (-27%), mpstat (-40%), nfsiostat (-43%) and cifsiostat (-43%). --- Makefile.in | 21 +++- count.c | 330 ++++++++++++++++++++++++++-------------------------- count.h | 13 ++- rd_stats.c | 318 +++++++++++++++++++++++++------------------------- rd_stats.h | 17 +-- 5 files changed, 362 insertions(+), 337 deletions(-) diff --git a/Makefile.in b/Makefile.in index 159cacf..ca208cf 100644 --- a/Makefile.in +++ b/Makefile.in @@ -178,8 +178,16 @@ act_sadf.o: activity.c sa.h rndr_stats.h xml_stats.h json_stats.h $(CC) -o $@ -c $(CFLAGS) -DSOURCE_SADF $(DFLAGS) $< rd_stats.o: rd_stats.c common.h rd_stats.h ioconf.h sysconfig.h + $(CC) -o $@ -c $(CFLAGS) -DSOURCE_SADC $(DFLAGS) $< + +rd_stats_light.o: rd_stats.c common.h rd_stats.h ioconf.h sysconfig.h + $(CC) -o $@ -c $(CFLAGS) $(DFLAGS) $< count.o: count.c common.h rd_stats.h + $(CC) -o $@ -c $(CFLAGS) -DSOURCE_SADC $(DFLAGS) $< + +count_light.o: count.c common.h rd_stats.h + $(CC) -o $@ -c $(CFLAGS) $(DFLAGS) $< rd_sensors.o: rd_sensors.c common.h rd_sensors.h sysconfig.h @@ -206,6 +214,9 @@ libsyscom.a: common.o ioconf.o librdstats.a: rd_stats.o count.o $(AR) rvs $@ $? +librdstats_light.a: rd_stats_light.o count_light.o + $(AR) rvs $@ $? + librdsensors.a: librdsensors.a(rd_sensors.o) sadc.o: sadc.c sa.h version.h common.h ioconf.h sysconfig.h rd_stats.h rd_sensors.h @@ -223,23 +234,23 @@ sadf: sadf.o act_sadf.o format.o sadf_misc.o rndr_stats.o xml_stats.o json_stats iostat.o: iostat.c iostat.h version.h common.h ioconf.h sysconfig.h rd_stats.h count.h -iostat: iostat.o librdstats.a libsyscom.a +iostat: iostat.o librdstats_light.a libsyscom.a pidstat.o: pidstat.c pidstat.h version.h common.h rd_stats.h count.h -pidstat: pidstat.o librdstats.a libsyscom.a +pidstat: pidstat.o librdstats_light.a libsyscom.a mpstat.o: mpstat.c mpstat.h version.h common.h rd_stats.h count.h -mpstat: mpstat.o librdstats.a libsyscom.a +mpstat: mpstat.o librdstats_light.a libsyscom.a nfsiostat.o: nfsiostat.c nfsiostat.h count.h version.h common.h -nfsiostat: nfsiostat.o librdstats.a libsyscom.a +nfsiostat: nfsiostat.o librdstats_light.a libsyscom.a cifsiostat.o: cifsiostat.c cifsiostat.h count.h version.h common.h -cifsiostat: cifsiostat.o librdstats.a libsyscom.a +cifsiostat: cifsiostat.o librdstats_light.a libsyscom.a ifdef REQUIRE_NLS locales: $(NLSGMO) diff --git a/count.c b/count.c index 1c76013..0d95f8a 100644 --- a/count.c +++ b/count.c @@ -44,98 +44,157 @@ /* *************************************************************************** - * Count number of interrupts that are in /proc/stat file. + * Count number of processors in /sys. * * RETURNS: - * Number of interrupts, including total number of interrupts. + * Number of processors (online and offline). + * A value of 0 means that /sys was not mounted. + * A value of N (!=0) means N processor(s) (cpu0 .. cpu(N-1)). *************************************************************************** */ -int get_irq_nr(void) +int get_sys_cpu_nr(void) { - FILE *fp; - char line[8192]; - int in = 0; - int pos = 4; + DIR *dir; + struct dirent *drd; + struct stat buf; + char line[MAX_PF_NAME]; + int proc_nr = 0; - if ((fp = fopen(STAT, "r")) == NULL) + /* Open relevant /sys directory */ + if ((dir = opendir(SYSFS_DEVCPU)) == NULL) return 0; - while (fgets(line, 8192, fp) != NULL) { - - if (!strncmp(line, "intr ", 5)) { + /* Get current file entry */ + while ((drd = readdir(dir)) != NULL) { - while (pos < strlen(line)) { - in++; - pos += strcspn(line + pos + 1, " ") + 1; + if (!strncmp(drd->d_name, "cpu", 3) && isdigit(drd->d_name[3])) { + snprintf(line, MAX_PF_NAME, "%s/%s", SYSFS_DEVCPU, drd->d_name); + line[MAX_PF_NAME - 1] = '\0'; + if (stat(line, &buf) < 0) + continue; + if (S_ISDIR(buf.st_mode)) { + proc_nr++; } } } - fclose(fp); + /* Close directory */ + closedir(dir); - return in; + return proc_nr; } /* *************************************************************************** - * Find number of serial lines that support tx/rx accounting - * in /proc/tty/driver/serial file. + * Count number of processors in /proc/stat. * * RETURNS: - * Number of serial lines supporting tx/rx accouting. + * Number of processors. The returned value is greater than or equal to the + * number of online processors. + * A value of 0 means one processor and non SMP kernel. + * A value of N (!=0) means N processor(s) (0 .. N-1) with SMP kernel. *************************************************************************** */ -int get_serial_nr(void) +int get_proc_cpu_nr(void) { FILE *fp; - char line[256]; - int sl = 0; + char line[16]; + int num_proc, proc_nr = -1; - if ((fp = fopen(SERIAL, "r")) == NULL) - return 0; /* No SERIAL file */ + if ((fp = fopen(STAT, "r")) == NULL) { + fprintf(stderr, _("Cannot open %s: %s\n"), STAT, strerror(errno)); + exit(1); + } - while (fgets(line, 256, fp) != NULL) { - /* - * tx/rx statistics are always present, - * except when serial line is unknown. - */ - if (strstr(line, "tx:") != NULL) { - sl++; + while (fgets(line, 16, fp) != NULL) { + + if (strncmp(line, "cpu ", 4) && !strncmp(line, "cpu", 3)) { + sscanf(line + 3, "%d", &num_proc); + if (num_proc > proc_nr) { + proc_nr = num_proc; + } } } fclose(fp); - return sl; + return (proc_nr + 1); } /* *************************************************************************** - * Find number of interfaces (network devices) that are in /proc/net/dev - * file. + * Count the number of processors on the machine. + * Try to use /sys for that, or /proc/stat if /sys doesn't exist. + * + * IN: + * @max_nr_cpus Maximum number of proc that sysstat can handle. * * RETURNS: - * Number of network interfaces. + * Number of processors. + * 0: one proc and non SMP kernel. + * 1: one proc and SMP kernel (NB: On SMP machines where all the CPUs but + * one have been disabled, we get the total number of proc since we use + * /sys to count them). + * 2: two proc... *************************************************************************** */ -int get_iface_nr(void) +int get_cpu_nr(unsigned int max_nr_cpus) +{ + int cpu_nr; + + if ((cpu_nr = get_sys_cpu_nr()) == 0) { + /* /sys may be not mounted. Use /proc/stat instead */ + cpu_nr = get_proc_cpu_nr(); + } + + if (cpu_nr > max_nr_cpus) { + fprintf(stderr, _("Cannot handle so many processors!\n")); + exit(1); + } + + return cpu_nr; +} + +/* + *************************************************************************** + * Find number of interrupts available per processor (use + * /proc/interrupts file or /proc/softirqs). + * + * IN: + * @file /proc file to read (interrupts or softirqs). + * @max_nr_irqcpu Maximum number of interrupts per processor that + * sadc can handle. + * @cpu_nr Number of processors. + * + * RETURNS: + * Number of interrupts per processor + a pre-allocation constant. + *************************************************************************** + */ +int get_irqcpu_nr(char *file, int max_nr_irqcpu, int cpu_nr) { FILE *fp; - char line[128]; - int iface = 0; + char *line = NULL; + unsigned int irq = 0; + int p; - if ((fp = fopen(NET_DEV, "r")) == NULL) - return 0; /* No network device file */ + if ((fp = fopen(file, "r")) == NULL) + return 0; /* No interrupts file */ - while (fgets(line, 128, fp) != NULL) { - if (strchr(line, ':')) { - iface++; + SREALLOC(line, char, INTERRUPTS_LINE + 11 * cpu_nr); + + while ((fgets(line, INTERRUPTS_LINE + 11 * cpu_nr , fp) != NULL) && + (irq < max_nr_irqcpu)) { + p = strcspn(line, ":"); + if ((p > 0) && (p < 16)) { + irq++; } } fclose(fp); - return iface; + free(line); + + return irq; } /* @@ -187,184 +246,128 @@ int get_diskstats_dev_nr(int count_part, int only_used_dev) return dev; } -/* - *************************************************************************** - * Get number of devices in /proc/diskstats. - * - * IN: - * @f Non zero (true) if disks *and* partitions should be counted, and - * zero (false) if only disks must be counted. - * - * RETURNS: - * Number of devices. - *************************************************************************** - */ -int get_disk_nr(unsigned int f) -{ - int disk_nr; - - /* - * Partitions are taken into account by sar -d only with - * kernels 2.6.25 and later. - */ - disk_nr = get_diskstats_dev_nr(f, CNT_USED_DEV); - - return disk_nr; -} +#ifdef SOURCE_SADC +/*---------------- BEGIN: FUNCTIONS USED BY SADC ONLY ---------------------*/ /* *************************************************************************** - * Count number of processors in /sys. + * Count number of interrupts that are in /proc/stat file. * * RETURNS: - * Number of processors (online and offline). - * A value of 0 means that /sys was not mounted. - * A value of N (!=0) means N processor(s) (cpu0 .. cpu(N-1)). + * Number of interrupts, including total number of interrupts. *************************************************************************** */ -int get_sys_cpu_nr(void) +int get_irq_nr(void) { - DIR *dir; - struct dirent *drd; - struct stat buf; - char line[MAX_PF_NAME]; - int proc_nr = 0; + FILE *fp; + char line[8192]; + int in = 0; + int pos = 4; - /* Open relevant /sys directory */ - if ((dir = opendir(SYSFS_DEVCPU)) == NULL) + if ((fp = fopen(STAT, "r")) == NULL) return 0; - /* Get current file entry */ - while ((drd = readdir(dir)) != NULL) { + while (fgets(line, 8192, fp) != NULL) { - if (!strncmp(drd->d_name, "cpu", 3) && isdigit(drd->d_name[3])) { - snprintf(line, MAX_PF_NAME, "%s/%s", SYSFS_DEVCPU, drd->d_name); - line[MAX_PF_NAME - 1] = '\0'; - if (stat(line, &buf) < 0) - continue; - if (S_ISDIR(buf.st_mode)) { - proc_nr++; + if (!strncmp(line, "intr ", 5)) { + + while (pos < strlen(line)) { + in++; + pos += strcspn(line + pos + 1, " ") + 1; } } } - /* Close directory */ - closedir(dir); + fclose(fp); - return proc_nr; + return in; } /* *************************************************************************** - * Count number of processors in /proc/stat. + * Find number of serial lines that support tx/rx accounting + * in /proc/tty/driver/serial file. * * RETURNS: - * Number of processors. The returned value is greater than or equal to the - * number of online processors. - * A value of 0 means one processor and non SMP kernel. - * A value of N (!=0) means N processor(s) (0 .. N-1) with SMP kernel. + * Number of serial lines supporting tx/rx accouting. *************************************************************************** */ -int get_proc_cpu_nr(void) +int get_serial_nr(void) { FILE *fp; - char line[16]; - int num_proc, proc_nr = -1; - - if ((fp = fopen(STAT, "r")) == NULL) { - fprintf(stderr, _("Cannot open %s: %s\n"), STAT, strerror(errno)); - exit(1); - } + char line[256]; + int sl = 0; - while (fgets(line, 16, fp) != NULL) { + if ((fp = fopen(SERIAL, "r")) == NULL) + return 0; /* No SERIAL file */ - if (strncmp(line, "cpu ", 4) && !strncmp(line, "cpu", 3)) { - sscanf(line + 3, "%d", &num_proc); - if (num_proc > proc_nr) { - proc_nr = num_proc; - } + while (fgets(line, 256, fp) != NULL) { + /* + * tx/rx statistics are always present, + * except when serial line is unknown. + */ + if (strstr(line, "tx:") != NULL) { + sl++; } } fclose(fp); - return (proc_nr + 1); + return sl; } /* *************************************************************************** - * Count the number of processors on the machine. - * Try to use /sys for that, or /proc/stat if /sys doesn't exist. - * - * IN: - * @max_nr_cpus Maximum number of proc that sysstat can handle. + * Find number of interfaces (network devices) that are in /proc/net/dev + * file. * * RETURNS: - * Number of processors. - * 0: one proc and non SMP kernel. - * 1: one proc and SMP kernel (NB: On SMP machines where all the CPUs but - * one have been disabled, we get the total number of proc since we use - * /sys to count them). - * 2: two proc... + * Number of network interfaces. *************************************************************************** */ -int get_cpu_nr(unsigned int max_nr_cpus) +int get_iface_nr(void) { - int cpu_nr; + FILE *fp; + char line[128]; + int iface = 0; - if ((cpu_nr = get_sys_cpu_nr()) == 0) { - /* /sys may be not mounted. Use /proc/stat instead */ - cpu_nr = get_proc_cpu_nr(); - } + if ((fp = fopen(NET_DEV, "r")) == NULL) + return 0; /* No network device file */ - if (cpu_nr > max_nr_cpus) { - fprintf(stderr, _("Cannot handle so many processors!\n")); - exit(1); + while (fgets(line, 128, fp) != NULL) { + if (strchr(line, ':')) { + iface++; + } } - return cpu_nr; + fclose(fp); + + return iface; } /* *************************************************************************** - * Find number of interrupts available per processor (use - * /proc/interrupts file or /proc/softirqs). + * Get number of devices in /proc/diskstats. * * IN: - * @file /proc file to read (interrupts or softirqs). - * @max_nr_irqcpu Maximum number of interrupts per processor that - * sadc can handle. - * @cpu_nr Number of processors. + * @f Non zero (true) if disks *and* partitions should be counted, and + * zero (false) if only disks must be counted. * * RETURNS: - * Number of interrupts per processor + a pre-allocation constant. + * Number of devices. *************************************************************************** */ -int get_irqcpu_nr(char *file, int max_nr_irqcpu, int cpu_nr) +int get_disk_nr(unsigned int f) { - FILE *fp; - char *line = NULL; - unsigned int irq = 0; - int p; - - if ((fp = fopen(file, "r")) == NULL) - return 0; /* No interrupts file */ - - SREALLOC(line, char, INTERRUPTS_LINE + 11 * cpu_nr); - - while ((fgets(line, INTERRUPTS_LINE + 11 * cpu_nr , fp) != NULL) && - (irq < max_nr_irqcpu)) { - p = strcspn(line, ":"); - if ((p > 0) && (p < 16)) { - irq++; - } - } - - fclose(fp); + int disk_nr; - free(line); + /* + * Partitions are taken into account by sar -d only with + * kernels 2.6.25 and later. + */ + disk_nr = get_diskstats_dev_nr(f, CNT_USED_DEV); - return irq; + return disk_nr; } /* @@ -473,3 +476,6 @@ int get_filesystem_nr(void) return fs; } + +/*------------------ END: FUNCTIONS USED BY SADC ONLY ---------------------*/ +#endif /* SOURCE_SADC */ diff --git a/count.h b/count.h index ded803a..56b3e53 100644 --- a/count.h +++ b/count.h @@ -15,20 +15,21 @@ *************************************************************************** */ +extern int + get_cpu_nr(unsigned int); +extern int + get_irqcpu_nr(char *, int, int); +extern int + get_diskstats_dev_nr(int, int); + extern int get_irq_nr(void); extern int get_serial_nr(void); extern int get_iface_nr(void); -extern int - get_diskstats_dev_nr(int, int); extern int get_disk_nr(unsigned int); -extern int - get_cpu_nr(unsigned int); -extern int - get_irqcpu_nr(char *, int, int); extern int get_freq_nr(void); extern int diff --git a/rd_stats.c b/rd_stats.c index 1115eb8..8034a94 100644 --- a/rd_stats.c +++ b/rd_stats.c @@ -42,42 +42,6 @@ #define _(string) (string) #endif -/* - *************************************************************************** - * Replace octal codes in string with their corresponding characters. - * - * IN: - * @str String to parse. - * - * OUT: - * @str String with octal codes replaced with characters. - *************************************************************************** - */ -void oct2chr(char *str) -{ - int i = 0; - int j, len; - - len = strlen(str); - - while (i < len - 3) { - if ((str[i] == '\\') && - (str[i + 1] >= '0') && (str[i + 1] <= '3') && - (str[i + 2] >= '0') && (str[i + 2] <= '7') && - (str[i + 3] >= '0') && (str[i + 3] <= '7')) { - /* Octal code found */ - str[i] = (str[i + 1] - 48) * 64 + - (str[i + 2] - 48) * 8 + - (str[i + 3] - 48); - for (j = i + 4; j <= len; j++) { - str[j - 3] = str[j]; - } - len -= 3; - } - i++; - } -} - /* *************************************************************************** * Read CPU statistics and machine uptime. @@ -198,42 +162,6 @@ void read_stat_cpu(struct stats_cpu *st_cpu, int nbr, fclose(fp); } -/* - *************************************************************************** - * Read processes (tasks) creation and context switches statistics - * from /proc/stat. - * - * IN: - * @st_pcsw Structure where stats will be saved. - * - * OUT: - * @st_pcsw Structure with statistics. - *************************************************************************** - */ -void read_stat_pcsw(struct stats_pcsw *st_pcsw) -{ - FILE *fp; - char line[8192]; - - if ((fp = fopen(STAT, "r")) == NULL) - return; - - while (fgets(line, 8192, fp) != NULL) { - - if (!strncmp(line, "ctxt ", 5)) { - /* Read number of context switches */ - sscanf(line + 5, "%llu", &st_pcsw->context_switch); - } - - else if (!strncmp(line, "processes ", 10)) { - /* Read number of processes created since system boot */ - sscanf(line + 10, "%lu", &st_pcsw->processes); - } - } - - fclose(fp); -} - /* *************************************************************************** * Read interrupts statistics from /proc/stat. @@ -275,61 +203,6 @@ void read_stat_irq(struct stats_irq *st_irq, int nbr) fclose(fp); } -/* - *************************************************************************** - * Read queue and load statistics from /proc/loadavg and /proc/stat. - * - * IN: - * @st_queue Structure where stats will be saved. - * - * OUT: - * @st_queue Structure with statistics. - *************************************************************************** - */ -void read_loadavg(struct stats_queue *st_queue) -{ - FILE *fp; - char line[8192]; - int load_tmp[3]; - - if ((fp = fopen(LOADAVG, "r")) == NULL) - return; - - /* Read load averages and queue length */ - fscanf(fp, "%d.%d %d.%d %d.%d %ld/%d %*d\n", - &load_tmp[0], &st_queue->load_avg_1, - &load_tmp[1], &st_queue->load_avg_5, - &load_tmp[2], &st_queue->load_avg_15, - &st_queue->nr_running, - &st_queue->nr_threads); - - fclose(fp); - - st_queue->load_avg_1 += load_tmp[0] * 100; - st_queue->load_avg_5 += load_tmp[1] * 100; - st_queue->load_avg_15 += load_tmp[2] * 100; - - if (st_queue->nr_running) { - /* Do not take current process into account */ - st_queue->nr_running--; - } - - /* Read nr of tasks blocked from /proc/stat */ - if ((fp = fopen(STAT, "r")) == NULL) - return; - - while (fgets(line, 8192, fp) != NULL) { - - if (!strncmp(line, "procs_blocked ", 14)) { - /* Read number of processes blocked */ - sscanf(line + 14, "%lu", &st_queue->procs_blocked); - break; - } - } - - fclose(fp); -} - /* *************************************************************************** * Read memory statistics from /proc/meminfo. @@ -400,6 +273,166 @@ void read_meminfo(struct stats_memory *st_memory) fclose(fp); } +/* + *************************************************************************** + * Read machine uptime, independently of the number of processors. + * + * OUT: + * @uptime Uptime value in jiffies. + *************************************************************************** + */ +void read_uptime(unsigned long long *uptime) +{ + FILE *fp; + char line[128]; + unsigned long up_sec, up_cent; + + if ((fp = fopen(UPTIME, "r")) == NULL) + return; + + if (fgets(line, 128, fp) == NULL) { + fclose(fp); + return; + } + + sscanf(line, "%lu.%lu", &up_sec, &up_cent); + *uptime = (unsigned long long) up_sec * HZ + + (unsigned long long) up_cent * HZ / 100; + + fclose(fp); + +} + +#ifdef SOURCE_SADC +/*---------------- BEGIN: FUNCTIONS USED BY SADC ONLY ---------------------*/ + +/* + *************************************************************************** + * Replace octal codes in string with their corresponding characters. + * + * IN: + * @str String to parse. + * + * OUT: + * @str String with octal codes replaced with characters. + *************************************************************************** + */ +void oct2chr(char *str) +{ + int i = 0; + int j, len; + + len = strlen(str); + + while (i < len - 3) { + if ((str[i] == '\\') && + (str[i + 1] >= '0') && (str[i + 1] <= '3') && + (str[i + 2] >= '0') && (str[i + 2] <= '7') && + (str[i + 3] >= '0') && (str[i + 3] <= '7')) { + /* Octal code found */ + str[i] = (str[i + 1] - 48) * 64 + + (str[i + 2] - 48) * 8 + + (str[i + 3] - 48); + for (j = i + 4; j <= len; j++) { + str[j - 3] = str[j]; + } + len -= 3; + } + i++; + } +} + +/* + *************************************************************************** + * Read processes (tasks) creation and context switches statistics + * from /proc/stat. + * + * IN: + * @st_pcsw Structure where stats will be saved. + * + * OUT: + * @st_pcsw Structure with statistics. + *************************************************************************** + */ +void read_stat_pcsw(struct stats_pcsw *st_pcsw) +{ + FILE *fp; + char line[8192]; + + if ((fp = fopen(STAT, "r")) == NULL) + return; + + while (fgets(line, 8192, fp) != NULL) { + + if (!strncmp(line, "ctxt ", 5)) { + /* Read number of context switches */ + sscanf(line + 5, "%llu", &st_pcsw->context_switch); + } + + else if (!strncmp(line, "processes ", 10)) { + /* Read number of processes created since system boot */ + sscanf(line + 10, "%lu", &st_pcsw->processes); + } + } + + fclose(fp); +} + +/* + *************************************************************************** + * Read queue and load statistics from /proc/loadavg and /proc/stat. + * + * IN: + * @st_queue Structure where stats will be saved. + * + * OUT: + * @st_queue Structure with statistics. + *************************************************************************** + */ +void read_loadavg(struct stats_queue *st_queue) +{ + FILE *fp; + char line[8192]; + int load_tmp[3]; + + if ((fp = fopen(LOADAVG, "r")) == NULL) + return; + + /* Read load averages and queue length */ + fscanf(fp, "%d.%d %d.%d %d.%d %ld/%d %*d\n", + &load_tmp[0], &st_queue->load_avg_1, + &load_tmp[1], &st_queue->load_avg_5, + &load_tmp[2], &st_queue->load_avg_15, + &st_queue->nr_running, + &st_queue->nr_threads); + + fclose(fp); + + st_queue->load_avg_1 += load_tmp[0] * 100; + st_queue->load_avg_5 += load_tmp[1] * 100; + st_queue->load_avg_15 += load_tmp[2] * 100; + + if (st_queue->nr_running) { + /* Do not take current process into account */ + st_queue->nr_running--; + } + + /* Read nr of tasks blocked from /proc/stat */ + if ((fp = fopen(STAT, "r")) == NULL) + return; + + while (fgets(line, 8192, fp) != NULL) { + + if (!strncmp(line, "procs_blocked ", 14)) { + /* Read number of processes blocked */ + sscanf(line + 14, "%lu", &st_queue->procs_blocked); + break; + } + } + + fclose(fp); +} + /* *************************************************************************** * Read swapping statistics from /proc/vmstat. @@ -2012,32 +2045,5 @@ void read_filesystem(struct stats_filesystem *st_filesystem, int nbr) fclose(fp); } -/* - *************************************************************************** - * Read machine uptime, independently of the number of processors. - * - * OUT: - * @uptime Uptime value in jiffies. - *************************************************************************** - */ -void read_uptime(unsigned long long *uptime) -{ - FILE *fp; - char line[128]; - unsigned long up_sec, up_cent; - - if ((fp = fopen(UPTIME, "r")) == NULL) - return; - - if (fgets(line, 128, fp) == NULL) { - fclose(fp); - return; - } - - sscanf(line, "%lu.%lu", &up_sec, &up_cent); - *uptime = (unsigned long long) up_sec * HZ + - (unsigned long long) up_cent * HZ / 100; - - fclose(fp); - -} +/*------------------ END: FUNCTIONS USED BY SADC ONLY ---------------------*/ +#endif /* SOURCE_SADC */ diff --git a/rd_stats.h b/rd_stats.h index 8276910..41558b5 100644 --- a/rd_stats.h +++ b/rd_stats.h @@ -550,19 +550,22 @@ struct stats_filesystem { *************************************************************************** */ -extern void - oct2chr(char *); extern void read_stat_cpu(struct stats_cpu *, int, unsigned long long *, unsigned long long *); -extern void - read_stat_pcsw(struct stats_pcsw *); extern void read_stat_irq(struct stats_irq *, int); -extern void - read_loadavg(struct stats_queue *); extern void read_meminfo(struct stats_memory *); +extern void + read_uptime(unsigned long long *); + +extern void + oct2chr(char *); +extern void + read_stat_pcsw(struct stats_pcsw *); +extern void + read_loadavg(struct stats_queue *); extern void read_vmstat_swap(struct stats_swap *); extern void @@ -601,8 +604,6 @@ extern void read_net_etcp(struct stats_net_etcp *); extern void read_net_udp(struct stats_net_udp *); -extern void - read_uptime(unsigned long long *); extern void read_net_sock6(struct stats_net_sock6 *); extern void -- 2.40.0