]> granicus.if.org Git - sysstat/blob - sa.h
Merge branch 'scop-grep-E'
[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 NON_FATAL               0
303 #define FATAL                   1
304 #define C_SAR                   0
305 #define C_SADF                  1
306 #define ALL_ACTIVITIES          ~0U
307 #define EXIT_IF_NOT_FOUND       1
308 #define RESUME_IF_NOT_FOUND     0
309
310 #define SOFT_SIZE       0
311 #define HARD_SIZE       1
312
313 #define FIRST   0
314 #define SECOND  1
315
316 #define END_OF_DATA_UNEXPECTED  1
317 #define INCONSISTENT_INPUT_DATA 2
318
319 #define UEOF_STOP       0
320 #define UEOF_CONT       1
321
322 #define CLOSE_XML_MARKUP        0
323 #define OPEN_XML_MARKUP         1
324
325 #define CLOSE_JSON_MARKUP       0
326 #define OPEN_JSON_MARKUP        1
327
328 #define COUNT_ACTIVITIES        0
329 #define COUNT_OUTPUTS           1
330
331 /* Type for all functions reading statistics */
332 #define __read_funct_t  void
333 /* Type for all functions displaying statistics */
334 #define __print_funct_t void
335
336 /*
337  ***************************************************************************
338  * Output formats for sadf
339  ***************************************************************************
340  */
341
342 /* Number of output formats */
343 #define NR_FMT  9
344
345 /* Output formats */
346 #define F_SAR_OUTPUT    0
347 #define F_DB_OUTPUT     1
348 #define F_HEADER_OUTPUT 2
349 #define F_PPC_OUTPUT    3
350 #define F_XML_OUTPUT    4
351 #define F_JSON_OUTPUT   5
352 #define F_CONV_OUTPUT   6
353 #define F_SVG_OUTPUT    7
354 #define F_RAW_OUTPUT    8
355 #define F_PCP_OUTPUT    9
356
357
358 /* Structure for SVG specific parameters */
359 struct svg_parm {
360         unsigned long long dt;                  /* Interval of time for current sample */
361         unsigned long long ust_time_ref;        /* X axis start time in seconds since the epoch */
362         unsigned long long ust_time_end;        /* X axis end time in seconds since the epoch */
363         unsigned long long ust_time_first;      /* Time (in seconds since the epoch) for first sample */
364         int graph_no;                           /* Total number of views already displayed */
365         int restart;                            /* TRUE if we have just met a RESTART record */
366         int nr_act_dispd;                       /* Number of activities that will be displayed */
367         struct file_header *file_hdr;           /* Pointer on file header structure */
368 };
369
370 /* Structure used when displaying SVG header */
371 struct svg_hdr_parm {
372         int graph_nr;      /* Number of rows of views to display or canvas height entered on the command line */
373         int views_per_row; /* Maximum number of views on a single row */
374         int nr_act_dispd;  /* Number of activities that will be displayed */
375 };
376
377 /*
378  ***************************************************************************
379  * System activity data files
380  *
381  * The rule is: "strict writing, read any", meaning that sar/sadc can
382  * only append data to a datafile whose format is strictly the same as that
383  * of current version (checking FORMAT_MAGIC is not enough), but sar/sadf
384  * can read data from different versions, providing that FORMAT_MAGIC value
385  * has not changed (note that we are talking here of data read from a file,
386  * not data that sar reads from sadc, in which case the "strict" rule applies).
387  *
388  * Format of system activity data files:
389  *       __
390  *      |
391  *      | file_magic structure
392  *      |
393  *      |--
394  *      |
395  *      | file_header structure
396  *      |
397  *      |--                         --|
398  *      |                             |
399  *      | file_activity structure     | x file_header:sa_act_nr
400  *      |                             |
401  *      |---------                  --|
402  *              |
403  *              | extra_desc structure (exists only if file_header:extra_next != 0)
404  *              |
405  *              |--                         --|
406  *              |                             |
407  *              | unknown extra structure(s)  | x extra_desc:extra_nr
408  *              |                             |
409  *              |--                         --|
410  *              |
411  *              | (extra_desc structure (exists only if previous extra_desc:extra_next != 0))
412  *              |
413  *              |--
414  *              |
415  *              | (...)
416  *              |
417  *      |---------                  --|
418  *      |                             |
419  *      | record_header structure     |
420  *      |                             |
421  *      |---------                  --|
422  *              |
423  *              | extra_desc structure (exists only if record_header:extra_next != 0)
424  *              |
425  *              |--                         --|
426  *              |                             |
427  *              | unknown extra structure(s)  | x extra_desc:extra_nr
428  *              |                             |
429  *              |--                         --|
430  *              |
431  *              | (extra_desc structure (exists only if previous extra_desc:extra_next != 0))
432  *              |
433  *              |--
434  *              |
435  *              | (...)
436  *              |
437  *      |---------                  --|
438  *      |(__nr_t)                     |
439  *      |--                           |
440  *      |                             |
441  *      | Statistics structure(s)     | x <count>
442  *      |                             |
443  *      |--                           |
444  *      |(__nr_t)                     |
445  *      |--                           |
446  *      |                             |
447  *      | Statistics structure(s)...  |
448  *      |                             |
449  *      |--                         --|
450  *
451  * Note: For activities with varying number of items, a __nr_t value, giving
452  * the number of items, arrives before the statistics structures so that
453  * we know how many of them have to be read.
454  * NB: This value exists for all the activities even if they share the same
455  * count function (e.g. A_NET_DEV and A_NET_EDEV). Indeed, statistics are not
456  * read atomically and the number of items (e.g. network interfaces) may have
457  * varied in between.
458  *
459  * If the record header's type is R_COMMENT then we find only a comment
460  * following the record_header structure.
461  *
462  * If the record_header's type is R_RESTART then we find only the number of CPU
463  * (of type __nr_t) of the machine following the record_header structure.
464  * This number is 1 for 1 CPU and not an SMP kernel (CPU "all"),
465  * 2 for 1 CPU and SMP kernel (CPU "all" and CPU 0), etc.
466  * Of course we display the real number of CPU (e.g. "1" for 1 CPU and SMP
467  * kernel) with the LINUX RESTART message.
468  *
469  * If the record_header's type is R_EXTRA* then we find only a list of extra
470  * structures following the record_header structure but no statistics ones.
471  * Note that extra structures may exist for all record_header types
472  * (R_STATS, R_COMMENT, R_RESTART...). For R_COMMENT and R_RESTART records,
473  * the extra structures will be found after the comment or the number of CPU.
474  ***************************************************************************
475  */
476
477 /*
478  * Sysstat magic number. Should never be modified.
479  * Indicate that the file was created by sysstat.
480  */
481 #define SYSSTAT_MAGIC   0xd596
482 #define SYSSTAT_MAGIC_SWAPPED   (((SYSSTAT_MAGIC << 8) | (SYSSTAT_MAGIC >> 8)) & 0xffff)
483
484 /*
485  * Datafile format magic number.
486  * Modified to indicate that the format of the file is
487  * no longer compatible with that of previous sysstat versions.
488  */
489 #define FORMAT_MAGIC    0x2175
490 #define FORMAT_MAGIC_SWAPPED    (((FORMAT_MAGIC << 8) | (FORMAT_MAGIC >> 8)) & 0xffff)
491
492 /* Previous datafile format magic numbers used by older sysstat versions */
493 #define FORMAT_MAGIC_2171               0x2171
494 #define FORMAT_MAGIC_2171_SWAPPED       (((FORMAT_MAGIC_2171 << 8) | (FORMAT_MAGIC_2171 >> 8)) & 0xffff)
495 #define FORMAT_MAGIC_2173               0x2173
496 #define FORMAT_MAGIC_2173_SWAPPED       (((FORMAT_MAGIC_2173 << 8) | (FORMAT_MAGIC_2173 >> 8)) & 0xffff)
497
498 /* Padding in file_magic structure. See below. */
499 #define FILE_MAGIC_PADDING      48
500
501 /* Structure for file magic header data */
502 struct file_magic {
503         /*
504          * This field identifies the file as a file created by sysstat.
505          */
506         unsigned short sysstat_magic;
507         /*
508          * The value of this field varies whenever datafile format changes.
509          */
510         unsigned short format_magic;
511         /*
512          * Sysstat version used to create the file.
513          */
514         unsigned char sysstat_version;
515         unsigned char sysstat_patchlevel;
516         unsigned char sysstat_sublevel;
517         unsigned char sysstat_extraversion;
518 #define FILE_MAGIC_ULL_NR       0       /* Nr of unsigned long long below */
519 #define FILE_MAGIC_UL_NR        0       /* Nr of unsigned long below */
520 #define FILE_MAGIC_U_NR         5       /* Nr of [unsigned] int below */
521         /*
522          * Size of file's header (size of file_header structure used by file).
523          */
524         unsigned int header_size;
525         /*
526          * Set to non zero if data file has been converted with "sadf -c" from
527          * an old format (version x.y.z) to a newest format (version X.Y.Z).
528          * In this case, the value is: Y*256 + Z + 1.
529          * The FORMAT_MAGIC value of the file can be used to determine X.
530          */
531         unsigned int upgraded;
532         /*
533          * Description of the file_header structure
534          * (nr of "long long", nr of "long" and nr of "int").
535          */
536         unsigned int hdr_types_nr[3];
537         /*
538          * Padding. Reserved for future use while avoiding a format change.
539          * sysstat always reads a number of bytes which is that expected for
540          * current sysstat version (FILE_MAGIC_SIZE). We cannot guess if we
541          * are going to read a file from current, an older or a newer version.
542          */
543         unsigned char pad[FILE_MAGIC_PADDING];
544 };
545
546 #define FILE_MAGIC_SIZE (sizeof(struct file_magic))
547
548 /* Header structure for system activity data file */
549 struct file_header {
550         /*
551          * Timestamp in seconds since the epoch.
552          */
553         unsigned long long sa_ust_time;
554         /*
555          * Number of jiffies per second.
556          */
557         unsigned long sa_hz             __attribute__ ((aligned (8)));
558         /*
559          * Number of [online or offline] CPU (1 .. CPU_NR + 1)
560          * when the datafile has been created.
561          * When reading a datafile, this value is updated (in memory)
562          * whenever a RESTART record is found.
563          * When writing or appending data to a file, this field is updated
564          * neither in file nor in memory.
565          */
566         unsigned int sa_cpu_nr          __attribute__ ((aligned (8)));
567         /*
568          * Number of activities saved in file.
569          */
570         unsigned int sa_act_nr;
571         /*
572          * Current year.
573          */
574         int sa_year;
575         /*
576          * Description of the file_activity and record_header structures
577          * (nr of "long long", nr of "long" and nr of "int").
578          */
579         unsigned int act_types_nr[3];
580         unsigned int rec_types_nr[3];
581         /*
582          * Size of file_activity and record_header structures used by file.
583          */
584         unsigned int act_size;
585         unsigned int rec_size;
586         /*
587          * TRUE if an extra_desc structure exists.
588          */
589         unsigned int extra_next;
590         /*
591          * Current day and month.
592          * No need to save DST (Daylight Saving Time) flag, since it is not taken
593          * into account by the strftime() function used to print the timestamp.
594          */
595         unsigned char sa_day;
596         unsigned char sa_month;
597         /*
598          * Size of a long integer. Useful to know the architecture on which
599          * the datafile was created.
600          */
601         char sa_sizeof_long;
602         /*
603          * Operating system name.
604          */
605         char sa_sysname[UTSNAME_LEN];
606         /*
607          * Machine hostname.
608          */
609         char sa_nodename[UTSNAME_LEN];
610         /*
611          * Operating system release number.
612          */
613         char sa_release[UTSNAME_LEN];
614         /*
615          * Machine architecture.
616          */
617         char sa_machine[UTSNAME_LEN];
618         /*
619          * Timezone value.
620          */
621         char sa_tzname[TZNAME_LEN];
622 };
623
624 #define FILE_HEADER_SIZE        (sizeof(struct file_header))
625 #define FILE_HEADER_ULL_NR      1       /* Nr of unsigned long long in file_header structure */
626 #define FILE_HEADER_UL_NR       1       /* Nr of unsigned long in file_header structure */
627 #define FILE_HEADER_U_NR        12      /* Nr of [unsigned] int in file_header structure */
628 /* The values below are used for sanity check */
629 #define MIN_FILE_HEADER_SIZE    0
630 #define MAX_FILE_HEADER_SIZE    8192
631
632
633 /*
634  * Base magical number for activities.
635  */
636 #define ACTIVITY_MAGIC_BASE     0x8a
637 /*
638  * Magical value used for activities with
639  * unknown format (used for sadf -H only).
640  */
641 #define ACTIVITY_MAGIC_UNKNOWN  0x89
642
643 /* List of activities saved in file */
644 struct file_activity {
645         /*
646          * Identification value of activity.
647          */
648         unsigned int id;
649         /*
650          * Activity magical number.
651          */
652         unsigned int magic;
653         /*
654          * Number of items for this activity
655          * when the data file has been created.
656          */
657         __nr_t nr;
658         /*
659          * Number of sub-items for this activity.
660          */
661         __nr_t nr2;
662         /*
663          * Set to TRUE if statistics are preceded by
664          * a value giving the number of structures to read.
665          */
666         int has_nr;
667         /*
668          * Size of an item structure.
669          */
670         int size;
671         /*
672          * Description of the structure containing statistics for the
673          * given activity (nr of "long long", nr of "long" and nr of "int").
674          */
675         unsigned int types_nr[3];
676 };
677
678 #define FILE_ACTIVITY_SIZE      (sizeof(struct file_activity))
679 #define MAX_FILE_ACTIVITY_SIZE  1024    /* Used for sanity check */
680 #define FILE_ACTIVITY_ULL_NR    0       /* Nr of unsigned long long in file_activity structure */
681 #define FILE_ACTIVITY_UL_NR     0       /* Nr of unsigned long in file_activity structure */
682 #define FILE_ACTIVITY_U_NR      9       /* Nr of [unsigned] int in file_activity structure */
683
684 #define MAX_ITEM_STRUCT_SIZE    1024    /* Used for sanity check */
685
686 /*
687  * Description of an extra structure.
688  * The composition of this structure should not change in time.
689  */
690 struct extra_desc {
691         /*
692          * Number of extra structures to read.
693          */
694         unsigned int extra_nr;
695         /*
696          * Size of an extra structure.
697          */
698         unsigned int extra_size;
699         /*
700          * TRUE if another extra_desc structure exists after
701          * all the extra structures.
702          */
703         unsigned int extra_next;
704         /*
705          * Description of an extra structure
706          * (nr of "long long", nr of "long" and nr of "int").
707          */
708         unsigned int extra_types_nr[3];
709 };
710
711 #define EXTRA_DESC_SIZE         (sizeof(struct extra_desc))
712 #define EXTRA_DESC_ULL_NR       0       /* Nr of unsigned long long in extra_desc structure */
713 #define EXTRA_DESC_UL_NR        0       /* Nr of unsigned long in extra_desc structure */
714 #define EXTRA_DESC_U_NR         6       /* Nr of [unsigned] int in extra_desc structure */
715 #define MAX_EXTRA_NR            8192
716 #define MAX_EXTRA_SIZE          1024
717
718 /* Record type */
719 /*
720  * R_STATS means that this is a record of statistics.
721  */
722 #define R_STATS         1
723 /*
724  * R_RESTART means that this is a special record containing
725  * a LINUX RESTART message.
726  */
727 #define R_RESTART       2
728 /*
729  * R_LAST_STATS warns sar that this is the last record to be written
730  * to file before a file rotation, and that the next data to come will
731  * be a header file.
732  * Such a record is tagged R_STATS anyway before being written to file.
733  */
734 #define R_LAST_STATS    3
735 /*
736  * R_COMMENT means that this is a special record containing
737  * a comment.
738  */
739 #define R_COMMENT       4
740 /*
741  * R_EXTRA* records means that extra structures are following current
742  * record_header structure, but no statistics structures.
743  */
744 #define R_EXTRA_MIN     5
745 #define R_EXTRA_MAX     15
746
747 /* Maximum length of a comment */
748 #define MAX_COMMENT_LEN 64
749
750 /* Header structure for every record */
751 struct record_header {
752         /*
753          * Machine uptime in 1/100th of a second.
754          */
755         unsigned long long uptime_cs;
756         /*
757          * Timestamp (number of seconds since the epoch).
758          */
759         unsigned long long ust_time;
760         /*
761          * TRUE if an extra_desc structure exists.
762          */
763         unsigned int extra_next;
764         /*
765          * Record type: R_STATS, R_RESTART,...
766          */
767         unsigned char record_type;
768         /*
769          * Timestamp: Hour (0-23), minute (0-59) and second (0-60).
770          * Used to determine TRUE time.
771          * Hour value depends in fact on timezone (TZ variable) value.
772          */
773         unsigned char hour;
774         unsigned char minute;
775         unsigned char second;
776 };
777
778 #define RECORD_HEADER_SIZE      (sizeof(struct record_header))
779 #define MAX_RECORD_HEADER_SIZE  512     /* Used for sanity check */
780 #define RECORD_HEADER_ULL_NR    2       /* Nr of unsigned long long in record_header structure */
781 #define RECORD_HEADER_UL_NR     0       /* Nr of unsigned long in record_header structure */
782 #define RECORD_HEADER_U_NR      1       /* Nr of unsigned int in record_header structure */
783
784
785 /*
786  ***************************************************************************
787  * Generic description of an activity.
788  ***************************************************************************
789  */
790
791 /* Activity options */
792 #define AO_NULL                 0x00
793 /*
794  * Indicate that corresponding activity should be collected by sadc.
795  */
796 #define AO_COLLECTED            0x01
797 /*
798  * Indicate that corresponding activity should be displayed by sar.
799  */
800 #define AO_SELECTED             0x02
801 /*
802  * Indicate that corresponding activity has items that need to be counted.
803  * This means that its @f_count_index values is >= 0.
804  * (We use AO_COUNTED instead of @f_count_index because @f_count_index
805  * is available (initialized) only for sadc).
806  */
807 #define AO_COUNTED              0x04
808 /*
809  * Indicate that activity's metrics have persistent values when devices
810  * are registered again (this means that when the device is registered again,
811  * the metrics pick the values they had when they had been unregistered).
812  * Exclusively used for CPU related statistics at the present time
813  * (e.g. A_CPU and A_NET_SOFT).
814  */
815 #define AO_PERSISTENT           0x08
816 /*
817  * This flag should be set for every activity closing a markup used
818  * by several activities. Used by sadf f_xml_print() functions to
819  * display XML output, and also by f_json_print() functions to display JSON output.
820  */
821 #define AO_CLOSE_MARKUP         0x10
822 /*
823  * Indicate that corresponding activity has multiple different
824  * output formats. This is the case for example for memory activity
825  * with options -r and -R.
826  * PS: Such an activity should appear in the list of activities that
827  * sar -A is supposed to display.
828  */
829 #define AO_MULTIPLE_OUTPUTS     0x20
830 /*
831  * Indicate that one (SVG) graph will be displayed for each
832  * distinct item for this activity (sadf -g).
833  */
834 #define AO_GRAPH_PER_ITEM       0x40
835 /*
836  * Indicate that this activity may have sub-items.
837  */
838 #define AO_MATRIX               0x80
839 /*
840  * Indicate that a list of devices has been entered on the command
841  * line for this activity (see options --dev=, --iface=, ...)
842  */
843 #define AO_LIST_ON_CMDLINE      0x100
844 /*
845  * Indicate that the number of items for this activity should always
846  * be counted, even if the activity is not collected.
847  */
848 #define AO_ALWAYS_COUNTED       0x200
849 /*
850  * Indicate that corresponding activity should be collected only
851  * if a test has been successfully passed before.
852  * The test corresponds to the count() function (see @f_count_index).
853  * This is intended for activities with a fixed number of items but
854  * whose {/proc|/sys} files are not necessarily available, e.g. depending
855  * on the kernel version used. Unlike activities with AO_COUNTED flag,
856  * those having AO_DETECTED flag won't have a @has_nr number preceding
857  * their statistics structures in datafile.
858  */
859 #define AO_DETECTED             0x400
860
861 #define IS_COLLECTED(m)         (((m) & AO_COLLECTED)        == AO_COLLECTED)
862 #define IS_SELECTED(m)          (((m) & AO_SELECTED)         == AO_SELECTED)
863 #define HAS_COUNT_FUNCTION(m)   (((m) & AO_COUNTED)          == AO_COUNTED)
864 #define HAS_DETECT_FUNCTION(m)  (((m) & AO_DETECTED)         == AO_DETECTED)
865 #define HAS_PERSISTENT_VALUES(m) (((m) & AO_PERSISTENT)      == AO_PERSISTENT)
866 #define CLOSE_MARKUP(m)         (((m) & AO_CLOSE_MARKUP)     == AO_CLOSE_MARKUP)
867 #define HAS_MULTIPLE_OUTPUTS(m) (((m) & AO_MULTIPLE_OUTPUTS) == AO_MULTIPLE_OUTPUTS)
868 #define ONE_GRAPH_PER_ITEM(m)   (((m) & AO_GRAPH_PER_ITEM)   == AO_GRAPH_PER_ITEM)
869 #define IS_MATRIX(m)            (((m) & AO_MATRIX)           == AO_MATRIX)
870 #define HAS_LIST_ON_CMDLINE(m)  (((m) & AO_LIST_ON_CMDLINE)  == AO_LIST_ON_CMDLINE)
871 #define ALWAYS_COUNT_ITEMS(m)   (((m) & AO_ALWAYS_COUNTED)   == AO_ALWAYS_COUNTED)
872
873 #define _buf0   buf[0]
874 #define _nr0    nr[0]
875
876 /* Structure used to define a bitmap needed by an activity */
877 struct act_bitmap {
878         /*
879          * Bitmap for activities that need one. Remember to allocate it
880          * before use!
881          */
882         unsigned char *b_array;
883         /*
884          * Size of the bitmap in bits. In fact, bitmap is sized to b_size + 1
885          * to take into account CPU "all"
886          */
887         int b_size;
888 };
889
890 /*
891  * Structure used to define an activity.
892  * Note: This structure can be modified without changing the format of data files.
893  */
894 struct activity {
895         /*
896          * This variable contains the identification value (A_...) for this activity.
897          */
898         unsigned int id;
899         /*
900          * Activity options (AO_...)
901          */
902         unsigned int options;
903         /*
904          * Activity magical number. This number changes when activity format in file
905          * is no longer compatible with the format of that same activity from
906          * previous versions.
907          */
908         unsigned int magic;
909         /*
910          * An activity belongs to a group (and only one).
911          * Groups are those selected with option -S of sadc.
912          */
913         unsigned int group;
914         /*
915          * Index in f_count[] array to determine function used to count
916          * the number of items (serial lines, network interfaces, etc.) for
917          * activities with AO_COUNTED flag. Determine @nr value.
918          * Such a function should _always_ return a value greater than
919          * or equal to 0.
920          *
921          * A value of -1 indicates that the number of items
922          * is a constant (and @nr_ini is set to this value).
923          *
924          * This function may be called even if corresponding activity has not
925          * been selected if flag AO_ALWAYS_COUNTED is set, to make sure that
926          * all items have been calculated (e.g. #CPU)
927          *
928          * The count() function may also be used to know if an activity (with
929          * AO_DETECTED flag) can actually be collected based on the presence of
930          * {/proc|/sys} files.
931          */
932         int f_count_index;
933         /*
934          * Index in f_count[] array to determine function used to count the
935          * number of sub-items -> @nr2
936          * Such a function should _always_ return a value greater than
937          * or equal to 0.
938          *
939          * A value of -1 indicates that the number of items is a constant
940          * (and @nr2 is set to this value).
941          */
942         int f_count2_index;
943         /*
944          * This function reads the relevant file and fill the buffer
945          * with statistics corresponding to given activity.
946          */
947         __read_funct_t (*f_read) (struct activity *);
948         /*
949          * This function displays activity statistics onto the screen.
950          */
951         __print_funct_t (*f_print) (struct activity *, int, int, unsigned long long);
952         /*
953          * This function displays average activity statistics onto the screen.
954          */
955         __print_funct_t (*f_print_avg) (struct activity *, int, int, unsigned long long);
956         /*
957          * This function is used by sadf to display activity in a format that can
958          * easily be ingested by a relational database, or a format that can be
959          * handled by pattern processing commands like "awk".
960          */
961         __print_funct_t (*f_render) (struct activity *, int, char *, int, unsigned long long);
962         /*
963          * This function is used by sadf to display activity statistics in XML.
964          */
965         __print_funct_t (*f_xml_print) (struct activity *, int, int, unsigned long long);
966         /*
967          * This function is used by sadf to display activity statistics in JSON.
968          */
969         __print_funct_t (*f_json_print) (struct activity *, int, int, unsigned long long);
970         /*
971          * This function is used by sadf to display activity statistics in SVG.
972          */
973         __print_funct_t (*f_svg_print) (struct activity *, int, int, struct svg_parm *,
974                                         unsigned long long, struct record_header *);
975         /*
976          * This function is used by sadf to display activity statistics in raw format.
977          */
978         __print_funct_t (*f_raw_print) (struct activity *, char *, int);
979         /*
980          * This function is used by sadf to display activity statistics in PCP format.
981          */
982         __print_funct_t (*f_pcp_print) (struct activity *, int);
983         /*
984          * This function is used by sadf to count the number of new items in current
985          * sample and add them to the linked list @item_list.
986          */
987         __nr_t (*f_count_new) (struct activity *, int);
988         /*
989          * Linked list containing item names. This is either all the different items
990          * found in a file for activities that have a @f_count_new() function (used by sadf),
991          * or a list entered on the command line (used by sadf and sar).
992          */
993         struct sa_item *item_list;
994         /*
995          * Number of different items found in file (calculated by sadf).
996          * This is also the number of items in @item_list if this list exists.
997          */
998         __nr_t item_list_sz;
999         /*
1000          * Header string displayed by sadf -d.
1001          * Header lines for each output (for activities with multiple outputs) are
1002          * separated with a '|' character.
1003          * For a given output, the first field corresponding to extended statistics
1004          * (eg. -r ALL) begins with a '&' character.
1005          */
1006         char *hdr_line;
1007         /*
1008          * Description of activity.
1009          */
1010         char *desc;
1011         /*
1012          * Name of activity.
1013          */
1014         char *name;
1015         /*
1016          * Description of the corresponding structure containing statistics (as defined
1017          * in rd_stats.h or rd_sensors.h). Such a structure has 0+ fields of type
1018          * "long long", followed by 0+ fields of type "long", followed by 0+ fields of
1019          * type "int", followed by 0+ other fields (e.g. of type char). The array below
1020          * gives the number of "long long" fields composing the structure, then the number
1021          * of "long" fields, then the number of "int" fields.
1022          */
1023         unsigned int gtypes_nr[3];
1024         /*
1025          * This array has the same meaning as @gtypes_nr[] above, but the values are those
1026          * read from current data file. They may be different from those of @gtypes_nr[]
1027          * because we can read data from a different sysstat version (older or newer).
1028          */
1029         unsigned int ftypes_nr[3];
1030         /*
1031          * Number of SVG graphs for this activity. The total number of graphs for
1032          * the activity can be greater though if flag AO_GRAPH_PER_ITEM is set, in
1033          * which case the total number will  be @g_nr * @nr.
1034          */
1035         int g_nr;
1036         /*
1037          * Number of items on the system, as counted when the system is initialized.
1038          * A negative value (-1) is the default value and indicates that this number
1039          * has still not been calculated by the function whose index is in @f_count_index.
1040          * A value of 0 means that this number has been calculated, but no items have
1041          * been found.
1042          * A positive value (>0) has either been calculated or is a constant.
1043          */
1044         __nr_t nr_ini;
1045         /*
1046          * Number of sub-items on the system.
1047          * @nr2 is in fact the second dimension of a matrix of items, the first
1048          * one being @nr. @nr is the number of lines, and @nr2 the number of columns.
1049          * A negative value (-1) is the default value and indicates that this number
1050          * has still not been calculated by the f_count2() function.
1051          * A value of 0 means that this number has been calculated, but no sub-items have
1052          * been found.
1053          * A positive value (>0) has either been calculated or is a constant.
1054          * Rules:
1055          * 1) IF @nr2 = 0 THEN @nr_ini = 0
1056          *    Note: If @nr_ini = 0, then @nr2 is undetermined (may be -1, 0 or >0).
1057          * 2) IF @nr_ini > 0 THEN @nr2 > 0.
1058          *    Note: If @nr2 > 0 then @nr_ini is undetermined (may be -1, 0 or >0).
1059          * 3) IF @nr_ini <= 0 THEN @nr2 = -1 (this is the default value for @nr2,
1060          * meaning that it has not been calculated).
1061          */
1062         __nr_t nr2;
1063         /*
1064          * Maximum number of elements that sar can handle for this item.
1065          * NB: The maximum number of elements that sar can handle for sub-items
1066          * is NR2_MAX.
1067          */
1068         __nr_t nr_max;
1069         /*
1070          * Number of items, as read and saved in corresponding buffer (@buf: See below).
1071          * The value may be zero for a particular sample if no items have been found.
1072          */
1073         __nr_t nr[3];
1074         /*
1075          * Number of structures allocated in @buf[*]. This number should be greater
1076          * than or equal to @nr[*].
1077          */
1078         __nr_t nr_allocated;
1079         /*
1080          * Size of an item.
1081          * This is the size of the corresponding structure, as read from or written
1082          * to a file, or read from or written by the data collector.
1083          */
1084         int fsize;
1085         /*
1086          * Size of an item.
1087          * This is the size of the corresponding structure as mapped into memory.
1088          * @msize can be different from @fsize when data are read from or written to
1089          * a data file from a different sysstat version.
1090          */
1091         int msize;
1092         /*
1093          * Optional flags for activity. This is eg. used when AO_MULTIPLE_OUTPUTS
1094          * option is set.
1095          * 0x0001 - 0x0080 : Multiple outputs (eg. AO_F_MEMORY, AO_F_SWAP...)
1096          * 0x0100 - 0x8000 : If bit set then display complete header (@hdr_line) for
1097          *                   corresponding output
1098          * 0x010000+       : Optional flags
1099          */
1100         unsigned int opt_flags;
1101         /*
1102          * Buffers that will contain the statistics read. Its size is @nr * @nr2 * @size each.
1103          * [0]: used by sadc.
1104          * [0] and [1]: current/previous statistics values (used by sar).
1105          * [2]: Used by sar to save first collected stats (used later to
1106          * compute average).
1107          */
1108         void *buf[3];
1109         /*
1110          * Bitmap for activities that need one. Such a bitmap is needed by activity
1111          * if @bitmap is not NULL.
1112          */
1113         struct act_bitmap *bitmap;
1114 };
1115
1116
1117 /*
1118  ***************************************************************************
1119  * Generic description of an output format for sadf (and sar).
1120  ***************************************************************************
1121  */
1122
1123 /* Type for all functions used by sadf to display stats in various formats */
1124 #define __printf_funct_t void
1125 #define __tm_funct_t char *
1126
1127 /*
1128  * Structure used to define a report.
1129  * A XML-like report has the following format:
1130  *       __
1131  *      |
1132  *      | Header block
1133  *      |  __
1134  *      | |
1135  *      | | Statistics block
1136  *      | |  __
1137  *      | | |
1138  *      | | | Timestamp block
1139  *      | | |  __
1140  *      | | | |
1141  *      | | | | Activity #1
1142  *      | | | |__
1143  *      | | | |
1144  *      | | | | ...
1145  *      | | | |__
1146  *      | | | |
1147  *      | | | | Activity #n
1148  *      | | | |__
1149  *      | | |__
1150  *      | |__
1151  *      | |
1152  *      | | Restart messages block
1153  *      | |__
1154  *      | |
1155  *      | | Comments block
1156  *      | |__
1157  *      |__
1158  */
1159 struct report_format {
1160         /*
1161          * This variable contains the identification value (F_...) for this report format.
1162          */
1163         unsigned int id;
1164         /*
1165          * Format options (FO_...).
1166          */
1167         unsigned int options;
1168         /*
1169          * This function displays the report header
1170          * (data displayed once at the beginning of the report).
1171          */
1172         __printf_funct_t (*f_header) (void *, int, char *, struct file_magic *, struct file_header *,
1173                                       struct activity * [], unsigned int [], struct file_activity *);
1174         /*
1175          * This function defines the statistics part of the report.
1176          * Used only with textual (XML-like) reports and PCP archives.
1177          */
1178         __printf_funct_t (*f_statistics) (int *, int, struct activity * [], unsigned int []);
1179         /*
1180          * This function defines the timestamp part of the report.
1181          * Used only with textual (XML-like) reports, PCP archives and RAW output format.
1182          */
1183         __tm_funct_t (*f_timestamp) (void *, int, char *, char *, unsigned long long,
1184                                      struct record_header *, struct file_header *, unsigned int);
1185         /*
1186          * This function displays the restart messages.
1187          */
1188         __printf_funct_t (*f_restart) (int *, int, char *, char *, int,
1189                                        struct file_header *, struct record_header *);
1190         /*
1191          * This function displays the comments.
1192          */
1193         __printf_funct_t (*f_comment) (int *, int, char *, char *, int, char *,
1194                                        struct file_header *, struct record_header *);
1195         /*
1196          * This is the main function used to display all the statistics for current format.
1197          */
1198         void (*f_display) (int, char *, struct file_activity *, struct file_magic *,
1199                            struct tm *, void *);
1200 };
1201
1202
1203 /* Possible actions for functions used to display reports */
1204 #define F_BEGIN 0x01
1205 #define F_MAIN  0x02
1206 #define F_END   0x04
1207
1208 /*
1209  ***************************************************************************
1210  * SVG output definitions
1211  ***************************************************************************
1212  */
1213
1214 /*
1215  *   ^
1216  * 1 | General header
1217  *   v
1218  *   ^
1219  * 9 | One line from table of contents (if any)
1220  *   v
1221  *   ^   ^   ^
1222  *   |   | 4 | Graph title
1223  *   |   |   v
1224  *   |   |   ^    |                                Caption
1225  *   | 3 |   |    |
1226  *   |   |   |  G |Y
1227  * 2 |   | 5 |  r |
1228  *   |   |   |  a |A
1229  *   |   |   |  d |x
1230  *   |   |   |  . |i
1231  *   |   |   |    |s          X Axis
1232  *   |   |   v    |-------------------------------
1233  *   |   |              Grad.
1234  *   |   v   <---><------------------------------>
1235  *   |         6                8
1236  *   | Gap
1237  *   v<---------------------------------------------------------------> Gap
1238  *                                    7
1239  *    <--------------------------------------------------------------------->
1240  *                                      8
1241  */
1242
1243 /* #8 */
1244 #define SVG_G_XSIZE     720
1245 /* #6 */
1246 #define SVG_M_XSIZE     70
1247 /* #7 */
1248 #define SVG_V_XSIZE     1050
1249 /* #8 */
1250 #define SVG_T_XSIZE     1060
1251
1252 /* #5 */
1253 #define SVG_G_YSIZE     200
1254 /* #1 */
1255 #define SVG_H_YSIZE     60
1256 /* #4 */
1257 #define SVG_M_YSIZE     50
1258 /* #2 */
1259 #define SVG_T_YSIZE     310
1260 /* #3 */
1261 #define SVG_V_YSIZE     300
1262 /* #9 */
1263 #define SVG_C_YSIZE     20
1264
1265 /* Grid: Nr of horizontal lines */
1266 #define SVG_H_GRIDNR    3
1267 /* Grid: Nr of vertical lines */
1268 #define SVG_V_GRIDNR    10
1269
1270 /* Block size used to allocate arrays for graphs data */
1271 #define CHUNKSIZE       4096
1272
1273 /* Maximum number of views on a single row */
1274 #define MAX_VIEWS_ON_A_ROW      6
1275
1276 #define SVG_LINE_GRAPH  1
1277 #define SVG_BAR_GRAPH   2
1278
1279 /* Maximum number of horizontal lines for the background grid */
1280 #define MAX_HLINES_NR   10
1281
1282 /* Color palette constants */
1283 #define SVG_COLORS_IDX_MASK     0x0f
1284 #define SVG_COL_PALETTE_SIZE    24
1285 #define SVG_COL_PALETTE_NR      3
1286 #define SVG_COL_BCKGRD_IDX      16
1287 #define SVG_COL_AXIS_IDX        17
1288 #define SVG_COL_GRID_IDX        18
1289 #define SVG_COL_TITLE_IDX       19
1290 #define SVG_COL_INFO_IDX        20
1291 #define SVG_COL_DEFAULT_IDX     21
1292 #define SVG_COL_HEADER_IDX      22
1293 #define SVG_COL_ERROR_IDX       23
1294
1295 #define SVG_DEFAULT_COL_PALETTE 0
1296 #define SVG_CUSTOM_COL_PALETTE  1
1297 #define SVG_BW_COL_PALETTE      2
1298
1299 #define MAYBE   0x80
1300
1301 /*
1302  ***************************************************************************
1303  * Macro functions definitions.
1304  *
1305  * Note: Using 'do ... while' makes the macros safer to use
1306  * (remember that macro use is followed by a semicolon).
1307  ***************************************************************************
1308  */
1309
1310 /* Close file descriptors */
1311 #define CLOSE_ALL(_fd_)         do {                    \
1312                                         close(_fd_[0]); \
1313                                         close(_fd_[1]); \
1314                                 } while (0)
1315
1316 #define CLOSE(_fd_)             if (_fd_ >= 0)          \
1317                                         close(_fd_)
1318
1319
1320 /*
1321  ***************************************************************************
1322  * Various structure definitions.
1323  ***************************************************************************
1324  */
1325
1326 /* Structure for timestamps */
1327 struct tstamp {
1328         int tm_sec;
1329         int tm_min;
1330         int tm_hour;
1331         int use;
1332 };
1333
1334 /* Structure for items in list */
1335 struct sa_item {
1336         char *item_name;
1337         struct sa_item *next;
1338 };
1339
1340
1341 /*
1342  ***************************************************************************
1343  * Functions prototypes.
1344  ***************************************************************************
1345  */
1346
1347 /*
1348  * Prototypes used to count new items
1349  */
1350 __nr_t count_new_net_dev
1351         (struct activity *, int);
1352 __nr_t count_new_net_edev
1353         (struct activity *, int);
1354 __nr_t count_new_filesystem
1355         (struct activity *, int);
1356 __nr_t count_new_fchost
1357         (struct activity *, int);
1358 __nr_t count_new_disk
1359         (struct activity *, int);
1360
1361 /* Functions used to count number of items */
1362 __nr_t wrap_get_cpu_nr
1363         (struct activity *);
1364 __nr_t wrap_get_irq_nr
1365         (struct activity *);
1366 __nr_t wrap_get_serial_nr
1367         (struct activity *);
1368 __nr_t wrap_get_disk_nr
1369         (struct activity *);
1370 __nr_t wrap_get_iface_nr
1371         (struct activity *);
1372 __nr_t wrap_get_fan_nr
1373         (struct activity *);
1374 __nr_t wrap_get_temp_nr
1375         (struct activity *);
1376 __nr_t wrap_get_in_nr
1377         (struct activity *);
1378 __nr_t wrap_get_freq_nr
1379         (struct activity *);
1380 __nr_t wrap_get_usb_nr
1381         (struct activity *);
1382 __nr_t wrap_get_filesystem_nr
1383         (struct activity *);
1384 __nr_t wrap_get_fchost_nr
1385         (struct activity *);
1386 __nr_t wrap_detect_psi
1387         (struct activity *);
1388
1389 /* Functions used to read activities statistics */
1390 __read_funct_t wrap_read_stat_cpu
1391         (struct activity *);
1392 __read_funct_t wrap_read_stat_pcsw
1393         (struct activity *);
1394 __read_funct_t wrap_read_stat_irq
1395         (struct activity *);
1396 __read_funct_t wrap_read_swap
1397         (struct activity *);
1398 __read_funct_t wrap_read_paging
1399         (struct activity *);
1400 __read_funct_t wrap_read_io
1401         (struct activity *);
1402 __read_funct_t wrap_read_meminfo
1403         (struct activity *);
1404 __read_funct_t wrap_read_kernel_tables
1405         (struct activity *);
1406 __read_funct_t wrap_read_loadavg
1407         (struct activity *);
1408 __read_funct_t wrap_read_tty_driver_serial
1409         (struct activity *);
1410 __read_funct_t wrap_read_disk
1411         (struct activity *);
1412 __read_funct_t wrap_read_net_dev
1413         (struct activity *);
1414 __read_funct_t wrap_read_net_edev
1415         (struct activity *);
1416 __read_funct_t wrap_read_net_nfs
1417         (struct activity *);
1418 __read_funct_t wrap_read_net_nfsd
1419         (struct activity *);
1420 __read_funct_t wrap_read_net_sock
1421         (struct activity *);
1422 __read_funct_t wrap_read_net_ip
1423         (struct activity *);
1424 __read_funct_t wrap_read_net_eip
1425         (struct activity *);
1426 __read_funct_t wrap_read_net_icmp
1427         (struct activity *);
1428 __read_funct_t wrap_read_net_eicmp
1429         (struct activity *);
1430 __read_funct_t wrap_read_net_tcp
1431         (struct activity *);
1432 __read_funct_t wrap_read_net_etcp
1433         (struct activity *);
1434 __read_funct_t wrap_read_net_udp
1435         (struct activity *);
1436 __read_funct_t wrap_read_net_sock6
1437         (struct activity *);
1438 __read_funct_t wrap_read_net_ip6
1439         (struct activity *);
1440 __read_funct_t wrap_read_net_eip6
1441         (struct activity *);
1442 __read_funct_t wrap_read_net_icmp6
1443         (struct activity *);
1444 __read_funct_t wrap_read_net_eicmp6
1445         (struct activity *);
1446 __read_funct_t wrap_read_net_udp6
1447         (struct activity *);
1448 __read_funct_t wrap_read_cpuinfo
1449         (struct activity *);
1450 __read_funct_t wrap_read_fan
1451         (struct activity *);
1452 __read_funct_t wrap_read_temp
1453         (struct activity *);
1454 __read_funct_t wrap_read_in
1455         (struct activity *);
1456 __read_funct_t wrap_read_meminfo_huge
1457         (struct activity *);
1458 __read_funct_t wrap_read_cpu_wghfreq
1459         (struct activity *);
1460 __read_funct_t wrap_read_bus_usb_dev
1461         (struct activity *);
1462 __read_funct_t wrap_read_filesystem
1463         (struct activity *);
1464 __read_funct_t wrap_read_fchost
1465         (struct activity *);
1466 __read_funct_t wrap_read_softnet
1467         (struct activity *);
1468 __read_funct_t wrap_read_psicpu
1469         (struct activity *);
1470 __read_funct_t wrap_read_psiio
1471         (struct activity *);
1472 __read_funct_t wrap_read_psimem
1473         (struct activity *);
1474
1475 /* Other functions */
1476 int check_alt_sa_dir
1477         (char *, int, int);
1478 void enum_version_nr
1479         (struct file_magic *);
1480 int get_activity_nr
1481         (struct activity * [], unsigned int, int);
1482 int get_activity_position
1483         (struct activity * [], unsigned int, int);
1484 void handle_invalid_sa_file
1485         (int, struct file_magic *, char *, int);
1486 void print_collect_error
1487         (void);
1488 void set_default_file
1489         (char *, int, int);
1490 int skip_extra_struct
1491         (int, int, int);
1492 int write_all
1493         (int, const void *, int);
1494
1495 #ifndef SOURCE_SADC
1496 int add_list_item
1497         (struct sa_item **, char *, int);
1498 void allocate_bitmaps
1499         (struct activity * []);
1500 void allocate_structures
1501         (struct activity * []);
1502 int check_disk_reg
1503         (struct activity *, int, int, int);
1504 void check_file_actlst
1505         (int *, char *, struct activity * [], uint64_t, struct file_magic *,
1506          struct file_header *, struct file_activity **, unsigned int [], int *, int *);
1507 int check_net_dev_reg
1508         (struct activity *, int, int, int);
1509 int check_net_edev_reg
1510         (struct activity *, int, int, int);
1511 double compute_ifutil
1512         (struct stats_net_dev *, double, double);
1513 void copy_structures
1514         (struct activity * [], unsigned int [], struct record_header [], int, int);
1515 int datecmp
1516         (struct tm *, struct tstamp *, int);
1517 void display_sa_file_version
1518         (FILE *, struct file_magic *);
1519 void free_bitmaps
1520         (struct activity * []);
1521 void free_structures
1522         (struct activity * []);
1523 char *get_devname
1524         (unsigned int, unsigned int);
1525 char *get_sa_devname
1526         (unsigned int, unsigned int, unsigned long long [], unsigned int, uint64_t);
1527 void get_file_timestamp_struct
1528         (uint64_t, struct tm *, struct file_header *);
1529 char *get_fs_name_to_display
1530         (struct activity *, uint64_t, struct stats_filesystem *);
1531 unsigned long long get_global_cpu_statistics
1532         (struct activity *, int, int, uint64_t, unsigned char []);
1533 void get_global_soft_statistics
1534         (struct activity *, int, int, uint64_t, unsigned char []);
1535 void get_itv_value
1536         (struct record_header *, struct record_header *, unsigned long long *);
1537 void init_custom_color_palette
1538         (void);
1539 int next_slice
1540         (unsigned long long, unsigned long long, int, long);
1541 void parse_sa_devices
1542         (char *, struct activity *, int, int *, int);
1543 int parse_sar_opt
1544         (char * [], int *, struct activity * [], uint64_t *, int);
1545 int parse_sar_I_opt
1546         (char * [], int *, uint64_t *, struct activity * []);
1547 int parse_sa_P_opt
1548         (char * [], int *, uint64_t *, struct activity * []);
1549 int parse_sar_m_opt
1550         (char * [], int *, struct activity * []);
1551 int parse_sar_n_opt
1552         (char * [], int *, struct activity * []);
1553 int parse_sar_q_opt
1554         (char * [], int *, struct activity * []);
1555 int parse_timestamp
1556         (char * [], int *, struct tstamp *, const char *);
1557 void print_report_hdr
1558         (uint64_t, struct tm *, struct file_header *);
1559 void print_sar_comment
1560         (int *, int, char *, char *, int, char *, struct file_header *,
1561          struct record_header *);
1562 __printf_funct_t print_sar_restart
1563         (int *, int, char *, char *, int, struct file_header *, struct record_header *);
1564 int print_special_record
1565         (struct record_header *, uint64_t, struct tstamp *, struct tstamp *,
1566          int, int, struct tm *, char *, int, struct file_magic *,
1567          struct file_header *, struct activity * [], struct report_format *, int, int);
1568 int read_file_stat_bunch
1569         (struct activity * [], int, int, int, struct file_activity *, int, int,
1570          char *, struct file_magic *, int);
1571 __nr_t read_nr_value
1572         (int, char *, struct file_magic *, int, int, int);
1573 int read_record_hdr
1574         (int, void *, struct record_header *, struct file_header *, int, int,
1575          int, size_t, uint64_t, struct report_format *);
1576 void reallocate_all_buffers
1577         (struct activity *, __nr_t);
1578 void replace_nonprintable_char
1579         (int, char *);
1580 int sa_fread
1581         (int, void *, size_t, int, int);
1582 int sa_get_record_timestamp_struct
1583         (uint64_t, struct record_header *, struct tm *);
1584 int sa_open_read_magic
1585         (int *, char *, struct file_magic *, int, int *, int);
1586 int search_list_item
1587         (struct sa_item *, char *);
1588 void select_all_activities
1589         (struct activity * []);
1590 void select_default_activity
1591         (struct activity * []);
1592 void set_bitmaps
1593         (struct activity * [], uint64_t *);
1594 void set_hdr_rectime
1595         (unsigned int, struct tm *, struct file_header *);
1596 void set_record_timestamp_string
1597         (uint64_t, struct record_header *, char *, char *, int, struct tm *);
1598 void swap_struct
1599         (unsigned int [], void *, int);
1600 #endif /* SOURCE_SADC undefined */
1601 #endif  /* _SA_H */