From 39ba5613c580804a6c394b04360ca6b8fbc9f928 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sat, 23 Dec 2017 16:52:12 +0100 Subject: [PATCH] sadf.c: Simplify code Signed-off-by: Sebastien GODARD --- sadf.c | 98 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/sadf.c b/sadf.c index a8c5067..be25da1 100644 --- a/sadf.c +++ b/sadf.c @@ -233,70 +233,70 @@ int read_next_sample(int ifd, int action, int curr, char *file, int *rtype, int struct file_magic *file_magic, struct file_activity *file_actlst, struct tm *rectime, struct tm *loctime) { - int eosaf; char rec_hdr_tmp[MAX_RECORD_HEADER_SIZE]; /* Read current record */ - eosaf = read_record_hdr(ifd, rec_hdr_tmp, &record_hdr[curr], &file_hdr, - arch_64, endian_mismatch); + if (read_record_hdr(ifd, rec_hdr_tmp, &record_hdr[curr], &file_hdr, + arch_64, endian_mismatch)) + /* End of sa file */ + return TRUE; + *rtype = record_hdr[curr].record_type; - if (!eosaf) { - if (*rtype == R_COMMENT) { - if (action & IGNORE_COMMENT) { - /* Ignore COMMENT record */ - if (lseek(ifd, MAX_COMMENT_LEN, SEEK_CUR) < MAX_COMMENT_LEN) { - perror("lseek"); - } - if (action & SET_TIMESTAMPS) { - sa_get_record_timestamp_struct(flags, &record_hdr[curr], - rectime, loctime); - } + if (*rtype == R_COMMENT) { + if (action & IGNORE_COMMENT) { + /* Ignore COMMENT record */ + if (lseek(ifd, MAX_COMMENT_LEN, SEEK_CUR) < MAX_COMMENT_LEN) { + perror("lseek"); } - else { - /* Display COMMENT record */ - print_special_record(&record_hdr[curr], flags, &tm_start, &tm_end, - *rtype, ifd, rectime, loctime, file, tab, - file_magic, &file_hdr, act, fmt[f_position], - endian_mismatch, arch_64); + if (action & SET_TIMESTAMPS) { + sa_get_record_timestamp_struct(flags, &record_hdr[curr], + rectime, loctime); } } - else if (*rtype == R_RESTART) { - if (action & IGNORE_RESTART) { - /* - * Ignore RESTART record (don't display it) - * but anyway we have to read the CPU number that follows it - * (unless we don't want to do it now). - */ - if (!(action & DONT_READ_CPU_NR)) { - file_hdr.sa_cpu_nr = read_nr_value(ifd, file, file_magic, - endian_mismatch, arch_64, TRUE); - } - if (action & SET_TIMESTAMPS) { - sa_get_record_timestamp_struct(flags, &record_hdr[curr], - rectime, loctime); - } + else { + /* Display COMMENT record */ + print_special_record(&record_hdr[curr], flags, &tm_start, &tm_end, + *rtype, ifd, rectime, loctime, file, tab, + file_magic, &file_hdr, act, fmt[f_position], + endian_mismatch, arch_64); + } + } + else if (*rtype == R_RESTART) { + if (action & IGNORE_RESTART) { + /* + * Ignore RESTART record (don't display it) + * but anyway we have to read the CPU number that follows it + * (unless we don't want to do it now). + */ + if (!(action & DONT_READ_CPU_NR)) { + file_hdr.sa_cpu_nr = read_nr_value(ifd, file, file_magic, + endian_mismatch, arch_64, TRUE); } - else { - /* Display RESTART record */ - print_special_record(&record_hdr[curr], flags, &tm_start, &tm_end, - *rtype, ifd, rectime, loctime, file, tab, - file_magic, &file_hdr, act, fmt[f_position], - endian_mismatch, arch_64); + if (action & SET_TIMESTAMPS) { + sa_get_record_timestamp_struct(flags, &record_hdr[curr], + rectime, loctime); } } else { - /* - * OK: Previous record was not a special one. - * So read now the extra fields. - */ - read_file_stat_bunch(act, curr, ifd, file_hdr.sa_act_nr, - file_actlst, endian_mismatch, arch_64, file, file_magic); - sa_get_record_timestamp_struct(flags, &record_hdr[curr], rectime, loctime); + /* Display RESTART record */ + print_special_record(&record_hdr[curr], flags, &tm_start, &tm_end, + *rtype, ifd, rectime, loctime, file, tab, + file_magic, &file_hdr, act, fmt[f_position], + endian_mismatch, arch_64); } } + else { + /* + * OK: Previous record was not a special one. + * So read now the extra fields. + */ + read_file_stat_bunch(act, curr, ifd, file_hdr.sa_act_nr, + file_actlst, endian_mismatch, arch_64, file, file_magic); + sa_get_record_timestamp_struct(flags, &record_hdr[curr], rectime, loctime); + } - return eosaf; + return FALSE; } /* -- 2.40.0