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