/* *************************************************************************** * Print contents of a special (RESTART or COMMENT) record. * * IN: * @curr Index in array for current sample statistics. * @use_tm_start Set to TRUE if option -s has been used. * @use_tm_end Set to TRUE if option -e has been used. * @rtype Record type (RESTART or COMMENT). * @ifd Input file descriptor. * @rectime Structure where timestamp (expressed in local time * or in UTC depending on whether options -T/-t have * been used or not) can be saved for current record. * @loctime Structure where timestamp (expressed in local time) * can be saved for current record. * @file Name of file being read. * @tab Number of tabulations to print. * @file_magic file_magic structure filled with file magic header * data. *************************************************************************** */ void print_special_record(int curr, int use_tm_start, int use_tm_end, int rtype, int ifd, struct tm *rectime, struct tm *loctime, char *file, int tab, struct file_magic *file_magic) { char cur_date[32], cur_time[32]; int dp = 1; unsigned int new_cpu_nr; /* Fill timestamp structure (rectime) for current record */ sa_get_record_timestamp_struct(flags, &record_hdr[curr], rectime, loctime); /* The record must be in the interval specified by -s/-e options */ if ((use_tm_start && (datecmp(loctime, &tm_start) < 0)) || (use_tm_end && (datecmp(loctime, &tm_end) > 0))) { /* Will not display the special record */ dp = 0; } else { /* Set date and time strings to be displayed for current record */ set_record_timestamp_string(curr, cur_date, cur_time, 32, rectime); } if (rtype == R_RESTART) { /* Don't forget to read the volatile activities structures */ new_cpu_nr = read_vol_act_structures(ifd, act, file, file_magic, file_hdr.sa_vol_act_nr); if (!dp) return; if (*fmt[f_position]->f_restart) { (*fmt[f_position]->f_restart)(&tab, F_MAIN, cur_date, cur_time, !PRINT_LOCAL_TIME(flags) && !PRINT_TRUE_TIME(flags), &file_hdr, new_cpu_nr); } } else if (rtype == R_COMMENT) { char file_comment[MAX_COMMENT_LEN]; /* Read and replace non printable chars in comment */ replace_nonprintable_char(ifd, file_comment); if (!dp || !DISPLAY_COMMENT(flags)) return; if (*fmt[f_position]->f_comment) { (*fmt[f_position]->f_comment)(&tab, F_MAIN, cur_date, cur_time, !PRINT_LOCAL_TIME(flags) && !PRINT_TRUE_TIME(flags), file_comment, &file_hdr); } } }
/* *************************************************************************** * Print a Linux restart message (contents of a RESTART record) or a * comment (contents of a COMMENT record). * * IN: * @curr Index in array for current sample statistics. * @use_tm_start Set to TRUE if option -s has been used. * @use_tm_end Set to TRUE if option -e has been used. * @rtype Record type to display. * @ifd Input file descriptor. * @file Name of file being read. * @file_magic file_magic structure filled with file magic header * data. * * RETURNS: * 1 if the record has been successfully displayed, and 0 otherwise. *************************************************************************** */ int sar_print_special(int curr, int use_tm_start, int use_tm_end, int rtype, int ifd, char *file, struct file_magic *file_magic) { char cur_time[26], restart[64]; int dp = 1; unsigned int new_cpu_nr; if (set_record_timestamp_string(curr, cur_time, 26)) return 0; /* The record must be in the interval specified by -s/-e options */ if ((use_tm_start && (datecmp(&rectime, &tm_start) < 0)) || (use_tm_end && (datecmp(&rectime, &tm_end) > 0))) { dp = 0; } if (rtype == R_RESTART) { /* Don't forget to read the volatile activities structures */ new_cpu_nr = read_vol_act_structures(ifd, act, file, file_magic, file_hdr.sa_vol_act_nr); if (dp) { printf("\n%-11s", cur_time); sprintf(restart, " LINUX RESTART\t(%d CPU)\n", new_cpu_nr > 1 ? new_cpu_nr - 1 : 1); cprintf_s(IS_RESTART, "%s", restart); return 1; } } else if (rtype == R_COMMENT) { char file_comment[MAX_COMMENT_LEN]; /* Don't forget to read comment record even if it won't be displayed... */ replace_nonprintable_char(ifd, file_comment); if (dp && DISPLAY_COMMENT(flags)) { printf("%-11s", cur_time); cprintf_s(IS_COMMENT, " COM %s\n", file_comment); return 1; } } return 0; }