/*
* sar: report system activity
- * (C) 1999-2020 by Sebastien GODARD (sysstat <at> orange.fr)
+ * (C) 1999-2021 by Sebastien GODARD (sysstat <at> orange.fr)
*
***************************************************************************
* This program is free software; you can redistribute it and/or modify it *
int write_stats(int curr, int read_from_file, long *cnt, int use_tm_start,
int use_tm_end, int reset, unsigned int act_id, int reset_cd)
{
- int i, prev_hour;
+ int i, prev_hour, rc = 0;
unsigned long long itv;
static int cross_day = FALSE;
}
/* Check time (2) */
- if (use_tm_start && (datecmp(&rectime, &tm_start, cross_day) < 0))
- /* it's too soon... */
- return 0;
-
- /* Get interval value in 1/100th of a second */
- get_itv_value(&record_hdr[curr], &record_hdr[!curr], &itv);
-
- /* Check time (3) */
if (use_tm_end && (datecmp(&rectime, &tm_end, cross_day) > 0)) {
- /* It's too late... */
+ /* End time exceeded */
*cnt = 0;
return 0;
}
+ /* Get interval value in 1/100th of a second */
+ get_itv_value(&record_hdr[curr], &record_hdr[!curr], &itv);
+
avg_count++;
/* Test stdout */
if (IS_SELECTED(act[i]->options) && (act[i]->nr[curr] > 0)) {
/* Display current activity statistics */
(*act[i]->f_print)(act[i], !curr, curr, itv);
+ rc = 1;
}
}
- return 1;
+ return rc;
}
/*
reallocate_all_buffers(act[p], act[p]->nr[curr]);
}
-
/*
* For persistent activities, we must make sure that no statistics
* from a previous iteration remain, especially if the number
* Start with reading current sample's record header.
*/
*eosaf = read_record_hdr(ifd, rec_hdr_tmp, &record_hdr[*curr],
- &file_hdr, arch_64, endian_mismatch, UEOF_STOP, b_size, flags);
+ &file_hdr, arch_64, endian_mismatch, UEOF_STOP, b_size,
+ flags, &sar_fmt);
rtype = record_hdr[*curr].record_type;
if ((lines >= rows) || !lines) {
if (rtype != R_COMMENT) {
/* Read the extra fields since it's not a special record */
- read_file_stat_bunch(act, *curr, ifd, file_hdr.sa_act_nr, file_actlst,
- endian_mismatch, arch_64, file, file_magic, UEOF_STOP);
+ if (read_file_stat_bunch(act, *curr, ifd, file_hdr.sa_act_nr, file_actlst,
+ endian_mismatch, arch_64, file, file_magic, UEOF_STOP))
+ /* Error or unexpected EOF */
+ break;
}
else {
/* Display comment */
if ((file_hdr.act_size != FILE_ACTIVITY_SIZE) ||
(file_hdr.rec_size != RECORD_HEADER_SIZE)) {
#ifdef DEBUG
- fprintf(stderr, "%s: act_size=%u/%lu rec_size=%u/%lu\n", __FUNCTION__,
+ fprintf(stderr, "%s: act_size=%u/%zu rec_size=%u/%zu\n", __FUNCTION__,
file_hdr.act_size, FILE_ACTIVITY_SIZE, file_hdr.rec_size, RECORD_HEADER_SIZE);
#endif
print_read_error(INCONSISTENT_INPUT_DATA);
*/
do {
if (read_record_hdr(ifd, rec_hdr_tmp, &record_hdr[0], &file_hdr,
- arch_64, endian_mismatch, UEOF_STOP, sizeof(rec_hdr_tmp), flags)) {
+ arch_64, endian_mismatch, UEOF_STOP, sizeof(rec_hdr_tmp), flags, &sar_fmt)) {
/* End of sa data file */
return;
}
* OK: Previous record was not a special one.
* So read now the extra fields.
*/
- read_file_stat_bunch(act, 0, ifd, file_hdr.sa_act_nr,
- file_actlst, endian_mismatch, arch_64,
- from_file, &file_magic, UEOF_STOP);
+ if (read_file_stat_bunch(act, 0, ifd, file_hdr.sa_act_nr,
+ file_actlst, endian_mismatch, arch_64,
+ from_file, &file_magic, UEOF_STOP))
+ /* Possible unexpected EOF */
+ return;
+
if (sa_get_record_timestamp_struct(flags + S_F_LOCAL_TIME,
&record_hdr[0], &rectime))
/*
do {
/* Read next record header */
eosaf = read_record_hdr(ifd, rec_hdr_tmp, &record_hdr[curr],
- &file_hdr, arch_64, endian_mismatch, UEOF_STOP, sizeof(rec_hdr_tmp), flags);
+ &file_hdr, arch_64, endian_mismatch, UEOF_STOP, sizeof(rec_hdr_tmp), flags, &sar_fmt);
rtype = record_hdr[curr].record_type;
if (eosaf || (rtype == R_RESTART))
break;
if (rtype != R_COMMENT) {
- read_file_stat_bunch(act, curr, ifd, file_hdr.sa_act_nr,
- file_actlst, endian_mismatch, arch_64,
- from_file, &file_magic, UEOF_STOP);
+ if (read_file_stat_bunch(act, curr, ifd, file_hdr.sa_act_nr,
+ file_actlst, endian_mismatch, arch_64,
+ from_file, &file_magic, UEOF_STOP))
+ /* Possible unexpected EOF */
+ break;
}
else {
- /* This was a COMMENT record: print it */
+ /* This was a COMMENT record: Print it */
print_special_record(&record_hdr[curr], flags + S_F_LOCAL_TIME,
&tm_start, &tm_end, R_COMMENT, ifd,
&rectime, from_file, 0,