]> granicus.if.org Git - sysstat/commitdiff
sadc: Compile out unneeded functions
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 17 Feb 2018 17:54:27 +0000 (18:54 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 17 Feb 2018 17:54:27 +0000 (18:54 +0100)
Reduce size for sadc binary (30% smaller) by compiling out unneeded
functions.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
Makefile.in
common.c
common.h
sa.h
sa_common.c

index bb0969b9a2297cf53748cb3b2162e08704d1fba0..a204022dc9afe1b1c73173cd5f440389ec2dcb6c 100644 (file)
@@ -172,8 +172,14 @@ NLSPOT= $(NLSPO:.po=.pot)
 
 all: sadc sar sadf iostat tapestat mpstat pidstat cifsiostat locales
 
+common_sadc.o: common.c version.h common.h
+       $(CC) -o $@ -c $(CFLAGS) -DSOURCE_SADC $(DFLAGS) $<
+
 common.o: common.c version.h common.h
 
+sa_common_sadc.o: sa_common.c version.h sa.h common.h rd_stats.h rd_sensors.h ioconf.h sysconfig.h
+       $(CC) -o $@ -c $(CFLAGS) -DSOURCE_SADC $(DFLAGS) $<
+
 sa_common.o: sa_common.c version.h sa.h common.h rd_stats.h rd_sensors.h ioconf.h sysconfig.h
 
 ioconf.o: ioconf.c ioconf.h common.h sysconfig.h
@@ -245,7 +251,8 @@ librdsensors.a: rd_sensors.o
 sadc.o: sadc.c sa.h version.h common.h rd_stats.h rd_sensors.h
 
 sadc: LFLAGS += $(LFSENSORS)
-sadc: sadc.o act_sadc.o sa_wrap.o sa_common.o librdstats.a librdsensors.a libsyscom.a
+
+sadc: sadc.o act_sadc.o sa_wrap.o sa_common_sadc.o common_sadc.o librdstats.a librdsensors.a
 
 sar.o: sar.c sa.h version.h common.h rd_stats.h rd_sensors.h
 
index bcec9b60d9c389336d3aacbd71151219fa57bcc5..fb3d2e29b604fce51ff085ad762d4be0e584b0f3 100644 (file)
--- a/common.c
+++ b/common.c
@@ -168,6 +168,113 @@ time_t get_time(struct tm *rectime, int d_off)
                return get_localtime(rectime, d_off);
 }
 
+#ifdef USE_NLS
+/*
+ ***************************************************************************
+ * Init National Language Support.
+ ***************************************************************************
+ */
+void init_nls(void)
+{
+       setlocale(LC_MESSAGES, "");
+       setlocale(LC_CTYPE, "");
+       setlocale(LC_TIME, "");
+       setlocale(LC_NUMERIC, "");
+
+       bindtextdomain(PACKAGE, LOCALEDIR);
+       textdomain(PACKAGE);
+}
+#endif
+
+/*
+ ***************************************************************************
+ * Test whether given name is a device or a partition, using sysfs.
+ * This is more straightforward that using ioc_iswhole() function from
+ * ioconf.c which should be used only with kernels that don't have sysfs.
+ *
+ * IN:
+ * @name               Device or partition name.
+ * @allow_virtual      TRUE if virtual devices are also accepted.
+ *                     The device is assumed to be virtual if no
+ *                     /sys/block/<device>/device link exists.
+ *
+ * RETURNS:
+ * TRUE if @name is not a partition.
+ ***************************************************************************
+ */
+int is_device(char *name, int allow_virtual)
+{
+       char syspath[PATH_MAX];
+       char *slash;
+
+       /* Some devices may have a slash in their name (eg. cciss/c0d0...) */
+       while ((slash = strchr(name, '/'))) {
+               *slash = '!';
+       }
+       snprintf(syspath, sizeof(syspath), "%s/%s%s", SYSFS_BLOCK, name,
+                allow_virtual ? "" : "/device");
+
+       return !(access(syspath, F_OK));
+}
+
+/*
+ ***************************************************************************
+ * Get page shift in kB.
+ ***************************************************************************
+ */
+void get_kb_shift(void)
+{
+       int shift = 0;
+       long size;
+
+       /* One can also use getpagesize() to get the size of a page */
+       if ((size = sysconf(_SC_PAGESIZE)) == -1) {
+               perror("sysconf");
+       }
+
+       size >>= 10;    /* Assume that a page has a minimum size of 1 kB */
+
+       while (size > 1) {
+               shift++;
+               size >>= 1;
+       }
+
+       kb_shift = (unsigned int) shift;
+}
+
+/*
+ ***************************************************************************
+ * Get number of clock ticks per second.
+ ***************************************************************************
+ */
+void get_HZ(void)
+{
+       long ticks;
+
+       if ((ticks = sysconf(_SC_CLK_TCK)) == -1) {
+               perror("sysconf");
+       }
+
+       hz = (unsigned long) ticks;
+}
+
+/*
+ ***************************************************************************
+ * Unhandled situation: Panic and exit. Should never happen.
+ *
+ * IN:
+ * @function   Function name where situation occured.
+ * @error_code Error code.
+ ***************************************************************************
+ */
+void sysstat_panic(const char *function, int error_code)
+{
+       fprintf(stderr, "sysstat: %s[%d]: Internal error...\n",
+               function, error_code);
+       exit(1);
+}
+
+#ifndef SOURCE_SADC
 /*
  ***************************************************************************
  * Count number of comma-separated values in arguments list. For example,
@@ -493,24 +600,6 @@ int print_gal_header(struct tm *rectime, char *sysname, char *release,
        return rc;
 }
 
-#ifdef USE_NLS
-/*
- ***************************************************************************
- * Init National Language Support.
- ***************************************************************************
- */
-void init_nls(void)
-{
-       setlocale(LC_MESSAGES, "");
-       setlocale(LC_CTYPE, "");
-       setlocale(LC_TIME, "");
-       setlocale(LC_NUMERIC, "");
-
-       bindtextdomain(PACKAGE, LOCALEDIR);
-       textdomain(PACKAGE);
-}
-#endif
-
 /*
  ***************************************************************************
  * Get number of rows for current window.
@@ -572,78 +661,6 @@ char *device_name(char *name)
        return out;
 }
 
-/*
- ***************************************************************************
- * Test whether given name is a device or a partition, using sysfs.
- * This is more straightforward that using ioc_iswhole() function from
- * ioconf.c which should be used only with kernels that don't have sysfs.
- *
- * IN:
- * @name               Device or partition name.
- * @allow_virtual      TRUE if virtual devices are also accepted.
- *                     The device is assumed to be virtual if no
- *                     /sys/block/<device>/device link exists.
- *
- * RETURNS:
- * TRUE if @name is not a partition.
- ***************************************************************************
- */
-int is_device(char *name, int allow_virtual)
-{
-       char syspath[PATH_MAX];
-       char *slash;
-
-       /* Some devices may have a slash in their name (eg. cciss/c0d0...) */
-       while ((slash = strchr(name, '/'))) {
-               *slash = '!';
-       }
-       snprintf(syspath, sizeof(syspath), "%s/%s%s", SYSFS_BLOCK, name,
-                allow_virtual ? "" : "/device");
-
-       return !(access(syspath, F_OK));
-}
-
-/*
- ***************************************************************************
- * Get page shift in kB.
- ***************************************************************************
- */
-void get_kb_shift(void)
-{
-       int shift = 0;
-       long size;
-
-       /* One can also use getpagesize() to get the size of a page */
-       if ((size = sysconf(_SC_PAGESIZE)) == -1) {
-               perror("sysconf");
-       }
-
-       size >>= 10;    /* Assume that a page has a minimum size of 1 kB */
-
-       while (size > 1) {
-               shift++;
-               size >>= 1;
-       }
-
-       kb_shift = (unsigned int) shift;
-}
-
-/*
- ***************************************************************************
- * Get number of clock ticks per second.
- ***************************************************************************
- */
-void get_HZ(void)
-{
-       long ticks;
-
-       if ((ticks = sysconf(_SC_CLK_TCK)) == -1) {
-               perror("sysconf");
-       }
-
-       hz = (unsigned long) ticks;
-}
-
 /*
  ***************************************************************************
  * Workaround for CPU counters read from /proc/stat: Dyn-tick kernels
@@ -686,22 +703,6 @@ unsigned long long get_interval(unsigned long long prev_uptime,
        return itv;
 }
 
-/*
- ***************************************************************************
- * Unhandled situation: Panic and exit. Should never happen.
- *
- * IN:
- * @function   Function name where situation occured.
- * @error_code Error code.
- ***************************************************************************
- */
-void sysstat_panic(const char *function, int error_code)
-{
-       fprintf(stderr, "sysstat: %s[%d]: Internal error...\n",
-               function, error_code);
-       exit(1);
-}
-
 /*
  ***************************************************************************
  * Count number of bits set in an array.
@@ -1403,3 +1404,4 @@ int parse_values(char *strargv, unsigned char bitmap[], int max_val, const char
 
        return 0;
 }
+#endif /* SOURCE_SADC undefined */
index a9716f676c31a0a92eecaa9a15e9725c9f86f38b..7fd2ca2babcaefe76efa0e31281aa00a63a11c4f 100644 (file)
--- a/common.h
+++ b/common.h
@@ -230,7 +230,24 @@ struct ext_disk_stats {
  * Functions prototypes
  ***************************************************************************
  */
+void print_version
+       (void);
+void get_HZ
+       (void);
+void get_kb_shift
+       (void);
+time_t get_localtime
+       (struct tm *, int);
+time_t get_time
+       (struct tm *, int);
+void init_nls
+       (void);
+int is_device
+       (char *, int);
+void sysstat_panic
+       (const char *, int);
 
+#ifndef SOURCE_SADC
 int count_bits
        (void *, int);
 int count_csvalues
@@ -249,18 +266,10 @@ void cprintf_x
        (int, int, ...);
 char *device_name
        (char *);
-void get_HZ
-       (void);
 unsigned int get_devmap_major
        (void);
 unsigned long long get_interval
        (unsigned long long, unsigned long long);
-void get_kb_shift
-       (void);
-time_t get_localtime
-       (struct tm *, int);
-time_t get_time
-       (struct tm *, int);
 char *get_persistent_name_from_pretty
        (char *);
 char *get_persistent_type_dir
@@ -273,10 +282,6 @@ int get_win_height
        (void);
 void init_colors
        (void);
-void init_nls
-       (void);
-int is_device
-       (char *, int);
 double ll_sp_value
        (unsigned long long, unsigned long long, unsigned long long);
 int is_iso_time_fmt
@@ -285,17 +290,14 @@ int parse_values
        (char *, unsigned char[], int, const char *);
 int print_gal_header
        (struct tm *, char *, char *, char *, char *, int, int);
-void print_version
-       (void);
 int set_report_date
        (struct tm *, char[], int);
 char *strtolower
        (char *);
-void sysstat_panic
-       (const char *, int);
 void xprintf
        (int, const char *, ...);
 void xprintf0
        (int, const char *, ...);
 
+#endif /* SOURCE_SADC undefined */
 #endif  /* _COMMON_H */
diff --git a/sa.h b/sa.h
index 684c7703057679fb40ec254e7b6abdd325ade295..ea433251d045159e8c91a1ac2cc2dd7ab5688f98 100644 (file)
--- a/sa.h
+++ b/sa.h
@@ -1208,12 +1208,26 @@ __read_funct_t wrap_read_softnet
        (struct activity *);
 
 /* Other functions */
+int check_alt_sa_dir
+       (char *, int, int);
+void enum_version_nr
+       (struct file_magic *);
+int get_activity_nr
+       (struct activity * [], unsigned int, int);
+int get_activity_position
+       (struct activity * [], unsigned int, int);
+void set_default_file
+       (char *, int, int);
+void handle_invalid_sa_file
+       (int, struct file_magic *, char *, int);
+void print_collect_error
+       (void);
+
+#ifndef SOURCE_SADC
 void allocate_bitmaps
        (struct activity * []);
 void allocate_structures
        (struct activity * []);
-int check_alt_sa_dir
-       (char *, int, int);
 int check_disk_reg
        (struct activity *, int, int, int);
 void check_file_actlst
@@ -1231,24 +1245,16 @@ int datecmp
        (struct tm *, struct tstamp *);
 void display_sa_file_version
        (FILE *, struct file_magic *);
-void enum_version_nr
-       (struct file_magic *);
 void free_bitmaps
        (struct activity * []);
 void free_structures
        (struct activity * []);
-int get_activity_nr
-       (struct activity * [], unsigned int, int);
-int get_activity_position
-       (struct activity * [], unsigned int, int);
 char *get_devname
        (unsigned int, unsigned int, int);
 void get_file_timestamp_struct
        (unsigned int, struct tm *, struct file_header *);
 void get_itv_value
        (struct record_header *, struct record_header *, unsigned long long *);
-void handle_invalid_sa_file
-       (int, struct file_magic *, char *, int);
 int next_slice
        (unsigned long long, unsigned long long, int, long);
 int parse_sar_opt
@@ -1263,8 +1269,6 @@ int parse_sar_n_opt
        (char * [], int *, struct activity * []);
 int parse_timestamp
        (char * [], int *, struct tstamp *, const char *);
-void print_collect_error
-       (void);
 void print_report_hdr
        (unsigned int, struct tm *, struct file_header *);
 void print_sar_comment
@@ -1300,13 +1304,11 @@ void select_default_activity
        (struct activity * []);
 void set_bitmap
        (unsigned char [], unsigned char, unsigned int);
-void set_default_file
-       (char *, int, int);
 void set_hdr_rectime
        (unsigned int, struct tm *, struct file_header *);
 void set_record_timestamp_string
        (unsigned int, struct record_header *, char *, char *, int, struct tm *);
 void swap_struct
        (unsigned int [], void *, int);
-
+#endif /* SOURCE_SADC undefined */
 #endif  /* _SA_H */
index 9820deb466dde090d69c7509e5e87e5ec9bce120..b75fc7e9a21a90a1e6f170ff941289f2fa9d9fa5 100644 (file)
@@ -53,6 +53,338 @@ unsigned int act_types_nr[] = {FILE_ACTIVITY_ULL_NR, FILE_ACTIVITY_UL_NR, FILE_A
 unsigned int rec_types_nr[] = {RECORD_HEADER_ULL_NR, RECORD_HEADER_UL_NR, RECORD_HEADER_U_NR};
 unsigned int nr_types_nr[]  = {0, 0, 1};
 
+/*
+ ***************************************************************************
+ * Look for activity in array.
+ *
+ * IN:
+ * @act                Array of activities.
+ * @act_flag   Activity flag to look for.
+ * @stop       TRUE if sysstat should exit when activity is not found.
+ *
+ * RETURNS:
+ * Position of activity in array, or -1 if not found (this may happen when
+ * reading data from a system activity file created by another version of
+ * sysstat).
+ ***************************************************************************
+ */
+int get_activity_position(struct activity *act[], unsigned int act_flag, int stop)
+{
+       int i;
+
+       for (i = 0; i < NR_ACT; i++) {
+               if (act[i]->id == act_flag)
+                       return i;
+       }
+
+       if (stop) {
+               PANIC((int) act_flag);
+       }
+
+       return -1;
+}
+
+/*
+ ***************************************************************************
+ * Count number of activities with given option.
+ *
+ * IN:
+ * @act                        Array of activities.
+ * @option             Option that activities should have to be counted
+ *                     (eg. AO_COLLECTED...)
+ * @count_outputs      TRUE if each output should be counted for activities with
+ *                     multiple outputs.
+ *
+ * RETURNS:
+ * Number of selected activities
+ ***************************************************************************
+ */
+int get_activity_nr(struct activity *act[], unsigned int option, int count_outputs)
+{
+       int i, n = 0;
+       unsigned int msk;
+
+       for (i = 0; i < NR_ACT; i++) {
+               if ((act[i]->options & option) == option) {
+
+                       if (HAS_MULTIPLE_OUTPUTS(act[i]->options) && count_outputs) {
+                               for (msk = 1; msk < 0x100; msk <<= 1) {
+                                       if ((act[i]->opt_flags & 0xff) & msk) {
+                                               n++;
+                                       }
+                               }
+                       }
+                       else {
+                               n++;
+                       }
+               }
+       }
+
+       return n;
+}
+
+/*
+ ***************************************************************************
+ * Look for the most recent of saDD and saYYYYMMDD to decide which one to
+ * use. If neither exists then use saDD by default.
+ *
+ * IN:
+ * @sa_dir     Directory where standard daily data files are saved.
+ * @rectime    Structure containing the current date.
+ *
+ * OUT:
+ * @sa_name    0 to use saDD data files,
+ *             1 to use saYYYYMMDD data files.
+ ***************************************************************************
+ */
+void guess_sa_name(char *sa_dir, struct tm *rectime, int *sa_name)
+{
+       char filename[MAX_FILE_LEN];
+       struct stat sb;
+       time_t sa_mtime;
+
+       /* Use saDD by default */
+       *sa_name = 0;
+
+       /* Look for saYYYYMMDD */
+       snprintf(filename, MAX_FILE_LEN,
+                "%s/sa%04d%02d%02d", sa_dir,
+                rectime->tm_year + 1900,
+                rectime->tm_mon + 1,
+                rectime->tm_mday);
+       filename[MAX_FILE_LEN - 1] = '\0';
+
+       if (stat(filename, &sb) < 0)
+               /* Cannot find or access saYYYYMMDD, so use saDD */
+               return;
+       sa_mtime = sb.st_mtime;
+
+       /* Look for saDD */
+       snprintf(filename, MAX_FILE_LEN,
+                "%s/sa%02d", sa_dir,
+                rectime->tm_mday);
+       filename[MAX_FILE_LEN - 1] = '\0';
+
+       if (stat(filename, &sb) < 0) {
+               /* Cannot find or access saDD, so use saYYYYMMDD */
+               *sa_name = 1;
+               return;
+       }
+
+       if (sa_mtime > sb.st_mtime) {
+               /* saYYYYMMDD is more recent than saDD, so use it */
+               *sa_name = 1;
+       }
+}
+
+/*
+ ***************************************************************************
+ * Set current daily data file name.
+ *
+ * IN:
+ * @datafile   If not an empty string then this is the alternate directory
+ *             location where daily data files will be saved.
+ * @d_off      Day offset (number of days to go back in the past).
+ * @sa_name    0 for saDD data files,
+ *             1 for saYYYYMMDD data files,
+ *             -1 if unknown. In this case, will look for the most recent
+ *             of saDD and saYYYYMMDD and use it.
+ *
+ * OUT:
+ * @datafile   Name of daily data file.
+ ***************************************************************************
+ */
+void set_default_file(char *datafile, int d_off, int sa_name)
+{
+       char sa_dir[MAX_FILE_LEN];
+       struct tm rectime = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL};
+
+       /* Set directory where daily data files will be saved */
+       if (datafile[0]) {
+               strncpy(sa_dir, datafile, MAX_FILE_LEN);
+       }
+       else {
+               strncpy(sa_dir, SA_DIR, MAX_FILE_LEN);
+       }
+       sa_dir[MAX_FILE_LEN - 1] = '\0';
+
+       get_time(&rectime, d_off);
+       if (sa_name < 0) {
+               /*
+                * Look for the most recent of saDD and saYYYYMMDD
+                * and use it. If neither exists then use saDD.
+                * sa_name is set accordingly.
+                */
+               guess_sa_name(sa_dir, &rectime, &sa_name);
+       }
+       if (sa_name) {
+               /* Using saYYYYMMDD data files */
+               snprintf(datafile, MAX_FILE_LEN,
+                        "%s/sa%04d%02d%02d", sa_dir,
+                        rectime.tm_year + 1900,
+                        rectime.tm_mon + 1,
+                        rectime.tm_mday);
+       }
+       else {
+               /* Using saDD data files */
+               snprintf(datafile, MAX_FILE_LEN,
+                        "%s/sa%02d", sa_dir,
+                        rectime.tm_mday);
+       }
+       datafile[MAX_FILE_LEN - 1] = '\0';
+       default_file_used = TRUE;
+}
+
+/*
+ ***************************************************************************
+ * Check data file type. If it is a directory then this is the alternate
+ * location where daily data files will be saved.
+ *
+ * IN:
+ * @datafile   Name of the daily data file. May be a directory.
+ * @d_off      Day offset (number of days to go back in the past).
+ * @sa_name    0 for saDD data files,
+ *             1 for saYYYYMMDD data files,
+ *             -1 if unknown. In this case, will look for the most recent
+ *             of saDD and saYYYYMMDD and use it.
+ *
+ *
+ * OUT:
+ * @datafile   Name of the daily data file. This is now a plain file, not
+ *             a directory.
+ *
+ * RETURNS:
+ * 1 if @datafile was a directory, and 0 otherwise.
+ ***************************************************************************
+ */
+int check_alt_sa_dir(char *datafile, int d_off, int sa_name)
+{
+       struct stat sb;
+
+       if (stat(datafile, &sb) == 0) {
+               if (S_ISDIR(sb.st_mode)) {
+                       /*
+                        * This is a directory: So append
+                        * the default file name to it.
+                        */
+                       set_default_file(datafile, d_off, sa_name);
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
+/*
+ ***************************************************************************
+ * Display sysstat version used to create system activity data file.
+ *
+ * IN:
+ * @st         Output stream (stderr or stdout).
+ * @file_magic File magic header.
+ ***************************************************************************
+ */
+void display_sa_file_version(FILE *st, struct file_magic *file_magic)
+{
+       fprintf(st, _("File created by sar/sadc from sysstat version %d.%d.%d"),
+               file_magic->sysstat_version,
+               file_magic->sysstat_patchlevel,
+               file_magic->sysstat_sublevel);
+
+       if (file_magic->sysstat_extraversion) {
+               fprintf(st, ".%d", file_magic->sysstat_extraversion);
+       }
+       fprintf(st, "\n");
+}
+
+/*
+ ***************************************************************************
+ * An invalid system activity file has been opened for reading.
+ * If this file was created by an old version of sysstat, tell it to the
+ * user...
+ *
+ * IN:
+ * @fd         Descriptor of the file that has been opened.
+ * @file_magic file_magic structure filled with file magic header data.
+ *             May contain invalid data.
+ * @file       Name of the file being read.
+ * @n          Number of bytes read while reading file magic header.
+ *             This function may also be called after failing to read file
+ *             standard header, or if CPU activity has not been found in
+ *             file. In this case, n is set to 0.
+ ***************************************************************************
+ */
+void handle_invalid_sa_file(int fd, struct file_magic *file_magic, char *file,
+                           int n)
+{
+       fprintf(stderr, _("Invalid system activity file: %s\n"), file);
+
+       if (n == FILE_MAGIC_SIZE) {
+               if ((file_magic->sysstat_magic == SYSSTAT_MAGIC) || (file_magic->sysstat_magic == SYSSTAT_MAGIC_SWAPPED)) {
+                       /* This is a sysstat file, but this file has an old format */
+                       display_sa_file_version(stderr, file_magic);
+
+                       fprintf(stderr,
+                               _("Current sysstat version cannot read the format of this file (%#x)\n"),
+                               file_magic->sysstat_magic == SYSSTAT_MAGIC ?
+                               file_magic->format_magic : __builtin_bswap16(file_magic->format_magic));
+               }
+       }
+
+       close (fd);
+       exit(3);
+}
+
+/*
+ ***************************************************************************
+ * Display an error message then exit.
+ ***************************************************************************
+ */
+void print_collect_error(void)
+{
+       fprintf(stderr, _("Requested activities not available\n"));
+       exit(1);
+}
+
+/*
+ ***************************************************************************
+ * Fill system activity file magic header.
+ *
+ * IN:
+ * @file_magic System activity file magic header.
+ ***************************************************************************
+ */
+void enum_version_nr(struct file_magic *fm)
+{
+       char *v;
+       char version[16];
+
+       fm->sysstat_extraversion = 0;
+
+       strcpy(version, VERSION);
+
+       /* Get version number */
+       if ((v = strtok(version, ".")) == NULL)
+               return;
+       fm->sysstat_version = atoi(v) & 0xff;
+
+       /* Get patchlevel number */
+       if ((v = strtok(NULL, ".")) == NULL)
+               return;
+       fm->sysstat_patchlevel = atoi(v) & 0xff;
+
+       /* Get sublevel number */
+       if ((v = strtok(NULL, ".")) == NULL)
+               return;
+       fm->sysstat_sublevel = atoi(v) & 0xff;
+
+       /* Get extraversion number. Don't necessarily exist */
+       if ((v = strtok(NULL, ".")) == NULL)
+               return;
+       fm->sysstat_extraversion = atoi(v) & 0xff;
+}
+
+#ifndef SOURCE_SADC
 /*
  ***************************************************************************
  * Allocate structures.
@@ -369,158 +701,6 @@ int parse_timestamp(char *argv[], int *opt, struct tstamp *tse,
        return decode_timestamp(timestamp, tse);
 }
 
-/*
- ***************************************************************************
- * Look for the most recent of saDD and saYYYYMMDD to decide which one to
- * use. If neither exists then use saDD by default.
- *
- * IN:
- * @sa_dir     Directory where standard daily data files are saved.
- * @rectime    Structure containing the current date.
- *
- * OUT:
- * @sa_name    0 to use saDD data files,
- *             1 to use saYYYYMMDD data files.
- ***************************************************************************
- */
-void guess_sa_name(char *sa_dir, struct tm *rectime, int *sa_name)
-{
-       char filename[MAX_FILE_LEN];
-       struct stat sb;
-       time_t sa_mtime;
-
-       /* Use saDD by default */
-       *sa_name = 0;
-
-       /* Look for saYYYYMMDD */
-       snprintf(filename, MAX_FILE_LEN,
-                "%s/sa%04d%02d%02d", sa_dir,
-                rectime->tm_year + 1900,
-                rectime->tm_mon + 1,
-                rectime->tm_mday);
-       filename[MAX_FILE_LEN - 1] = '\0';
-
-       if (stat(filename, &sb) < 0)
-               /* Cannot find or access saYYYYMMDD, so use saDD */
-               return;
-       sa_mtime = sb.st_mtime;
-
-       /* Look for saDD */
-       snprintf(filename, MAX_FILE_LEN,
-                "%s/sa%02d", sa_dir,
-                rectime->tm_mday);
-       filename[MAX_FILE_LEN - 1] = '\0';
-
-       if (stat(filename, &sb) < 0) {
-               /* Cannot find or access saDD, so use saYYYYMMDD */
-               *sa_name = 1;
-               return;
-       }
-
-       if (sa_mtime > sb.st_mtime) {
-               /* saYYYYMMDD is more recent than saDD, so use it */
-               *sa_name = 1;
-       }
-}
-
-/*
- ***************************************************************************
- * Set current daily data file name.
- *
- * IN:
- * @datafile   If not an empty string then this is the alternate directory
- *             location where daily data files will be saved.
- * @d_off      Day offset (number of days to go back in the past).
- * @sa_name    0 for saDD data files,
- *             1 for saYYYYMMDD data files,
- *             -1 if unknown. In this case, will look for the most recent
- *             of saDD and saYYYYMMDD and use it.
- *
- * OUT:
- * @datafile   Name of daily data file.
- ***************************************************************************
- */
-void set_default_file(char *datafile, int d_off, int sa_name)
-{
-       char sa_dir[MAX_FILE_LEN];
-       struct tm rectime = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL};
-
-       /* Set directory where daily data files will be saved */
-       if (datafile[0]) {
-               strncpy(sa_dir, datafile, MAX_FILE_LEN);
-       }
-       else {
-               strncpy(sa_dir, SA_DIR, MAX_FILE_LEN);
-       }
-       sa_dir[MAX_FILE_LEN - 1] = '\0';
-
-       get_time(&rectime, d_off);
-       if (sa_name < 0) {
-               /*
-                * Look for the most recent of saDD and saYYYYMMDD
-                * and use it. If neither exists then use saDD.
-                * sa_name is set accordingly.
-                */
-               guess_sa_name(sa_dir, &rectime, &sa_name);
-       }
-       if (sa_name) {
-               /* Using saYYYYMMDD data files */
-               snprintf(datafile, MAX_FILE_LEN,
-                        "%s/sa%04d%02d%02d", sa_dir,
-                        rectime.tm_year + 1900,
-                        rectime.tm_mon + 1,
-                        rectime.tm_mday);
-       }
-       else {
-               /* Using saDD data files */
-               snprintf(datafile, MAX_FILE_LEN,
-                        "%s/sa%02d", sa_dir,
-                        rectime.tm_mday);
-       }
-       datafile[MAX_FILE_LEN - 1] = '\0';
-       default_file_used = TRUE;
-}
-
-/*
- ***************************************************************************
- * Check data file type. If it is a directory then this is the alternate
- * location where daily data files will be saved.
- *
- * IN:
- * @datafile   Name of the daily data file. May be a directory.
- * @d_off      Day offset (number of days to go back in the past).
- * @sa_name    0 for saDD data files,
- *             1 for saYYYYMMDD data files,
- *             -1 if unknown. In this case, will look for the most recent
- *             of saDD and saYYYYMMDD and use it.
- *
- *
- * OUT:
- * @datafile   Name of the daily data file. This is now a plain file, not
- *             a directory.
- *
- * RETURNS:
- * 1 if @datafile was a directory, and 0 otherwise.
- ***************************************************************************
- */
-int check_alt_sa_dir(char *datafile, int d_off, int sa_name)
-{
-       struct stat sb;
-
-       if (stat(datafile, &sb) == 0) {
-               if (S_ISDIR(sb.st_mode)) {
-                       /*
-                        * This is a directory: So append
-                        * the default file name to it.
-                        */
-                       set_default_file(datafile, d_off, sa_name);
-                       return 1;
-               }
-       }
-
-       return 0;
-}
-
 /*
  ***************************************************************************
  * Set interval value.
@@ -872,118 +1052,48 @@ int check_disk_reg(struct activity *a, int curr, int ref, int pos)
 
 /*
  ***************************************************************************
- * Allocate bitmaps for activities that have one.
- *
- * IN:
- * @act                Array of activities.
- ***************************************************************************
- */
-void allocate_bitmaps(struct activity *act[])
-{
-       int i;
-
-       for (i = 0; i < NR_ACT; i++) {
-               /*
-                * If current activity has a bitmap which has not already
-                * been allocated, then allocate it.
-                * Note that a same bitmap may be used by several activities.
-                */
-               if (act[i]->bitmap && !act[i]->bitmap->b_array) {
-                       SREALLOC(act[i]->bitmap->b_array, unsigned char,
-                                BITMAP_SIZE(act[i]->bitmap->b_size));
-               }
-       }
-}
-
-/*
- ***************************************************************************
- * Free bitmaps for activities that have one.
- *
- * IN:
- * @act                Array of activities.
- ***************************************************************************
- */
-void free_bitmaps(struct activity *act[])
-{
-       int i;
-
-       for (i = 0; i < NR_ACT; i++) {
-               if (act[i]->bitmap && act[i]->bitmap->b_array) {
-                       free(act[i]->bitmap->b_array);
-                       /* Set pointer to NULL to prevent it from being freed again */
-                       act[i]->bitmap->b_array = NULL;
-               }
-       }
-}
-
-/*
- ***************************************************************************
- * Look for activity in array.
- *
- * IN:
- * @act                Array of activities.
- * @act_flag   Activity flag to look for.
- * @stop       TRUE if sysstat should exit when activity is not found.
- *
- * RETURNS:
- * Position of activity in array, or -1 if not found (this may happen when
- * reading data from a system activity file created by another version of
- * sysstat).
+ * Allocate bitmaps for activities that have one.
+ *
+ * IN:
+ * @act                Array of activities.
  ***************************************************************************
  */
-int get_activity_position(struct activity *act[], unsigned int act_flag, int stop)
+void allocate_bitmaps(struct activity *act[])
 {
        int i;
 
        for (i = 0; i < NR_ACT; i++) {
-               if (act[i]->id == act_flag)
-                       return i;
-       }
-
-       if (stop) {
-               PANIC((int) act_flag);
+               /*
+                * If current activity has a bitmap which has not already
+                * been allocated, then allocate it.
+                * Note that a same bitmap may be used by several activities.
+                */
+               if (act[i]->bitmap && !act[i]->bitmap->b_array) {
+                       SREALLOC(act[i]->bitmap->b_array, unsigned char,
+                                BITMAP_SIZE(act[i]->bitmap->b_size));
+               }
        }
-
-       return -1;
 }
 
 /*
  ***************************************************************************
- * Count number of activities with given option.
+ * Free bitmaps for activities that have one.
  *
  * IN:
- * @act                        Array of activities.
- * @option             Option that activities should have to be counted
- *                     (eg. AO_COLLECTED...)
- * @count_outputs      TRUE if each output should be counted for activities with
- *                     multiple outputs.
- *
- * RETURNS:
- * Number of selected activities
+ * @act                Array of activities.
  ***************************************************************************
  */
-int get_activity_nr(struct activity *act[], unsigned int option, int count_outputs)
+void free_bitmaps(struct activity *act[])
 {
-       int i, n = 0;
-       unsigned int msk;
+       int i;
 
        for (i = 0; i < NR_ACT; i++) {
-               if ((act[i]->options & option) == option) {
-
-                       if (HAS_MULTIPLE_OUTPUTS(act[i]->options) && count_outputs) {
-                               for (msk = 1; msk < 0x100; msk <<= 1) {
-                                       if ((act[i]->opt_flags & 0xff) & msk) {
-                                               n++;
-                                       }
-                               }
-                       }
-                       else {
-                               n++;
-                       }
+               if (act[i]->bitmap && act[i]->bitmap->b_array) {
+                       free(act[i]->bitmap->b_array);
+                       /* Set pointer to NULL to prevent it from being freed again */
+                       act[i]->bitmap->b_array = NULL;
                }
        }
-
-       return n;
 }
 
 /*
@@ -1245,77 +1355,6 @@ int read_record_hdr(int ifd, void *buffer, struct record_header *record_hdr,
        return 0;
 }
 
-/*
- ***************************************************************************
- * Display sysstat version used to create system activity data file.
- *
- * IN:
- * @st         Output stream (stderr or stdout).
- * @file_magic File magic header.
- ***************************************************************************
- */
-void display_sa_file_version(FILE *st, struct file_magic *file_magic)
-{
-       fprintf(st, _("File created by sar/sadc from sysstat version %d.%d.%d"),
-               file_magic->sysstat_version,
-               file_magic->sysstat_patchlevel,
-               file_magic->sysstat_sublevel);
-
-       if (file_magic->sysstat_extraversion) {
-               fprintf(st, ".%d", file_magic->sysstat_extraversion);
-       }
-       fprintf(st, "\n");
-}
-
-/*
- ***************************************************************************
- * An invalid system activity file has been opened for reading.
- * If this file was created by an old version of sysstat, tell it to the
- * user...
- *
- * IN:
- * @fd         Descriptor of the file that has been opened.
- * @file_magic file_magic structure filled with file magic header data.
- *             May contain invalid data.
- * @file       Name of the file being read.
- * @n          Number of bytes read while reading file magic header.
- *             This function may also be called after failing to read file
- *             standard header, or if CPU activity has not been found in
- *             file. In this case, n is set to 0.
- ***************************************************************************
- */
-void handle_invalid_sa_file(int fd, struct file_magic *file_magic, char *file,
-                           int n)
-{
-       fprintf(stderr, _("Invalid system activity file: %s\n"), file);
-
-       if (n == FILE_MAGIC_SIZE) {
-               if ((file_magic->sysstat_magic == SYSSTAT_MAGIC) || (file_magic->sysstat_magic == SYSSTAT_MAGIC_SWAPPED)) {
-                       /* This is a sysstat file, but this file has an old format */
-                       display_sa_file_version(stderr, file_magic);
-
-                       fprintf(stderr,
-                               _("Current sysstat version cannot read the format of this file (%#x)\n"),
-                               file_magic->sysstat_magic == SYSSTAT_MAGIC ?
-                               file_magic->format_magic : __builtin_bswap16(file_magic->format_magic));
-               }
-       }
-
-       close (fd);
-       exit(3);
-}
-
-/*
- ***************************************************************************
- * Display an error message then exit.
- ***************************************************************************
- */
-void print_collect_error(void)
-{
-       fprintf(stderr, _("Requested activities not available\n"));
-       exit(1);
-}
-
 /*
  ***************************************************************************
  * Move structures data.
@@ -1348,6 +1387,51 @@ void copy_structures(struct activity *act[], unsigned int id_seq[],
        }
 }
 
+/*
+ ***************************************************************************
+ * Read an __nr_t value from file.
+ * Such a value can be the new number of CPU saved after a RESTART record,
+ * or the number of structures to read saved before the structures containing
+ * statistics for an activity with a varying number of items in file.
+ *
+ * IN:
+ * @ifd                Input file descriptor.
+ * @file       Name of file being read.
+ * @file_magic file_magic structure filled with file magic header data.
+ * @endian_mismatch
+ *             TRUE if file's data don't match current machine's endianness.
+ * @arch_64    TRUE if file's data come from a 64 bit machine.
+ * @non_zero   TRUE if value should not be zero.
+ *
+ * RETURNS:
+ * __nr_t value, as read from file.
+ ***************************************************************************
+ */
+__nr_t read_nr_value(int ifd, char *file, struct file_magic *file_magic,
+                    int endian_mismatch, int arch_64, int non_zero)
+{
+       __nr_t value;
+
+       sa_fread(ifd, &value, sizeof(__nr_t), HARD_SIZE);
+
+       /* Normalize endianness for file_activity structures */
+       if (endian_mismatch) {
+               nr_types_nr[2] = 1;
+               swap_struct(nr_types_nr, &value, arch_64);
+       }
+
+       if ((non_zero && !value) || (value < 0)) {
+#ifdef DEBUG
+               fprintf(stderr, "%s: Value=%d\n",
+                       __FUNCTION__, value);
+#endif
+               /* Value number cannot be zero or negative */
+               handle_invalid_sa_file(ifd, file_magic, file, 0);
+       }
+
+       return value;
+}
+
 /*
  ***************************************************************************
  * Read varying part of the statistics from a daily data file.
@@ -1845,51 +1929,6 @@ format_error:
        handle_invalid_sa_file(*ifd, file_magic, dfile, 0);
 }
 
-/*
- ***************************************************************************
- * Read an __nr_t value from file.
- * Such a value can be the new number of CPU saved after a RESTART record,
- * or the number of structures to read saved before the structures containing
- * statistics for an activity with a varying number of items in file.
- *
- * IN:
- * @ifd                Input file descriptor.
- * @file       Name of file being read.
- * @file_magic file_magic structure filled with file magic header data.
- * @endian_mismatch
- *             TRUE if file's data don't match current machine's endianness.
- * @arch_64    TRUE if file's data come from a 64 bit machine.
- * @non_zero   TRUE if value should not be zero.
- *
- * RETURNS:
- * __nr_t value, as read from file.
- ***************************************************************************
- */
-__nr_t read_nr_value(int ifd, char *file, struct file_magic *file_magic,
-                    int endian_mismatch, int arch_64, int non_zero)
-{
-       __nr_t value;
-
-       sa_fread(ifd, &value, sizeof(__nr_t), HARD_SIZE);
-
-       /* Normalize endianness for file_activity structures */
-       if (endian_mismatch) {
-               nr_types_nr[2] = 1;
-               swap_struct(nr_types_nr, &value, arch_64);
-       }
-
-       if ((non_zero && !value) || (value < 0)) {
-#ifdef DEBUG
-               fprintf(stderr, "%s: Value=%d\n",
-                       __FUNCTION__, value);
-#endif
-               /* Value number cannot be zero or negative */
-               handle_invalid_sa_file(ifd, file_magic, file, 0);
-       }
-
-       return value;
-}
-
 /*
  ***************************************************************************
  * Parse sar activities options (also used by sadf).
@@ -2350,44 +2389,6 @@ double compute_ifutil(struct stats_net_dev *st_net_dev, double rx, double tx)
        return 0;
 }
 
-/*
- ***************************************************************************
- * Fill system activity file magic header.
- *
- * IN:
- * @file_magic System activity file magic header.
- ***************************************************************************
- */
-void enum_version_nr(struct file_magic *fm)
-{
-       char *v;
-       char version[16];
-
-       fm->sysstat_extraversion = 0;
-
-       strcpy(version, VERSION);
-
-       /* Get version number */
-       if ((v = strtok(version, ".")) == NULL)
-               return;
-       fm->sysstat_version = atoi(v) & 0xff;
-
-       /* Get patchlevel number */
-       if ((v = strtok(NULL, ".")) == NULL)
-               return;
-       fm->sysstat_patchlevel = atoi(v) & 0xff;
-
-       /* Get sublevel number */
-       if ((v = strtok(NULL, ".")) == NULL)
-               return;
-       fm->sysstat_sublevel = atoi(v) & 0xff;
-
-       /* Get extraversion number. Don't necessarily exist */
-       if ((v = strtok(NULL, ".")) == NULL)
-               return;
-       fm->sysstat_extraversion = atoi(v) & 0xff;
-}
-
 /*
  ***************************************************************************
  * Read and replace unprintable characters in comment with ".".
@@ -2656,3 +2657,4 @@ int print_special_record(struct record_header *record_hdr, unsigned int l_flags,
 
        return 1;
 }
+#endif /* SOURCE_SADC undefined */