* been used or not) can be saved for current record.
* @loctime Structure where timestamp (expressed in local time)
* can be saved for current record.
+ * @new_cpu_nr CPU count associated with restart mark.
*
* OUT:
* @rectime Structure where timestamp for current record has
***************************************************************************
*/
void write_textual_restarts(int curr, int use_tm_start, int use_tm_end, int tab,
- struct tm *rectime, struct tm *loctime)
+ struct tm *rectime, struct tm *loctime,
+ unsigned int new_cpu_nr)
{
char cur_date[32], cur_time[32];
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);
+ !PRINT_TRUE_TIME(flags), &file_hdr,
+ new_cpu_nr);
}
}
{
char cur_date[32], cur_time[32];
int dp = 1;
+ unsigned int new_cpu_nr;
/* Fill timestamp structure (rectime) for current record */
sadf_get_record_timestamp_struct(curr, rectime, loctime);
}
if (rtype == R_RESTART) {
+ /* Don't forget to read new number of CPU */
+ new_cpu_nr = read_new_cpu_nr(ifd, act);
+
if (!dp)
return;
if (*fmt[f_position]->f_restart) {
(*fmt[f_position]->f_restart)(NULL, F_MAIN, cur_date, cur_time,
!PRINT_LOCAL_TIME(flags) &&
- !PRINT_TRUE_TIME(flags), &file_hdr);
+ !PRINT_TRUE_TIME(flags), &file_hdr,
+ new_cpu_nr);
}
}
else if (rtype == R_COMMENT) {
{
int curr, tab = 0, rtype;
int eosaf = TRUE, next, reset = FALSE;
+ unsigned int save_cpu_nr, new_cpu_nr;
long cnt = 1;
off_t fpos;
perror("lseek");
exit(2);
}
+ /* Save number of CPU items for current file position */
+ save_cpu_nr = act[get_activity_position(act, A_CPU)]->nr;
/* Print header (eg. XML file header) */
if (*fmt[f_position]->f_header) {
eosaf = sa_fread(ifd, &record_hdr[0], RECORD_HEADER_SIZE, SOFT_SIZE);
rtype = record_hdr[0].record_type;
- if (!eosaf && (rtype != R_RESTART) && (rtype != R_COMMENT)) {
- /*
- * OK: Previous record was not a special one.
- * So read now the extra fields.
- */
- read_file_stat_bunch(act, 0, ifd, file_hdr.sa_nr_act,
- file_actlst);
- sadf_get_record_timestamp_struct(0, rectime, loctime);
- }
-
- if (!eosaf && (rtype == R_COMMENT)) {
- /*
- * Ignore COMMENT record.
- * (Unlike RESTART records, COMMENT records have an additional
- * comment field).
- */
- if (lseek(ifd, MAX_COMMENT_LEN, SEEK_CUR) < MAX_COMMENT_LEN) {
- perror("lseek");
+ if (!eosaf) {
+ if (rtype == R_COMMENT) {
+ /* Ignore COMMENT record */
+ if (lseek(ifd, MAX_COMMENT_LEN, SEEK_CUR) < MAX_COMMENT_LEN) {
+ perror("lseek");
+ }
+ }
+ else if (rtype == R_RESTART) {
+ /*
+ * Ignore RESTART record (don't display it)
+ * but anyway we have to reallocate CPU structures
+ * according to new CPU count (value saved after RESTART record).
+ */
+ read_new_cpu_nr(ifd, act);
+ }
+ else {
+ /*
+ * OK: Previous record was not a special one.
+ * So read now the extra fields.
+ */
+ read_file_stat_bunch(act, 0, ifd, file_hdr.sa_nr_act,
+ file_actlst);
+ sadf_get_record_timestamp_struct(0, rectime, loctime);
}
}
}
SOFT_SIZE);
rtype = record_hdr[curr].record_type;
- if (!eosaf && (rtype != R_RESTART) && (rtype != R_COMMENT)) {
- /* Read the extra fields since it's not a special record */
- read_file_stat_bunch(act, curr, ifd, file_hdr.sa_nr_act,
- file_actlst);
-
- if (*fmt[f_position]->f_statistics) {
- (*fmt[f_position]->f_statistics)(&tab, F_MAIN);
+ if (!eosaf) {
+ if (rtype == R_COMMENT) {
+ /* Ignore COMMENT record */
+ if (lseek(ifd, MAX_COMMENT_LEN, SEEK_CUR) < MAX_COMMENT_LEN) {
+ perror("lseek");
+ }
}
+ else if (rtype == R_RESTART) {
+ /*
+ * Ignore RESTART record (don't display it)
+ * but anyway we have to reallocate CPU structures
+ * according to new CPU count (value saved after RESTART record.
+ */
+ read_new_cpu_nr(ifd, act);
+ }
+ else {
+ /* This is not a special record, so read the extra fields */
+ read_file_stat_bunch(act, curr, ifd, file_hdr.sa_nr_act,
+ file_actlst);
- /* next is set to 1 when we were close enough to desired interval */
- next = write_textual_stats(curr, tm_start.use, tm_end.use, reset,
- &cnt, tab, cpu_nr, rectime, loctime);
-
- if (next) {
- curr ^= 1;
- if (cnt > 0) {
- cnt--;
+ if (*fmt[f_position]->f_statistics) {
+ (*fmt[f_position]->f_statistics)(&tab, F_MAIN);
}
- }
- reset = FALSE;
- }
- if (!eosaf && (rtype == R_COMMENT)) {
- /* Ignore COMMENT record */
- if (lseek(ifd, MAX_COMMENT_LEN, SEEK_CUR) < MAX_COMMENT_LEN) {
- perror("lseek");
+ /* next is set to 1 when we were close enough to desired interval */
+ next = write_textual_stats(curr, tm_start.use, tm_end.use, reset,
+ &cnt, tab, cpu_nr, rectime, loctime);
+
+ if (next) {
+ curr ^= 1;
+ if (cnt > 0) {
+ cnt--;
+ }
+ }
+ reset = FALSE;
}
}
}
eosaf = sa_fread(ifd, &record_hdr[curr], RECORD_HEADER_SIZE,
SOFT_SIZE);
rtype = record_hdr[curr].record_type;
- if (!eosaf && (rtype != R_RESTART) && (rtype != R_COMMENT)) {
- read_file_stat_bunch(act, curr, ifd, file_hdr.sa_nr_act,
- file_actlst);
- }
- else if (!eosaf && (rtype == R_COMMENT)) {
- /* Ignore COMMENT record */
- if (lseek(ifd, MAX_COMMENT_LEN, SEEK_CUR) < MAX_COMMENT_LEN) {
- perror("lseek");
+ if (!eosaf) {
+ if (rtype == R_COMMENT) {
+ /* Ignore COMMENT record */
+ if (lseek(ifd, MAX_COMMENT_LEN, SEEK_CUR) < MAX_COMMENT_LEN) {
+ perror("lseek");
+ }
+ }
+ else if (rtype == R_RESTART) {
+ /*
+ * Ignore RESTART record (don't display it)
+ * but anyway we have to reallocate CPU structures
+ * according to new CPU count (value saved after RESTART record.
+ */
+ read_new_cpu_nr(ifd, act);
+ }
+ else {
+ /* This is not a special record: Read the extra fields */
+ read_file_stat_bunch(act, curr, ifd, file_hdr.sa_nr_act,
+ file_actlst);
}
}
}
(*fmt[f_position]->f_statistics)(&tab, F_END);
}
- /* Rewind file */
+ /* Rewind file... */
if (lseek(ifd, fpos, SEEK_SET) < fpos) {
perror("lseek");
exit(2);
}
+ /* ... and restore number of CPU items for this position in file */
+ allocate_cpu_structures(act, save_cpu_nr);
/* Process now RESTART entries to display restart messages */
if (*fmt[f_position]->f_restart) {
(*fmt[f_position]->f_restart)(&tab, F_BEGIN, NULL, NULL, FALSE,
- &file_hdr);
+ &file_hdr, 0);
}
do {
SOFT_SIZE)) == 0) {
rtype = record_hdr[0].record_type;
- if ((rtype != R_RESTART) && (rtype != R_COMMENT)) {
- read_file_stat_bunch(act, 0, ifd, file_hdr.sa_nr_act,
- file_actlst);
- }
if (rtype == R_RESTART) {
+ /* Read new CPU count */
+ new_cpu_nr = read_new_cpu_nr(ifd, act);
+
+ /* Display RESTART records */
write_textual_restarts(0, tm_start.use, tm_end.use, tab,
- rectime, loctime);
+ rectime, loctime, new_cpu_nr);
}
else if (rtype == R_COMMENT) {
/* Ignore COMMENT record */
perror("lseek");
}
}
+ else {
+ /* Not a special record: Read the extra fields */
+ read_file_stat_bunch(act, 0, ifd, file_hdr.sa_nr_act,
+ file_actlst);
+ }
}
}
while (!eosaf);
if (*fmt[f_position]->f_restart) {
- (*fmt[f_position]->f_restart)(&tab, F_END, NULL, NULL, FALSE, &file_hdr);
+ (*fmt[f_position]->f_restart)(&tab, F_END, NULL, NULL, FALSE, &file_hdr, 0);
}
- /* Rewind file */
+ /* Rewind file... */
if (lseek(ifd, fpos, SEEK_SET) < fpos) {
perror("lseek");
exit(2);
}
+ /* ... and restore number of CPU items for this position in file */
+ allocate_cpu_structures(act, save_cpu_nr);
/* Last, process COMMENT entries to display comments */
if (DISPLAY_COMMENT(flags)) {
SOFT_SIZE)) == 0) {
rtype = record_hdr[0].record_type;
- if ((rtype != R_RESTART) && (rtype != R_COMMENT)) {
- read_file_stat_bunch(act, 0, ifd, file_hdr.sa_nr_act,
- file_actlst);
- }
if (rtype == R_COMMENT) {
+ /* Display R_COMMENT records */
write_textual_comments(0, tm_start.use, tm_end.use,
tab, ifd, rectime, loctime);
}
+ else if (rtype == R_RESTART) {
+ /*
+ * Ignore RESTART record (don't display it)
+ * but anyway we have to reallocate CPU structures
+ * according to new CPU count (value saved after RESTART record.
+ */
+ read_new_cpu_nr(ifd, act);
+ }
+ else {
+ /* Not a special record: Read the extra fields */
+ read_file_stat_bunch(act, 0, ifd, file_hdr.sa_nr_act,
+ file_actlst);
+ }
}
}
while (!eosaf);
eosaf = sa_fread(ifd, &record_hdr[curr], RECORD_HEADER_SIZE,
SOFT_SIZE);
rtype = record_hdr[curr].record_type;
- if (!eosaf && (rtype != R_RESTART) && (rtype != R_COMMENT)) {
- read_file_stat_bunch(act, curr, ifd, file_hdr.sa_nr_act,
- file_actlst);
- }
- else if (!eosaf && (rtype == R_COMMENT)) {
- /* This was a COMMENT record: print it */
- sadf_print_special(curr, tm_start.use, tm_end.use,
- R_COMMENT, ifd, rectime, loctime);
+ if (!eosaf) {
+ if (rtype == R_COMMENT) {
+ /* This was a COMMENT record: print it */
+ sadf_print_special(curr, tm_start.use, tm_end.use,
+ R_COMMENT, ifd, rectime, loctime);
+ }
+ else if (rtype != R_RESTART) {
+ /* This is not a RESTART or a COMMENT record */
+ read_file_stat_bunch(act, curr, ifd, file_hdr.sa_nr_act,
+ file_actlst);
+ }
}
}
while (!eosaf && (rtype != R_RESTART));
* @utc True if @cur_time is expressed in UTC.
* @sep Character used as separator.
* @file_hdr System activity file standard header.
+ * @cpu_nr CPU count associated with restart mark.
***************************************************************************
*/
void print_dbppc_restart(char *cur_date, char *cur_time, int utc, char sep,
- struct file_header *file_hdr)
+ struct file_header *file_hdr, unsigned int cpu_nr)
{
printf("%s%c-1%c", file_hdr->sa_nodename, sep, sep);
if (strlen(cur_date)) {
if (strlen(cur_date) && utc) {
printf(" UTC");
}
- printf("%cLINUX-RESTART\n", sep);
+ printf("%cLINUX-RESTART\t(%d CPU)\n",
+ sep, cpu_nr > 1 ? cpu_nr - 1 : 1);
}
/*
* @cur_time Time string of current restart message.
* @utc True if @cur_time is expressed in UTC.
* @file_hdr System activity file standard header.
+ * @cpu_nr CPU count associated with restart mark.
***************************************************************************
*/
__printf_funct_t print_db_restart(int *tab, int action, char *cur_date,
- char *cur_time, int utc, struct file_header *file_hdr)
+ char *cur_time, int utc, struct file_header *file_hdr,
+ unsigned int cpu_nr)
{
/* Actions F_BEGIN and F_END ignored */
if (action == F_MAIN) {
- print_dbppc_restart(cur_date, cur_time, utc, ';', file_hdr);
+ print_dbppc_restart(cur_date, cur_time, utc, ';', file_hdr, cpu_nr);
}
}
* @cur_time Time string of current restart message.
* @utc True if @cur_time is expressed in UTC.
* @file_hdr System activity file standard header.
+ * @cpu_nr CPU count associated with restart mark.
***************************************************************************
*/
__printf_funct_t print_ppc_restart(int *tab, int action, char *cur_date,
- char *cur_time, int utc, struct file_header *file_hdr)
+ char *cur_time, int utc, struct file_header *file_hdr,
+ unsigned int cpu_nr)
{
/* Actions F_BEGIN and F_END ignored */
if (action == F_MAIN) {
- print_dbppc_restart(cur_date, cur_time, utc, '\t', file_hdr);
+ print_dbppc_restart(cur_date, cur_time, utc, '\t', file_hdr, cpu_nr);
}
}
* @cur_time Time string of current restart message.
* @utc True if @cur_time is expressed in UTC.
* @file_hdr System activity file standard header (unused here).
+ * @cpu_nr CPU count associated with restart mark.
*
* OUT:
* @tab Number of tabulations.
***************************************************************************
*/
__printf_funct_t print_xml_restart(int *tab, int action, char *cur_date,
- char *cur_time, int utc, struct file_header *file_hdr)
+ char *cur_time, int utc, struct file_header *file_hdr,
+ unsigned int cpu_nr)
{
if (action & F_BEGIN) {
xprintf((*tab)++, "<restarts>");
}
if (action & F_MAIN) {
- xprintf(*tab, "<boot date=\"%s\" time=\"%s\" utc=\"%d\"/>",
- cur_date, cur_time, utc ? 1 : 0);
+ xprintf(*tab, "<boot date=\"%s\" time=\"%s\" utc=\"%d\" cpu_count=\"%d\"/>",
+ cur_date, cur_time, utc ? 1 : 0, cpu_nr > 1 ? cpu_nr - 1 : 1);
}
if (action & F_END) {
xprintf(--(*tab), "</restarts>");
* @cur_time Time string of current restart message.
* @utc True if @cur_time is expressed in UTC.
* @file_hdr System activity file standard header (unused here).
+ * @cpu_nr CPU count associated with restart mark.
*
* OUT:
* @tab Number of tabulations.
***************************************************************************
*/
__printf_funct_t print_json_restart(int *tab, int action, char *cur_date,
- char *cur_time, int utc, struct file_header *file_hdr)
+ char *cur_time, int utc, struct file_header *file_hdr,
+ unsigned int cpu_nr)
{
static int sep = FALSE;
printf(",\n");
}
xprintf((*tab)++, "{");
- xprintf(*tab, "\"boot\": {\"date\": \"%s\", \"time\": \"%s\", \"utc\": %d}",
- cur_date, cur_time, utc ? 1 : 0);
+ xprintf(*tab, "\"boot\": {\"date\": \"%s\", \"time\": \"%s\", \"utc\": %d, \"cpu_count\": %d}",
+ cur_date, cur_time, utc ? 1 : 0, cpu_nr > 1 ? cpu_nr - 1 : 1);
xprintf0(--(*tab), "}");
sep = TRUE;
}