]> granicus.if.org Git - sysstat/blob - sa.h
sar: Better assess size of buffers that need to be reallocated
[sysstat] / sa.h
1 /*
2  * sar/sadc: Report system activity
3  * (C) 1999-2018 by Sebastien Godard (sysstat <at> orange.fr)
4  */
5
6 #ifndef _SA_H
7 #define _SA_H
8
9 #include <stdio.h>
10
11 #include "common.h"
12 #include "rd_stats.h"
13 #include "rd_sensors.h"
14
15 /*
16  ***************************************************************************
17  * Activity identification values.
18  ***************************************************************************
19  */
20
21 /* Number of activities */
22 #define NR_ACT          39
23 /* The value below is used for sanity check */
24 #define MAX_NR_ACT      256
25
26 /* Number of functions used to count items */
27 #define NR_F_COUNT      11
28
29 /* Activities */
30 #define A_CPU           1
31 #define A_PCSW          2
32 #define A_IRQ           3
33 #define A_SWAP          4
34 #define A_PAGE          5
35 #define A_IO            6
36 #define A_MEMORY        7
37 #define A_KTABLES       8
38 #define A_QUEUE         9
39 #define A_SERIAL        10
40 #define A_DISK          11
41 #define A_NET_DEV       12
42 #define A_NET_EDEV      13
43 #define A_NET_NFS       14
44 #define A_NET_NFSD      15
45 #define A_NET_SOCK      16
46 #define A_NET_IP        17
47 #define A_NET_EIP       18
48 #define A_NET_ICMP      19
49 #define A_NET_EICMP     20
50 #define A_NET_TCP       21
51 #define A_NET_ETCP      22
52 #define A_NET_UDP       23
53 #define A_NET_SOCK6     24
54 #define A_NET_IP6       25
55 #define A_NET_EIP6      26
56 #define A_NET_ICMP6     27
57 #define A_NET_EICMP6    28
58 #define A_NET_UDP6      29
59 #define A_PWR_CPU       30
60 #define A_PWR_FAN       31
61 #define A_PWR_TEMP      32
62 #define A_PWR_IN        33
63 #define A_HUGE          34
64 #define A_PWR_FREQ      35
65 #define A_PWR_USB       36
66 #define A_FS            37
67 #define A_NET_FC        38
68 #define A_NET_SOFT      39
69
70
71 /* Macro used to flag an activity that should be collected */
72 #define COLLECT_ACTIVITY(m)     act[get_activity_position(act, m, EXIT_IF_NOT_FOUND)]->options |= AO_COLLECTED
73
74 /* Macro used to flag an activity that should be selected */
75 #define SELECT_ACTIVITY(m)      act[get_activity_position(act, m, EXIT_IF_NOT_FOUND)]->options |= AO_SELECTED
76
77
78 /*
79  ***************************************************************************
80  * Flags.
81  ***************************************************************************
82  */
83
84 #define S_F_SINCE_BOOT          0x00000001
85 #define S_F_SA_ROTAT            0x00000002
86 #define S_F_DEV_PRETTY          0x00000004
87 #define S_F_FORCE_FILE          0x00000008
88 #define S_F_INTERVAL_SET        0x00000010
89 #define S_F_TRUE_TIME           0x00000020
90 #define S_F_LOCK_FILE           0x00000040
91 #define S_F_SEC_EPOCH           0x00000080
92 #define S_F_HDR_ONLY            0x00000100
93 #define S_F_FILE_LOCKED         0x00000200
94 #define S_F_SA_YYYYMMDD         0x00000400
95 #define S_F_HORIZONTALLY        0x00000800
96 #define S_F_COMMENT             0x00001000
97 #define S_F_PERSIST_NAME        0x00002000
98 #define S_F_LOCAL_TIME          0x00004000
99 #define S_F_PREFD_TIME_OUTPUT   0x00008000
100 #define S_F_SVG_SKIP            0x00010000
101 /* Same value as S_F_SVG_SKIP above. Used for a different output format */
102 #define S_F_RAW_DEBUG_MODE      0x00010000
103 #define S_F_SVG_AUTOSCALE       0x00020000
104 #define S_F_SVG_ONE_DAY         0x00040000
105 #define S_F_SVG_SHOW_IDLE       0x00080000
106 #define S_F_UNIT                0x00100000
107 #define S_F_SVG_HEIGHT          0x00200000
108 #define S_F_SVG_PACKED          0x00400000
109 #define S_F_SVG_SHOW_INFO       0x00800000
110 #define S_F_HUMAN_READ          0x01000000
111 #define S_F_ZERO_OMIT           0x02000000
112
113 #define WANT_SINCE_BOOT(m)              (((m) & S_F_SINCE_BOOT)   == S_F_SINCE_BOOT)
114 #define WANT_SA_ROTAT(m)                (((m) & S_F_SA_ROTAT)     == S_F_SA_ROTAT)
115 #define USE_PRETTY_OPTION(m)            (((m) & S_F_DEV_PRETTY)   == S_F_DEV_PRETTY)
116 #define FORCE_FILE(m)                   (((m) & S_F_FORCE_FILE)   == S_F_FORCE_FILE)
117 #define INTERVAL_SET(m)                 (((m) & S_F_INTERVAL_SET) == S_F_INTERVAL_SET)
118 #define PRINT_TRUE_TIME(m)              (((m) & S_F_TRUE_TIME)    == S_F_TRUE_TIME)
119 #define LOCK_FILE(m)                    (((m) & S_F_LOCK_FILE)    == S_F_LOCK_FILE)
120 #define PRINT_SEC_EPOCH(m)              (((m) & S_F_SEC_EPOCH)    == S_F_SEC_EPOCH)
121 #define DISPLAY_HDR_ONLY(m)             (((m) & S_F_HDR_ONLY)     == S_F_HDR_ONLY)
122 #define FILE_LOCKED(m)                  (((m) & S_F_FILE_LOCKED)  == S_F_FILE_LOCKED)
123 #define USE_SA_YYYYMMDD(m)              (((m) & S_F_SA_YYYYMMDD)  == S_F_SA_YYYYMMDD)
124 #define DISPLAY_HORIZONTALLY(m)         (((m) & S_F_HORIZONTALLY) == S_F_HORIZONTALLY)
125 #define DISPLAY_COMMENT(m)              (((m) & S_F_COMMENT)      == S_F_COMMENT)
126 #define DISPLAY_PERSIST_NAME_S(m)       (((m) & S_F_PERSIST_NAME) == S_F_PERSIST_NAME)
127 #define PRINT_LOCAL_TIME(m)             (((m) & S_F_LOCAL_TIME)   == S_F_LOCAL_TIME)
128 #define USE_PREFD_TIME_OUTPUT(m)        (((m) & S_F_PREFD_TIME_OUTPUT)   == S_F_PREFD_TIME_OUTPUT)
129 #define SKIP_EMPTY_VIEWS(m)             (((m) & S_F_SVG_SKIP)     == S_F_SVG_SKIP)
130 #define DISPLAY_ZERO_OMIT(m)            (((m) & S_F_ZERO_OMIT)    == S_F_ZERO_OMIT)
131 #define DISPLAY_DEBUG_MODE(m)           (((m) & S_F_RAW_DEBUG_MODE) == S_F_RAW_DEBUG_MODE)
132 #define AUTOSCALE_ON(m)                 (((m) & S_F_SVG_AUTOSCALE) == S_F_SVG_AUTOSCALE)
133 #define DISPLAY_ONE_DAY(m)              (((m) & S_F_SVG_ONE_DAY)   == S_F_SVG_ONE_DAY)
134 #define DISPLAY_IDLE(m)                 (((m) & S_F_SVG_SHOW_IDLE) == S_F_SVG_SHOW_IDLE)
135 #define DISPLAY_INFO(m)                 (((m) & S_F_SVG_SHOW_INFO) == S_F_SVG_SHOW_INFO)
136 #define DISPLAY_UNIT(m)                 (((m) & S_F_UNIT) == S_F_UNIT)
137 #define SET_CANVAS_HEIGHT(m)            (((m) & S_F_SVG_HEIGHT) == S_F_SVG_HEIGHT)
138 #define PACK_VIEWS(m)                   (((m) & S_F_SVG_PACKED) == S_F_SVG_PACKED)
139 #define DISPLAY_HUMAN_READ(m)           (((m) & S_F_HUMAN_READ) == S_F_HUMAN_READ)
140
141 #define AO_F_NULL               0x00000000
142
143 /* Output flags for options -r / -S */
144 #define AO_F_MEMORY             0x00000001
145 #define AO_F_SWAP               0x00000002
146 /* AO_F_MEM_ALL: See opt_flags in struct activity below */
147 #define AO_F_MEM_ALL            (AO_F_MEMORY << 8)
148
149 #define DISPLAY_MEMORY(m)       (((m) & AO_F_MEMORY)    == AO_F_MEMORY)
150 #define DISPLAY_SWAP(m)         (((m) & AO_F_SWAP)      == AO_F_SWAP)
151 #define DISPLAY_MEM_ALL(m)      (((m) & AO_F_MEM_ALL)   == AO_F_MEM_ALL)
152
153 /* Output flags for option -u [ ALL ] */
154 #define AO_F_CPU_DEF            0x00000001
155 #define AO_F_CPU_ALL            0x00000002
156
157 #define DISPLAY_CPU_DEF(m)      (((m) & AO_F_CPU_DEF)     == AO_F_CPU_DEF)
158 #define DISPLAY_CPU_ALL(m)      (((m) & AO_F_CPU_ALL)     == AO_F_CPU_ALL)
159
160 /* Output flags for option -d */
161 #define AO_F_DISK_PART          0x00000001
162
163 #define COLLECT_PARTITIONS(m)   (((m) & AO_F_DISK_PART)   == AO_F_DISK_PART)
164
165 /* Output flags for option -F */
166 #define AO_F_FILESYSTEM         0x00000001
167 #define AO_F_MOUNT              0x00000002
168
169 #define DISPLAY_MOUNT(m)        (((m) & AO_F_MOUNT)       == AO_F_MOUNT)
170
171 /*
172  ***************************************************************************
173  * Various keywords and constants.
174  ***************************************************************************
175  */
176
177 /* Keywords */
178 #define K_A_NULL        "A_NULL"
179 #define K_XALL          "XALL"
180 #define K_SUM           "SUM"
181 #define K_DEV           "DEV"
182 #define K_EDEV          "EDEV"
183 #define K_NFS           "NFS"
184 #define K_NFSD          "NFSD"
185 #define K_SOCK          "SOCK"
186 #define K_IP            "IP"
187 #define K_EIP           "EIP"
188 #define K_ICMP          "ICMP"
189 #define K_EICMP         "EICMP"
190 #define K_TCP           "TCP"
191 #define K_ETCP          "ETCP"
192 #define K_UDP           "UDP"
193 #define K_SOCK6         "SOCK6"
194 #define K_IP6           "IP6"
195 #define K_EIP6          "EIP6"
196 #define K_ICMP6         "ICMP6"
197 #define K_EICMP6        "EICMP6"
198 #define K_UDP6          "UDP6"
199 #define K_CPU           "CPU"
200 #define K_FAN           "FAN"
201 #define K_TEMP          "TEMP"
202 #define K_IN            "IN"
203 #define K_FREQ          "FREQ"
204 #define K_MOUNT         "MOUNT"
205 #define K_FC            "FC"
206 #define K_SOFT          "SOFT"
207
208 #define K_INT           "INT"
209 #define K_DISK          "DISK"
210 #define K_XDISK         "XDISK"
211 #define K_SNMP          "SNMP"
212 #define K_IPV6          "IPV6"
213 #define K_POWER         "POWER"
214 #define K_USB           "USB"
215
216 #define K_SKIP_EMPTY    "skipempty"
217 #define K_AUTOSCALE     "autoscale"
218 #define K_ONEDAY        "oneday"
219 #define K_SHOWIDLE      "showidle"
220 #define K_SHOWINFO      "showinfo"
221 #define K_DEBUG         "debug"
222 #define K_HEIGHT        "height="
223 #define K_PACKED        "packed"
224
225 /* Groups of activities */
226 #define G_DEFAULT       0x00
227 #define G_INT           0x01
228 #define G_DISK          0x02
229 #define G_SNMP          0x04
230 #define G_IPV6          0x08
231 #define G_POWER         0x10
232 #define G_XDISK         0x20
233
234 /* sadc program */
235 #define SADC            "sadc"
236
237 /* Time must have the format HH:MM:SS with HH in 24-hour format */
238 #define DEF_TMSTART     "08:00:00"
239 #define DEF_TMEND       "18:00:00"
240
241 #define UTSNAME_LEN     65
242 #define HEADER_LINE_LEN 512
243
244 /*
245  * Define upper limit for various items.
246  * Made necessary because we have to check the number of
247  * items for each activity when we read a (possibly tainted)
248  * sa data file.
249  */
250 #define MAX_NR_SERIAL_LINES     65536
251 #define MAX_NR_DISKS            (65536 * 4096)
252 #define MAX_NR_IFACES           65536
253 #define MAX_NR_FANS             4096
254 #define MAX_NR_TEMP_SENSORS     4096
255 #define MAX_NR_IN_SENSORS       4096
256 #define MAX_NR_USB              65536
257 #define MAX_NR_FS               (65536 * 4096)
258 #define MAX_NR_FCHOSTS          65536
259
260 /* NR_MAX is the upper limit used for unknown activities */
261 #define NR_MAX          (65536 * 4096)
262 #define NR2_MAX         1024
263
264 /* Maximum number of args that can be passed to sadc */
265 #define MAX_ARGV_NR     32
266
267 /* Miscellaneous constants */
268 #define USE_SADC                0
269 #define USE_SA_FILE             1
270 #define NO_TM_START             0
271 #define NO_TM_END               0
272 #define NO_RESET                0
273 #define NON_FATAL               0
274 #define FATAL                   1
275 #define C_SAR                   0
276 #define C_SADF                  1
277 #define ALL_ACTIVITIES          ~0U
278 #define EXIT_IF_NOT_FOUND       1
279 #define RESUME_IF_NOT_FOUND     0
280
281 #define SOFT_SIZE       0
282 #define HARD_SIZE       1
283
284 #define FIRST   0
285 #define SECOND  1
286
287 #define END_OF_DATA_UNEXPECTED  1
288 #define INCONSISTENT_INPUT_DATA 2
289
290 #define CLOSE_XML_MARKUP        0
291 #define OPEN_XML_MARKUP         1
292
293 #define CLOSE_JSON_MARKUP       0
294 #define OPEN_JSON_MARKUP        1
295
296 #define COUNT_ACTIVITIES        0
297 #define COUNT_OUTPUTS           1
298
299 /* Type for all functions reading statistics */
300 #define __read_funct_t  void
301 /* Type for all functions displaying statistics */
302 #define __print_funct_t void
303
304 /* Structure for SVG specific parameters */
305 struct svg_parm {
306         unsigned long long dt;                  /* Interval of time for current sample */
307         unsigned long long ust_time_ref;        /* X axis start time in seconds since the epoch */
308         unsigned long long ust_time_end;        /* X axis end time in seconds since the epoch */
309         unsigned long long ust_time_first;      /* Time (in seconds since the epoch) for first sample */
310         int graph_no;                           /* Total number of views already displayed */
311         int restart;                            /* TRUE if we have just met a RESTART record */
312         __nr_t nr_max;                          /* Maximum number of items for this activity */
313         struct file_header *file_hdr;           /* Pointer on file header structure */
314 };
315
316 /* Structure used when displaying SVG header */
317 struct svg_hdr_parm {
318         int graph_nr;      /* Number of rows of views to display or canvas height entered on the command line */
319         int views_per_row; /* Maximum number of views on a single row */
320 };
321
322 /*
323  ***************************************************************************
324  * System activity data files
325  *
326  * The rule is: "strict writing, read any", meaning that sar/sadc can
327  * only append data to a datafile whose format is strictly the same as that
328  * of current version (checking FORMAT_MAGIC is not enough), but sar/sadf
329  * can read data from different versions, providing that FORMAT_MAGIC value
330  * has not changed (note that we are talking here of data read from a file,
331  * not data that sar reads from sadc, in which case the "strict" rule applies).
332  *
333  * Format of system activity data files:
334  *       __
335  *      |
336  *      | file_magic structure
337  *      |
338  *      |--
339  *      |
340  *      | file_header structure
341  *      |
342  *      |--                         --|
343  *      |                             |
344  *      | file_activity structure     | * sa_act_nr
345  *      |                             |
346  *      |--                         --|
347  *      |                             |
348  *      | record_header structure     |
349  *      |                             |
350  *      |--                           |
351  *      |(__nr_t)                     |
352  *      |--                           |
353  *      |                             |
354  *      | Statistics structure(s)     | * <count>
355  *      |                             |
356  *      |--                           |
357  *      |(__nr_t)                     |
358  *      |--                           |
359  *      |                             |
360  *      | Statistics structure(s)...  |
361  *      |                             |
362  *      |--                         --|
363  *
364  * Note: For activities with varying number of items, a __nr_t value, giving
365  * the number of items, arrives before the statistics structures so that
366  * we know how many of them have to be read.
367  * NB: This value exists for all the activities even if they share the same
368  * count function (e.g. A_NET_DEV and A_NET_EDEV). Indeed, statistics are not
369  * read atomically and the number of items (e.g. network interfaces) may have
370  * varied in between.
371  *
372  * If the record header's type is R_COMMENT then we find only a comment
373  * following the record_header structure.
374  * If the record_header's type is R_RESTART then we find only the number of CPU
375  * (of type __nr_t) of the machine following the record_header structure.
376  ***************************************************************************
377  */
378
379 /*
380  * Sysstat magic number. Should never be modified.
381  * Indicate that the file was created by sysstat.
382  */
383 #define SYSSTAT_MAGIC   0xd596
384 #define SYSSTAT_MAGIC_SWAPPED   (((SYSSTAT_MAGIC << 8) | (SYSSTAT_MAGIC >> 8)) & 0xffff)
385
386 /*
387  * Datafile format magic number.
388  * Modified to indicate that the format of the file is
389  * no longer compatible with that of previous sysstat versions.
390  */
391 #define FORMAT_MAGIC    0x2175
392 #define FORMAT_MAGIC_SWAPPED    (((FORMAT_MAGIC << 8) | (FORMAT_MAGIC >> 8)) & 0xffff)
393
394 /* Previous datafile format magic numbers used by older sysstat versions */
395 #define FORMAT_MAGIC_2171               0x2171
396 #define FORMAT_MAGIC_2171_SWAPPED       (((FORMAT_MAGIC_2171 << 8) | (FORMAT_MAGIC_2171 >> 8)) & 0xffff)
397 #define FORMAT_MAGIC_2173               0x2173
398 #define FORMAT_MAGIC_2173_SWAPPED       (((FORMAT_MAGIC_2173 << 8) | (FORMAT_MAGIC_2173 >> 8)) & 0xffff)
399
400 /* Padding in file_magic structure. See below. */
401 #define FILE_MAGIC_PADDING      48
402
403 /* Structure for file magic header data */
404 struct file_magic {
405         /*
406          * This field identifies the file as a file created by sysstat.
407          */
408         unsigned short sysstat_magic;
409         /*
410          * The value of this field varies whenever datafile format changes.
411          */
412         unsigned short format_magic;
413         /*
414          * Sysstat version used to create the file.
415          */
416         unsigned char sysstat_version;
417         unsigned char sysstat_patchlevel;
418         unsigned char sysstat_sublevel;
419         unsigned char sysstat_extraversion;
420 #define FILE_MAGIC_ULL_NR       0       /* Nr of unsigned long long below */
421 #define FILE_MAGIC_UL_NR        0       /* Nr of unsigned long below */
422 #define FILE_MAGIC_U_NR         5       /* Nr of [unsigned] int below */
423         /*
424          * Size of file's header (size of file_header structure used by file).
425          */
426         unsigned int header_size;
427         /*
428          * Set to non zero if data file has been converted with "sadf -c" from
429          * an old format (version x.y.z) to a newest format (version X.Y.Z).
430          * In this case, the value is: Y*256 + Z + 1.
431          * The FORMAT_MAGIC value of the file can be used to determine X.
432          */
433         unsigned int upgraded;
434         /*
435          * Description of the file_header structure
436          * (nr of "long long", nr of "long" and nr of "int").
437          */
438         unsigned int hdr_types_nr[3];
439         /*
440          * Padding. Reserved for future use while avoiding a format change.
441          * sysstat always reads a number of bytes which is that expected for
442          * current sysstat version (FILE_MAGIC_SIZE). We cannot guess if we
443          * are going to read a file from current, an older or a newer version.
444          */
445         unsigned char pad[FILE_MAGIC_PADDING];
446 };
447
448 #define FILE_MAGIC_SIZE (sizeof(struct file_magic))
449
450 /* Header structure for system activity data file */
451 struct file_header {
452         /*
453          * Timestamp in seconds since the epoch.
454          */
455         unsigned long long sa_ust_time;
456         /*
457          * Number of jiffies per second.
458          */
459         unsigned long sa_hz             __attribute__ ((aligned (8)));
460         /*
461          * Number of [online or offline] CPU (1 .. CPU_NR + 1)
462          * when the datafile has been created.
463          * When reading a datafile, this value is updated (in memory)
464          * whenever a RESTART record is found.
465          * When writing or appending data to a file, this field is updated
466          * neither in file nor in memory.
467          */
468         unsigned int sa_cpu_nr          __attribute__ ((aligned (8)));
469         /*
470          * Number of activities saved in file.
471          */
472         unsigned int sa_act_nr;
473         /*
474          * Current year.
475          */
476         int sa_year;
477         /*
478          * Description of the file_activity and record_header structures
479          * (nr of "long long", nr of "long" and nr of "int").
480          */
481         unsigned int act_types_nr[3];
482         unsigned int rec_types_nr[3];
483         /*
484          * Size of file_activity and record_header structures used by file.
485          */
486         unsigned int act_size;
487         unsigned int rec_size;
488         /*
489          * Current day and month.
490          * No need to save DST (Daylight Saving Time) flag, since it is not taken
491          * into account by the strftime() function used to print the timestamp.
492          */
493         unsigned char sa_day;
494         unsigned char sa_month;
495         /*
496          * Size of a long integer. Useful to know the architecture on which
497          * the datafile was created.
498          */
499         char sa_sizeof_long;
500         /*
501          * Operating system name.
502          */
503         char sa_sysname[UTSNAME_LEN];
504         /*
505          * Machine hostname.
506          */
507         char sa_nodename[UTSNAME_LEN];
508         /*
509          * Operating system release number.
510          */
511         char sa_release[UTSNAME_LEN];
512         /*
513          * Machine architecture.
514          */
515         char sa_machine[UTSNAME_LEN];
516 };
517
518 #define FILE_HEADER_SIZE        (sizeof(struct file_header))
519 #define FILE_HEADER_ULL_NR      1       /* Nr of unsigned long long in file_header structure */
520 #define FILE_HEADER_UL_NR       1       /* Nr of unsigned long in file_header structure */
521 #define FILE_HEADER_U_NR        11      /* Nr of [unsigned] int in file_header structure */
522 /* The values below are used for sanity check */
523 #define MIN_FILE_HEADER_SIZE    0
524 #define MAX_FILE_HEADER_SIZE    8192
525
526
527 /*
528  * Base magical number for activities.
529  */
530 #define ACTIVITY_MAGIC_BASE     0x8a
531 /*
532  * Magical value used for activities with
533  * unknown format (used for sadf -H only).
534  */
535 #define ACTIVITY_MAGIC_UNKNOWN  0x89
536
537 /* List of activities saved in file */
538 struct file_activity {
539         /*
540          * Identification value of activity.
541          */
542         unsigned int id;
543         /*
544          * Activity magical number.
545          */
546         unsigned int magic;
547         /*
548          * Number of items for this activity
549          * when the data file has been created.
550          */
551         __nr_t nr;
552         /*
553          * Number of sub-items for this activity.
554          */
555         __nr_t nr2;
556         /*
557          * Set to TRUE if statistics are preceded by
558          * a value giving the number of structures to read.
559          */
560         int has_nr;
561         /*
562          * Size of an item structure.
563          */
564         int size;
565         /*
566          * Description of the structure containing statistics for the
567          * given activity (nr of "long long", nr of "long" and nr of "int").
568          */
569         unsigned int types_nr[3];
570 };
571
572 #define FILE_ACTIVITY_SIZE      (sizeof(struct file_activity))
573 #define MAX_FILE_ACTIVITY_SIZE  1024    /* Used for sanity check */
574 #define FILE_ACTIVITY_ULL_NR    0       /* Nr of unsigned long long in file_activity structure */
575 #define FILE_ACTIVITY_UL_NR     0       /* Nr of unsigned long in file_activity structure */
576 #define FILE_ACTIVITY_U_NR      9       /* Nr of [unsigned] int in file_activity structure */
577
578
579 /* Record type */
580 /*
581  * R_STATS means that this is a record of statistics.
582  */
583 #define R_STATS         1
584 /*
585  * R_RESTART means that this is a special record containing
586  * a LINUX RESTART message.
587  */
588 #define R_RESTART       2
589 /*
590  * R_LAST_STATS warns sar that this is the last record to be written
591  * to file before a file rotation, and that the next data to come will
592  * be a header file.
593  * Such a record is tagged R_STATS anyway before being written to file.
594  */
595 #define R_LAST_STATS    3
596 /*
597  * R_COMMENT means that this is a special record containing
598  * a comment.
599  */
600 #define R_COMMENT       4
601
602 /* Maximum length of a comment */
603 #define MAX_COMMENT_LEN 64
604
605 /* Header structure for every record */
606 struct record_header {
607         /*
608          * Machine uptime in 1/100th of a second.
609          */
610         unsigned long long uptime_cs;
611         /*
612          * Timestamp (number of seconds since the epoch).
613          */
614         unsigned long long ust_time;
615         /*
616          * Record type: R_STATS, R_RESTART,...
617          */
618         unsigned char record_type;
619         /*
620          * Timestamp: Hour (0-23), minute (0-59) and second (0-59).
621          * Used to determine TRUE time (immutable, non locale dependent time).
622          */
623         unsigned char hour;
624         unsigned char minute;
625         unsigned char second;
626 };
627
628 #define RECORD_HEADER_SIZE      (sizeof(struct record_header))
629 #define MAX_RECORD_HEADER_SIZE  512     /* Used for sanity check */
630 #define RECORD_HEADER_ULL_NR    2       /* Nr of unsigned long long in record_header structure */
631 #define RECORD_HEADER_UL_NR     0       /* Nr of unsigned long in record_header structure */
632 #define RECORD_HEADER_U_NR      0       /* Nr of unsigned int in record_header structure */
633
634
635 /*
636  ***************************************************************************
637  * Generic description of an activity.
638  ***************************************************************************
639  */
640
641 /* Activity options */
642 #define AO_NULL                 0x00
643 /*
644  * Indicate that corresponding activity should be collected by sadc.
645  */
646 #define AO_COLLECTED            0x01
647 /*
648  * Indicate that corresponding activity should be displayed by sar.
649  */
650 #define AO_SELECTED             0x02
651 /*
652  * Indicate that corresponding activity has items that need to be counted.
653  * This means that its @f_count_index values is >= 0.
654  * (We use AO_COUNTED instead of @f_count_index because @f_count_index
655  * is available (initialized) only for sadc).
656  */
657 #define AO_COUNTED              0x04
658 /*
659  * Indicate that activity's metrics have persistent values when devices
660  * are registered again (this means that when the device is registered again,
661  * the metrics pick the values they had when they had been unregistered).
662  */
663 #define AO_PERSISTENT           0x08
664 /*
665  * This flag should be set for every activity closing a markup used
666  * by several activities. Used by sadf f_xml_print() functions to
667  * display XML output.
668  */
669 #define AO_CLOSE_MARKUP         0x10
670 /*
671  * Indicate that corresponding activity has multiple different
672  * output formats. This is the case for example for memory activity
673  * with options -r and -R.
674  * PS: Such an activity should appear in the list of activities that
675  * sar -A is supposed to display.
676  */
677 #define AO_MULTIPLE_OUTPUTS     0x20
678 /*
679  * Indicate that one (SVG) graph will be displayed for each
680  * distinct item for this activity (sadf -g).
681  */
682 #define AO_GRAPH_PER_ITEM       0x40
683 /*
684  * Indicate that this activity may have sub-items.
685  */
686 #define AO_MATRIX               0x80
687
688 #define IS_COLLECTED(m)         (((m) & AO_COLLECTED)        == AO_COLLECTED)
689 #define IS_SELECTED(m)          (((m) & AO_SELECTED)         == AO_SELECTED)
690 #define HAS_COUNT_FUNCTION(m)   (((m) & AO_COUNTED)          == AO_COUNTED)
691 #define HAS_PERSISTENT_VALUES(m) (((m) & AO_PERSISTENT)      == AO_PERSISTENT)
692 #define CLOSE_MARKUP(m)         (((m) & AO_CLOSE_MARKUP)     == AO_CLOSE_MARKUP)
693 #define HAS_MULTIPLE_OUTPUTS(m) (((m) & AO_MULTIPLE_OUTPUTS) == AO_MULTIPLE_OUTPUTS)
694 #define ONE_GRAPH_PER_ITEM(m)   (((m) & AO_GRAPH_PER_ITEM)   == AO_GRAPH_PER_ITEM)
695 #define IS_MATRIX(m)            (((m) & AO_MATRIX)           == AO_MATRIX)
696
697 #define _buf0   buf[0]
698 #define _nr0    nr[0]
699
700 /* Structure used to define a bitmap needed by an activity */
701 struct act_bitmap {
702         /*
703          * Bitmap for activities that need one. Remember to allocate it
704          * before use!
705          */
706         unsigned char *b_array;
707         /*
708          * Size of the bitmap in bits. In fact, bitmap is sized to b_size + 1
709          * to take into account CPU "all"
710          */
711         int b_size;
712 };
713
714 /*
715  * Structure used to define an activity.
716  * Note: This structure can be modified without changing the format of data files.
717  */
718 struct activity {
719         /*
720          * This variable contains the identification value (A_...) for this activity.
721          */
722         unsigned int id;
723         /*
724          * Activity options (AO_...)
725          */
726         unsigned int options;
727         /*
728          * Activity magical number. This number changes when activity format in file
729          * is no longer compatible with the format of that same activity from
730          * previous versions.
731          */
732         unsigned int magic;
733         /*
734          * An activity belongs to a group (and only one).
735          * Groups are those selected with option -S of sadc.
736          */
737         unsigned int group;
738         /*
739          * Index in f_count[] array to determine function used to count
740          * the number of items (serial lines, network interfaces, etc.) -> @nr
741          * Such a function should _always_ return a value greater than
742          * or equal to 0.
743          *
744          * A value of -1 indicates that the number of items
745          * is a constant (and @nr is set to this value).
746          *
747          * These functions are called even if corresponding activities have not
748          * been selected, to make sure that all items have been calculated
749          * (including #CPU, etc.)
750          */
751         int f_count_index;
752         /*
753          * The f_count2() function is used to count the number of
754          * sub-items -> @nr2
755          * Such a function should _always_ return a value greater than
756          * or equal to 0.
757          *
758          * A NULL value for this function pointer indicates that the number of items
759          * is a constant (and @nr2 is set to this value).
760          */
761         __nr_t (*f_count2) (struct activity *);
762         /*
763          * This function reads the relevant file and fill the buffer
764          * with statistics corresponding to given activity.
765          */
766         __read_funct_t (*f_read) (struct activity *);
767         /*
768          * This function displays activity statistics onto the screen.
769          */
770         __print_funct_t (*f_print) (struct activity *, int, int, unsigned long long);
771         /*
772          * This function displays average activity statistics onto the screen.
773          */
774         __print_funct_t (*f_print_avg) (struct activity *, int, int, unsigned long long);
775         /*
776          * This function is used by sadf to display activity in a format that can
777          * easily be ingested by a relational database, or a format that can be
778          * handled by pattern processing commands like "awk".
779          */
780         __print_funct_t (*f_render) (struct activity *, int, char *, int, unsigned long long);
781         /*
782          * This function is used by sadf to display activity statistics in XML.
783          */
784         __print_funct_t (*f_xml_print) (struct activity *, int, int, unsigned long long);
785         /*
786          * This function is used by sadf to display activity statistics in JSON.
787          */
788         __print_funct_t (*f_json_print) (struct activity *, int, int, unsigned long long);
789         /*
790          * This function is used by sadf to display activity statistics in SVG.
791          */
792         __print_funct_t (*f_svg_print) (struct activity *, int, int, struct svg_parm *,
793                                         unsigned long long, struct record_header *);
794         /*
795          * This function is used by sadf to display activity statistics in raw format.
796          */
797         __print_funct_t (*f_raw_print) (struct activity *, char *, int);
798         /*
799          * Header string displayed by sadf -d.
800          * Header lines for each output (for activities with multiple outputs) are
801          * separated with a '|' character.
802          * For a given output, the first field corresponding to extended statistics
803          * (eg. -r ALL) begins with a '&' character.
804          */
805         char *hdr_line;
806         /*
807          * Name of activity.
808          */
809         char *name;
810         /*
811          * Description of the corresponding structure containing statistics (as defined
812          * in rd_stats.h or rd_sensors.h). Such a structure has 0+ fields of type
813          * "long long", followed by 0+ fields of type "long", followed by 0+ fields of
814          * type "int", followed by 0+ other fields (e.g. of type char). The array below
815          * gives the number of "long long" fields composing the structure, then the number
816          * of "long" fields, then the number of "int" fields.
817          */
818         unsigned int gtypes_nr[3];
819         /*
820          * This array has the same meaning as @gtypes_nr[] above, but the values are those
821          * read from current data file. They may be different from those of @gtypes_nr[]
822          * because we can read data from a different sysstat version (older or newer).
823          */
824         unsigned int ftypes_nr[3];
825         /*
826          * Number of SVG graphs for this activity. The total number of graphs for
827          * the activity can be greater though if flag AO_GRAPH_PER_ITEM is set, in
828          * which case the total number will  be @g_nr * @nr.
829          */
830         int g_nr;
831         /*
832          * Number of items on the system, as counted when the system is initialized.
833          * A negative value (-1) is the default value and indicates that this number
834          * has still not been calculated by the f_count() function.
835          * A value of 0 means that this number has been calculated, but no items have
836          * been found.
837          * A positive value (>0) has either been calculated or is a constant.
838          */
839         __nr_t nr_ini;
840         /*
841          * Number of sub-items on the system.
842          * @nr2 is in fact the second dimension of a matrix of items, the first
843          * one being @nr. @nr is the number of lines, and @nr2 the number of columns.
844          * A negative value (-1) is the default value and indicates that this number
845          * has still not been calculated by the f_count2() function.
846          * A value of 0 means that this number has been calculated, but no sub-items have
847          * been found.
848          * A positive value (>0) has either been calculated or is a constant.
849          * Rules:
850          * 1) IF @nr2 = 0 THEN @nr = 0
851          *    Note: If @nr = 0, then @nr2 is undetermined (may be -1, 0 or >0).
852          * 2) IF @nr > 0 THEN @nr2 > 0.
853          *    Note: If @nr2 > 0 then @nr is undetermined (may be -1, 0 or >0).
854          * 3) IF @nr <= 0 THEN @nr2 = -1 (this is the default value for @nr2,
855          * meaning that it has not been calculated).
856          */
857         __nr_t nr2;
858         /*
859          * Maximum number of elements that sar can handle for this item.
860          * NB: The maximum number of elements that sar can handle for sub-items
861          * is NR2_MAX.
862          */
863         __nr_t nr_max;
864         /*
865          * Number of items, as read and saved in corresponding buffer (@buf: See below).
866          * The value may be zero for a particular sample if no items have been found.
867          */
868         __nr_t nr[3];
869         /*
870          * Number of structures allocated in @buf[*]. This number should be greater
871          * than or equal to @nr[*].
872          */
873         __nr_t nr_allocated;
874         /*
875          * Size of an item.
876          * This is the size of the corresponding structure, as read from or written
877          * to a file, or read from or written by the data collector.
878          */
879         int fsize;
880         /*
881          * Size of an item.
882          * This is the size of the corresponding structure as mapped into memory.
883          * @msize can be different from @fsize when data are read from or written to
884          * a data file from a different sysstat version.
885          */
886         int msize;
887         /*
888          * Optional flags for activity. This is eg. used when AO_MULTIPLE_OUTPUTS
889          * option is set.
890          * 0x0001 - 0x0080 : Multiple outputs (eg. AO_F_MEMORY, AO_F_SWAP...)
891          * 0x0100 - 0x8000 : If bit set then display complete header (hdr_line) for
892          *                   corresponding output
893          * 0x010000+       : Optional flags
894          */
895         unsigned int opt_flags;
896         /*
897          * Buffers that will contain the statistics read. Its size is @nr * @nr2 * @size each.
898          * [0]: used by sadc.
899          * [0] and [1]: current/previous statistics values (used by sar).
900          * [2]: Used by sar to save first collected stats (used later to
901          * compute average).
902          */
903         void *buf[3];
904         /*
905          * Bitmap for activities that need one. Such a bitmap is needed by activity
906          * if @bitmap is not NULL.
907          */
908         struct act_bitmap *bitmap;
909 };
910
911
912 /*
913  ***************************************************************************
914  * Generic description of an output format for sadf (and sar).
915  ***************************************************************************
916  */
917
918 /* Type for all functions used by sadf to display stats in various formats */
919 #define __printf_funct_t void
920 #define __tm_funct_t char *
921
922 /*
923  * Structure used to define a report.
924  * A XML-like report has the following format:
925  *       __
926  *      |
927  *      | Header block
928  *      |  __
929  *      | |
930  *      | | Statistics block
931  *      | |  __
932  *      | | |
933  *      | | | Timestamp block
934  *      | | |  __
935  *      | | | |
936  *      | | | | Activity #1
937  *      | | | |__
938  *      | | | |
939  *      | | | | ...
940  *      | | | |__
941  *      | | | |
942  *      | | | | Activity #n
943  *      | | | |__
944  *      | | |__
945  *      | |__
946  *      | |
947  *      | | Restart messages block
948  *      | |__
949  *      | |
950  *      | | Comments block
951  *      | |__
952  *      |__
953  */
954 struct report_format {
955         /*
956          * This variable contains the identification value (F_...) for this report format.
957          */
958         unsigned int id;
959         /*
960          * Format options (FO_...).
961          */
962         unsigned int options;
963         /*
964          * This function displays the report header
965          * (data displayed once at the beginning of the report).
966          */
967         __printf_funct_t (*f_header) (void *, int, char *, struct file_magic *, struct file_header *,
968                                       struct activity * [], unsigned int [], struct file_activity *);
969         /*
970          * This function defines the statistics part of the report.
971          * Used only with textual (XML-like) reports.
972          */
973         __printf_funct_t (*f_statistics) (int *, int);
974         /*
975          * This function defines the timestamp part of the report.
976          * Used only with textual (XML-like) reports.
977          */
978         __tm_funct_t (*f_timestamp) (void *, int, char *, char *, unsigned long long,
979                                      struct file_header *, unsigned int);
980         /*
981          * This function displays the restart messages.
982          */
983         __printf_funct_t (*f_restart) (int *, int, char *, char *, int, struct file_header *);
984         /*
985          * This function displays the comments.
986          */
987         __printf_funct_t (*f_comment) (int *, int, char *, char *, int, char *, struct file_header *);
988 };
989
990 /* Possible actions for functions used to display reports */
991 #define F_BEGIN 0x01
992 #define F_MAIN  0x02
993 #define F_END   0x04
994
995 /*
996  ***************************************************************************
997  * SVG output definitions
998  ***************************************************************************
999  */
1000
1001 /*
1002  *   ^
1003  * 1 | General header
1004  *   v
1005  *   ^   ^   ^
1006  *   |   | 4 | Graph title
1007  *   |   |   v
1008  *   |   |   ^    |                                Caption
1009  *   | 3 |   |    |
1010  *   |   |   |  G |Y
1011  * 2 |   | 5 |  r |
1012  *   |   |   |  a |A
1013  *   |   |   |  d |x
1014  *   |   |   |  . |i
1015  *   |   |   |    |s          X Axis
1016  *   |   |   v    |-------------------------------
1017  *   |   |              Grad.
1018  *   |   v   <---><------------------------------>
1019  *   |         6                8
1020  *   | Gap
1021  *   v<---------------------------------------------------------------> Gap
1022  *                                    7
1023  *    <--------------------------------------------------------------------->
1024  *                                      8
1025  */
1026
1027 /* #8 */
1028 #define SVG_G_XSIZE     720
1029 /* #6 */
1030 #define SVG_M_XSIZE     70
1031 /* #7 */
1032 #define SVG_V_XSIZE     1050
1033 /* #8 */
1034 #define SVG_T_XSIZE     1060
1035
1036 /* #5 */
1037 #define SVG_G_YSIZE     200
1038 /* #1 */
1039 #define SVG_H_YSIZE     50
1040 /* #4 */
1041 #define SVG_M_YSIZE     50
1042 /* #2 */
1043 #define SVG_T_YSIZE     310
1044 /* #3 */
1045 #define SVG_V_YSIZE     300
1046
1047 /* Grid: Nr of horizontal lines */
1048 #define SVG_H_GRIDNR    3
1049 /* Grid: Nr of vertical lines */
1050 #define SVG_V_GRIDNR    10
1051
1052 /* Block size used to allocate arrays for graphs data */
1053 #define CHUNKSIZE       4096
1054
1055 /* Maximum number of views on a single row */
1056 #define MAX_VIEWS_ON_A_ROW      6
1057
1058 #define SVG_LINE_GRAPH  1
1059 #define SVG_BAR_GRAPH   2
1060
1061 /* Maximum number of horizontal lines for the background grid */
1062 #define MAX_HLINES_NR   10
1063
1064 #define MAYBE   0x80
1065
1066 /*
1067  ***************************************************************************
1068  * Macro functions definitions.
1069  *
1070  * Note: Using 'do ... while' makes the macros safer to use
1071  * (remember that macro use is followed by a semicolon).
1072  ***************************************************************************
1073  */
1074
1075 /* Close file descriptors */
1076 #define CLOSE_ALL(_fd_)         do {                    \
1077                                         close(_fd_[0]); \
1078                                         close(_fd_[1]); \
1079                                 } while (0)
1080
1081 #define CLOSE(_fd_)             if (_fd_ >= 0)          \
1082                                         close(_fd_)
1083
1084
1085 /*
1086  ***************************************************************************
1087  * Various structure definitions.
1088  ***************************************************************************
1089  */
1090
1091 /* Structure for timestamps */
1092 struct tstamp {
1093         int tm_sec;
1094         int tm_min;
1095         int tm_hour;
1096         int use;
1097 };
1098
1099
1100 /*
1101  ***************************************************************************
1102  * Functions prototypes.
1103  ***************************************************************************
1104  */
1105
1106 /* Functions used to count number of items */
1107 __nr_t wrap_get_cpu_nr
1108         (struct activity *);
1109 __nr_t wrap_get_irq_nr
1110         (struct activity *);
1111 __nr_t wrap_get_serial_nr
1112         (struct activity *);
1113 __nr_t wrap_get_disk_nr
1114         (struct activity *);
1115 __nr_t wrap_get_iface_nr
1116         (struct activity *);
1117 __nr_t wrap_get_fan_nr
1118         (struct activity *);
1119 __nr_t wrap_get_temp_nr
1120         (struct activity *);
1121 __nr_t wrap_get_in_nr
1122         (struct activity *);
1123 __nr_t wrap_get_freq_nr
1124         (struct activity *);
1125 __nr_t wrap_get_usb_nr
1126         (struct activity *);
1127 __nr_t wrap_get_filesystem_nr
1128         (struct activity *);
1129 __nr_t wrap_get_fchost_nr
1130         (struct activity *);
1131
1132 /* Functions used to read activities statistics */
1133 __read_funct_t wrap_read_stat_cpu
1134         (struct activity *);
1135 __read_funct_t wrap_read_stat_pcsw
1136         (struct activity *);
1137 __read_funct_t wrap_read_stat_irq
1138         (struct activity *);
1139 __read_funct_t wrap_read_swap
1140         (struct activity *);
1141 __read_funct_t wrap_read_paging
1142         (struct activity *);
1143 __read_funct_t wrap_read_io
1144         (struct activity *);
1145 __read_funct_t wrap_read_meminfo
1146         (struct activity *);
1147 __read_funct_t wrap_read_kernel_tables
1148         (struct activity *);
1149 __read_funct_t wrap_read_loadavg
1150         (struct activity *);
1151 __read_funct_t wrap_read_tty_driver_serial
1152         (struct activity *);
1153 __read_funct_t wrap_read_disk
1154         (struct activity *);
1155 __read_funct_t wrap_read_net_dev
1156         (struct activity *);
1157 __read_funct_t wrap_read_net_edev
1158         (struct activity *);
1159 __read_funct_t wrap_read_net_nfs
1160         (struct activity *);
1161 __read_funct_t wrap_read_net_nfsd
1162         (struct activity *);
1163 __read_funct_t wrap_read_net_sock
1164         (struct activity *);
1165 __read_funct_t wrap_read_net_ip
1166         (struct activity *);
1167 __read_funct_t wrap_read_net_eip
1168         (struct activity *);
1169 __read_funct_t wrap_read_net_icmp
1170         (struct activity *);
1171 __read_funct_t wrap_read_net_eicmp
1172         (struct activity *);
1173 __read_funct_t wrap_read_net_tcp
1174         (struct activity *);
1175 __read_funct_t wrap_read_net_etcp
1176         (struct activity *);
1177 __read_funct_t wrap_read_net_udp
1178         (struct activity *);
1179 __read_funct_t wrap_read_net_sock6
1180         (struct activity *);
1181 __read_funct_t wrap_read_net_ip6
1182         (struct activity *);
1183 __read_funct_t wrap_read_net_eip6
1184         (struct activity *);
1185 __read_funct_t wrap_read_net_icmp6
1186         (struct activity *);
1187 __read_funct_t wrap_read_net_eicmp6
1188         (struct activity *);
1189 __read_funct_t wrap_read_net_udp6
1190         (struct activity *);
1191 __read_funct_t wrap_read_cpuinfo
1192         (struct activity *);
1193 __read_funct_t wrap_read_fan
1194         (struct activity *);
1195 __read_funct_t wrap_read_temp
1196         (struct activity *);
1197 __read_funct_t wrap_read_in
1198         (struct activity *);
1199 __read_funct_t wrap_read_meminfo_huge
1200         (struct activity *);
1201 __read_funct_t wrap_read_cpu_wghfreq
1202         (struct activity *);
1203 __read_funct_t wrap_read_bus_usb_dev
1204         (struct activity *);
1205 __read_funct_t wrap_read_filesystem
1206         (struct activity *);
1207 __read_funct_t wrap_read_fchost
1208         (struct activity *);
1209 __read_funct_t wrap_read_softnet
1210         (struct activity *);
1211
1212 /* Other functions */
1213 int check_alt_sa_dir
1214         (char *, int, int);
1215 void enum_version_nr
1216         (struct file_magic *);
1217 int get_activity_nr
1218         (struct activity * [], unsigned int, int);
1219 int get_activity_position
1220         (struct activity * [], unsigned int, int);
1221 void set_default_file
1222         (char *, int, int);
1223 void handle_invalid_sa_file
1224         (int, struct file_magic *, char *, int);
1225 void print_collect_error
1226         (void);
1227
1228 #ifndef SOURCE_SADC
1229 void allocate_bitmaps
1230         (struct activity * []);
1231 void allocate_structures
1232         (struct activity * []);
1233 int check_disk_reg
1234         (struct activity *, int, int, int);
1235 void check_file_actlst
1236         (int *, char *, struct activity * [], struct file_magic *, struct file_header *,
1237          struct file_activity **, unsigned int [], int, int *, int *);
1238 int check_net_dev_reg
1239         (struct activity *, int, int, int);
1240 int check_net_edev_reg
1241         (struct activity *, int, int, int);
1242 double compute_ifutil
1243         (struct stats_net_dev *, double, double);
1244 void copy_structures
1245         (struct activity * [], unsigned int [], struct record_header [], int, int);
1246 int datecmp
1247         (struct tm *, struct tstamp *);
1248 void display_sa_file_version
1249         (FILE *, struct file_magic *);
1250 void free_bitmaps
1251         (struct activity * []);
1252 void free_structures
1253         (struct activity * []);
1254 char *get_devname
1255         (unsigned int, unsigned int, int);
1256 void get_file_timestamp_struct
1257         (unsigned int, struct tm *, struct file_header *);
1258 void get_itv_value
1259         (struct record_header *, struct record_header *, unsigned long long *);
1260 int next_slice
1261         (unsigned long long, unsigned long long, int, long);
1262 int parse_sar_opt
1263         (char * [], int *, struct activity * [], unsigned int *, int);
1264 int parse_sar_I_opt
1265         (char * [], int *, struct activity * []);
1266 int parse_sa_P_opt
1267         (char * [], int *, unsigned int *, struct activity * []);
1268 int parse_sar_m_opt
1269         (char * [], int *, struct activity * []);
1270 int parse_sar_n_opt
1271         (char * [], int *, struct activity * []);
1272 int parse_timestamp
1273         (char * [], int *, struct tstamp *, const char *);
1274 void print_report_hdr
1275         (unsigned int, struct tm *, struct file_header *);
1276 void print_sar_comment
1277         (int *, int, char *, char *, int, char *, struct file_header *);
1278 __printf_funct_t print_sar_restart
1279         (int *, int, char *, char *, int, struct file_header *);
1280 int print_special_record
1281         (struct record_header *, unsigned int, struct tstamp *, struct tstamp *,
1282          int, int, struct tm *, struct tm *, char *, int, struct file_magic *,
1283          struct file_header *, struct activity * [], struct report_format *, int, int);
1284 void read_file_stat_bunch
1285         (struct activity * [], int, int, int, struct file_activity *, int, int,
1286          char *, struct file_magic *);
1287 __nr_t read_nr_value
1288         (int, char *, struct file_magic *, int, int, int);
1289 int read_record_hdr
1290         (int, void *, struct record_header *, struct file_header *, int, int);
1291 void reallocate_all_buffers
1292         (struct activity *, __nr_t);
1293 void remap_struct
1294         (unsigned int [], unsigned int [], void *, unsigned int);
1295 void replace_nonprintable_char
1296         (int, char *);
1297 int sa_fread
1298         (int, void *, size_t, int);
1299 int sa_get_record_timestamp_struct
1300         (unsigned int, struct record_header *, struct tm *, struct tm *);
1301 int sa_open_read_magic
1302         (int *, char *, struct file_magic *, int, int *, int);
1303 void select_all_activities
1304         (struct activity * []);
1305 void select_default_activity
1306         (struct activity * []);
1307 void set_bitmap
1308         (unsigned char [], unsigned char, unsigned int);
1309 void set_hdr_rectime
1310         (unsigned int, struct tm *, struct file_header *);
1311 void set_record_timestamp_string
1312         (unsigned int, struct record_header *, char *, char *, int, struct tm *);
1313 void swap_struct
1314         (unsigned int [], void *, int);
1315 #endif /* SOURCE_SADC undefined */
1316 #endif  /* _SA_H */