Skip to content

Commit 3e5cb4c

Browse files
committed
Option -c added to sadf: Upgrade an old sa datafile
This patch adds option -c to sadf. This option enables the user to upgrade ("convert") an old system activity datafile (version 9.1.6 and later) to the up-to-date format (11.1.1 as of today). Enter "sadf -c old_datafile >new_datafile". Signed-off-by: Sebastien GODARD <[email protected]>
1 parent 40046f9 commit 3e5cb4c

File tree

9 files changed

+1298
-61
lines changed

9 files changed

+1298
-61
lines changed

Makefile.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ format.o: format.c sadf.h
208208

209209
sadf_misc.o: sadf_misc.c sadf.h sa.h
210210

211+
sa_conv.o: sa_conv.c sadf.h sa.h sa_conv.h
212+
211213
# Explicit rules needed to prevent possible file corruption
212214
# when using parallel execution.
213215
libsyscom.a: common.o ioconf.o
@@ -233,7 +235,7 @@ sar: sar.o act_sar.o sa_common.o pr_stats.o libsyscom.a
233235

234236
sadf.o: sadf.c sadf.h version.h sa.h common.h ioconf.h sysconfig.h
235237

236-
sadf: sadf.o act_sadf.o format.o sadf_misc.o rndr_stats.o xml_stats.o json_stats.o sa_common.o libsyscom.a
238+
sadf: sadf.o act_sadf.o format.o sadf_misc.o sa_conv.o rndr_stats.o xml_stats.o json_stats.o sa_common.o libsyscom.a
237239

238240
iostat.o: iostat.c iostat.h version.h common.h ioconf.h sysconfig.h rd_stats.h count.h
239241

format.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ struct report_format json_fmt = {
9494
.f_comment = print_json_comment
9595
};
9696

97+
/*
98+
* Display only datafile header.
99+
*/
100+
struct report_format conv_fmt = {
101+
.id = F_CONV_OUTPUT,
102+
.options = FO_BAD_FILE_FORMAT,
103+
.f_header = NULL,
104+
.f_statistics = NULL,
105+
.f_timestamp = NULL,
106+
.f_restart = NULL,
107+
.f_comment = NULL
108+
};
109+
97110
/*
98111
* Array of output formats.
99112
*/
@@ -102,5 +115,6 @@ struct report_format *fmt[NR_FMT] = {
102115
&db_fmt,
103116
&ppc_fmt,
104117
&xml_fmt,
105-
&json_fmt
118+
&json_fmt,
119+
&conv_fmt
106120
};

sa.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ struct activity {
487487
*/
488488
#define FORMAT_MAGIC 0x2173
489489

490+
/* Previous datafile format magic number used by older sysstat versions */
491+
#define PREVIOUS_FORMAT_MAGIC 0x2171
492+
490493
/* Structure for file magic header data */
491494
struct file_magic {
492495
/*
@@ -508,10 +511,17 @@ struct file_magic {
508511
* Size of file's header (size of file_header structure used by file).
509512
*/
510513
unsigned int header_size;
514+
/*
515+
* Set to non zero if data file has been converted with "sadf -c" from
516+
* an old format (version x.y.z) to a newest format (version X.Y.Z).
517+
* In this case, the value is: Y*16 + Z + 1.
518+
* The FORMAT_MAGIC value of the file can be used to determine X.
519+
*/
520+
unsigned char upgraded;
511521
/*
512522
* Padding. Reserved for future use while avoiding a format change.
513523
*/
514-
unsigned char pad[64];
524+
unsigned char pad[63];
515525
};
516526

517527
#define FILE_MAGIC_SIZE (sizeof(struct file_magic))
@@ -829,6 +839,8 @@ extern int
829839
datecmp(struct tm *, struct tstamp *);
830840
extern void
831841
display_sa_file_version(FILE *, struct file_magic *);
842+
extern void
843+
enum_version_nr(struct file_magic *);
832844
extern void
833845
free_bitmaps(struct activity * []);
834846
extern void
@@ -871,6 +883,8 @@ extern int
871883
reallocate_vol_act_structures(struct activity * [], unsigned int, unsigned int);
872884
extern int
873885
sa_fread(int, void *, int, int);
886+
extern int
887+
sa_open_read_magic(int *, char *, struct file_magic *, int);
874888
extern void
875889
select_all_activities(struct activity * []);
876890
extern void

sa_common.c

Lines changed: 93 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <sys/types.h>
3232
#include <sys/stat.h>
3333

34+
#include "version.h"
3435
#include "sa.h"
3536
#include "common.h"
3637
#include "ioconf.h"
@@ -1209,37 +1210,30 @@ void read_file_stat_bunch(struct activity *act[], int curr, int ifd, int act_nr,
12091210

12101211
/*
12111212
***************************************************************************
1212-
* Open a data file, and perform various checks before reading.
1213+
* Open a sysstat activity data file and read its magic structure.
12131214
*
12141215
* IN:
1215-
* @dfile Name of system activity data file
1216-
* @act Array of activities.
1216+
* @dfile Name of system activity data file.
12171217
* @ignore Set to 1 if a true sysstat activity file but with a bad
12181218
* format should not yield an error message. Useful with
12191219
* sadf -H.
12201220
*
12211221
* OUT:
1222-
* @ifd System activity data file descriptor
1222+
* @fd System activity data file descriptor.
12231223
* @file_magic file_magic structure containing data read from file magic
1224-
* header
1225-
* @file_hdr file_hdr structure containing data read from file standard
1226-
* header
1227-
* @file_actlst Acvtivity list in file.
1228-
* @id_seq Activity sequence.
1224+
* header.
1225+
*
1226+
* RETURNS:
1227+
* -1 if data file is a sysstat file with an old format, 0 otherwise.
12291228
***************************************************************************
12301229
*/
1231-
void check_file_actlst(int *ifd, char *dfile, struct activity *act[],
1232-
struct file_magic *file_magic, struct file_header *file_hdr,
1233-
struct file_activity **file_actlst, unsigned int id_seq[],
1230+
int sa_open_read_magic(int *fd, char *dfile, struct file_magic *file_magic,
12341231
int ignore)
12351232
{
1236-
int i, j, n, p;
1237-
unsigned int a_cpu = FALSE;
1238-
struct file_activity *fal;
1239-
void *buffer = NULL;
1233+
int n;
12401234

12411235
/* Open sa data file */
1242-
if ((*ifd = open(dfile, O_RDONLY)) < 0) {
1236+
if ((*fd = open(dfile, O_RDONLY)) < 0) {
12431237
int saved_errno = errno;
12441238

12451239
fprintf(stderr, _("Cannot open %s: %s\n"), dfile, strerror(errno));
@@ -1251,22 +1245,55 @@ void check_file_actlst(int *ifd, char *dfile, struct activity *act[],
12511245
}
12521246

12531247
/* Read file magic data */
1254-
n = read(*ifd, file_magic, FILE_MAGIC_SIZE);
1248+
n = read(*fd, file_magic, FILE_MAGIC_SIZE);
12551249

12561250
if ((n != FILE_MAGIC_SIZE) ||
12571251
(file_magic->sysstat_magic != SYSSTAT_MAGIC) ||
1258-
(file_magic->format_magic != FORMAT_MAGIC)) {
1259-
1260-
if (ignore &&
1261-
(n == FILE_MAGIC_SIZE) &&
1262-
(file_magic->sysstat_magic == SYSSTAT_MAGIC))
1263-
/* Don't display error message. This is for sadf -H */
1264-
return;
1265-
else {
1266-
/* Display error message and exit */
1267-
handle_invalid_sa_file(ifd, file_magic, dfile, n);
1268-
}
1252+
((file_magic->format_magic != FORMAT_MAGIC) && !ignore)) {
1253+
/* Display error message and exit */
1254+
handle_invalid_sa_file(fd, file_magic, dfile, n);
12691255
}
1256+
if (file_magic->format_magic != FORMAT_MAGIC)
1257+
/* This is an old sa datafile format */
1258+
return -1;
1259+
1260+
return 0;
1261+
}
1262+
1263+
/*
1264+
***************************************************************************
1265+
* Open a data file, and perform various checks before reading.
1266+
*
1267+
* IN:
1268+
* @dfile Name of system activity data file.
1269+
* @act Array of activities.
1270+
* @ignore Set to 1 if a true sysstat activity file but with a bad
1271+
* format should not yield an error message. Useful with
1272+
* sadf -H.
1273+
*
1274+
* OUT:
1275+
* @ifd System activity data file descriptor.
1276+
* @file_magic file_magic structure containing data read from file magic
1277+
* header.
1278+
* @file_hdr file_hdr structure containing data read from file standard
1279+
* header.
1280+
* @file_actlst Acvtivity list in file.
1281+
* @id_seq Activity sequence.
1282+
***************************************************************************
1283+
*/
1284+
void check_file_actlst(int *ifd, char *dfile, struct activity *act[],
1285+
struct file_magic *file_magic, struct file_header *file_hdr,
1286+
struct file_activity **file_actlst, unsigned int id_seq[],
1287+
int ignore)
1288+
{
1289+
int i, j, p;
1290+
unsigned int a_cpu = FALSE;
1291+
struct file_activity *fal;
1292+
void *buffer = NULL;
1293+
1294+
/* Open sa data file and read its magic structure */
1295+
if (sa_open_read_magic(ifd, dfile, file_magic, ignore) < 0)
1296+
return;
12701297

12711298
SREALLOC(buffer, char, file_magic->header_size);
12721299

@@ -1940,3 +1967,40 @@ double compute_ifutil(struct stats_net_dev *st_net_dev, double rx, double tx)
19401967
return 0;
19411968
}
19421969

1970+
/*
1971+
***************************************************************************
1972+
* Fill system activity file magic header.
1973+
*
1974+
* IN:
1975+
* @file_magic System activity file magic header.
1976+
***************************************************************************
1977+
*/
1978+
void enum_version_nr(struct file_magic *fm)
1979+
{
1980+
char *v;
1981+
char version[16];
1982+
1983+
fm->sysstat_extraversion = 0;
1984+
1985+
strcpy(version, VERSION);
1986+
1987+
/* Get version number */
1988+
if ((v = strtok(version, ".")) == NULL)
1989+
return;
1990+
fm->sysstat_version = atoi(v) & 0xff;
1991+
1992+
/* Get patchlevel number */
1993+
if ((v = strtok(NULL, ".")) == NULL)
1994+
return;
1995+
fm->sysstat_patchlevel = atoi(v) & 0xff;
1996+
1997+
/* Get sublevel number */
1998+
if ((v = strtok(NULL, ".")) == NULL)
1999+
return;
2000+
fm->sysstat_sublevel = atoi(v) & 0xff;
2001+
2002+
/* Get extraversion number. Don't necessarily exist */
2003+
if ((v = strtok(NULL, ".")) == NULL)
2004+
return;
2005+
fm->sysstat_extraversion = atoi(v) & 0xff;
2006+
}

0 commit comments

Comments
 (0)