do {
/* Read system uptime (reduced to one processor) */
- uptime0[curr] = 0;
read_uptime(&(uptime0[curr]));
if (!uptime0[curr])
- /* Cannot read system uptime (/proc/uptime doesn't exist) */
+ /* Cannot read system uptime */
exit(2);
/* Read CIFS stats */
do {
if (cpu_nr > 1) {
- /*
- * Read system uptime (only for SMP machines).
- * Init uptime0. So if /proc/uptime cannot fill it,
- * this will be done by /proc/stat.
- */
- uptime0[curr] = 0;
+ /* Read system uptime (only for SMP machines) */
read_uptime(&(uptime0[curr]));
}
- /*
- * Read stats for CPU "all" and 0.
- * Note that stats for CPU 0 are not used per se. It only makes
- * read_stat_cpu() fill uptime0.
- */
- read_stat_cpu(st_cpu[curr], 2, &(uptime[curr]), &(uptime0[curr]));
+ /* Read stats for CPU "all" and system uptime in jiffies */
+ read_stat_cpu(st_cpu[curr], 1, &(uptime[curr]));
if (dlist_idx) {
/*
/* Read uptime and CPU stats */
if (cpu_nr > 1) {
- /*
- * Init uptime0. So if /proc/uptime cannot fill it,
- * this will be done by /proc/stat.
- */
- uptime0[0] = 0;
+ /* Read system uptime (only for SMP machines) */
read_uptime(&(uptime0[0]));
}
- read_stat_cpu(st_cpu[0], cpu_nr + 1, &(uptime[0]), &(uptime0[0]));
+ read_stat_cpu(st_cpu[0], cpu_nr + 1, &(uptime[0]));
if (DISPLAY_NODE(actflags)) {
set_node_cpu_stats(st_node[0], st_cpu[0]);
}
/* Read uptime and CPU stats */
if (cpu_nr > 1) {
- uptime0[curr] = 0;
read_uptime(&(uptime0[curr]));
}
- read_stat_cpu(st_cpu[curr], cpu_nr + 1, &(uptime[curr]), &(uptime0[curr]));
+ read_stat_cpu(st_cpu[curr], cpu_nr + 1, &(uptime[curr]));
if (DISPLAY_NODE(actflags)) {
set_node_cpu_stats(st_node[curr], st_cpu[curr]);
}
perror("malloc");
exit(4);
}
- /* Read statistics for CPUs "all" and 0 */
- read_stat_cpu(st_cpu, 2, &uptime[curr], &uptime0[curr]);
+ /* Read statistics for CPUs "all" and system uptime (in jiffies) */
+ read_stat_cpu(st_cpu, 1, &uptime[curr]);
free(st_cpu);
if (DISPLAY_ALL_PID(pidflag)) {
setbuf(stdout, NULL);
if (cpu_nr > 1) {
- /*
- * Read system uptime (only for SMP machines).
- * Init uptime0. So if /proc/uptime cannot fill it, this will be
- * done by /proc/stat.
- */
- uptime0[0] = 0;
+ /* Read system uptime (only for SMP machines) */
read_uptime(&uptime0[0]);
}
read_stats(0);
get_localtime(&ps_tstamp[curr], 0);
if (cpu_nr > 1) {
- /*
- * Read system uptime (only for SMP machines).
- * Init uptime0. So if /proc/uptime cannot fill it, this will be
- * done by /proc/stat.
- */
- uptime0[curr] = 0;
+ /* Read system uptime (only for SMP machines) */
read_uptime(&(uptime0[curr]));
}
* OUT:
* @st_cpu Structure with statistics.
* @uptime Machine uptime multiplied by the number of processors.
- * @uptime0 Machine uptime. Filled only if previously set to zero.
***************************************************************************
*/
-void read_stat_cpu(struct stats_cpu *st_cpu, int nbr,
- unsigned long long *uptime, unsigned long long *uptime0)
+void read_stat_cpu(struct stats_cpu *st_cpu, int nbr, unsigned long long *uptime)
{
FILE *fp;
struct stats_cpu *st_cpu_i;
* else additional CPUs have been dynamically registered
* in /proc/stat.
*/
-
- if (!proc_nb && !*uptime0) {
- /*
- * Compute uptime reduced to one proc using proc#0.
- * Done if /proc/uptime was unavailable.
- *
- * NB: Don't add cpu_guest/cpu_guest_nice because cpu_user/cpu_nice
- * already include them.
- */
- *uptime0 = sc.cpu_user + sc.cpu_nice +
- sc.cpu_sys + sc.cpu_idle +
- sc.cpu_iowait + sc.cpu_steal +
- sc.cpu_hardirq + sc.cpu_softirq;
- }
}
}
}
char line[128];
unsigned long up_sec, up_cent;
- if ((fp = fopen(UPTIME, "r")) == NULL)
- return;
-
- if (fgets(line, sizeof(line), fp) == NULL) {
- fclose(fp);
+ if ((fp = fopen(UPTIME, "r")) == NULL) {
+ fprintf(stderr, _("Cannot open %s: %s\n"), UPTIME, strerror(errno));
+ exit(2);
return;
}
- sscanf(line, "%lu.%lu", &up_sec, &up_cent);
- *uptime = (unsigned long long) up_sec * HZ +
- (unsigned long long) up_cent * HZ / 100;
+ if (fgets(line, sizeof(line), fp) != NULL) {
+ sscanf(line, "%lu.%lu", &up_sec, &up_cent);
+ *uptime = (unsigned long long) up_sec * HZ +
+ (unsigned long long) up_cent * HZ / 100;
+ }
+ else {
+ /* Couldn't read system uptime */
+ *uptime = 0;
+ }
fclose(fp);
-
}
#ifdef SOURCE_SADC
void oct2chr
(char *);
void read_stat_cpu
- (struct stats_cpu *, int, unsigned long long *, unsigned long long *);
+ (struct stats_cpu *, int, unsigned long long *);
void read_stat_irq
(struct stats_irq *, int);
void read_meminfo
= (struct stats_cpu *) a->_buf0;
/* Read CPU statistics */
- read_stat_cpu(st_cpu, a->nr, &record_hdr.uptime, &record_hdr.uptime0);
+ read_stat_cpu(st_cpu, a->nr, &record_hdr.uptime);
return;
}
int i;
__nr_t cpu_nr = act[get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND)]->nr;
- /*
- * Init uptime0. So if /proc/uptime cannot fill it,
- * this will be done by /proc/stat.
- * If cpu_nr = 2, force /proc/stat to fill it.
- * If cpu_nr = 1, uptime0 and uptime are equal.
- * NB: uptime0 is always filled.
- * Remember that cpu_nr = 1 means one CPU and no SMP kernel
- * (one structure for CPU "all") and cpu_nr = 2 means one CPU
- * and an SMP kernel (two structures for CPUs "all" and "0").
- */
- record_hdr.uptime0 = 0;
- if (cpu_nr > 2) {
+ if (cpu_nr > 1) {
+ /* Read system uptime in jiffies */
read_uptime(&(record_hdr.uptime0));
}
if (cpu_nr == 1) {
/*
- * uptime has been filled by read_uptime()
- * or when reading CPU stats from /proc/stat.
+ * If cpu_nr = 1, uptime0 and uptime are equal.
+ * Remember that cpu_nr = 1 means one CPU and no SMP kernel
+ * (one structure for CPU "all") and cpu_nr = 2 means one CPU
+ * and an SMP kernel (two structures for CPUs "all" and "0").
*/
record_hdr.uptime0 = record_hdr.uptime;
}