]> granicus.if.org Git - sysstat/blob - sa.h
NLS: Sync with translation project
[sysstat] / sa.h
1 /*
2  * sar/sadc: Report system activity
3  * (C) 1999-2016 by Sebastien Godard (sysstat <at> orange.fr)
4  */
5
6 #ifndef _SA_H
7 #define _SA_H
8
9 #include <stdio.h>
10
11 #include "common.h"
12 #include "prealloc.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          38
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      11
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_CPUFREQ   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_WGHFREQ   35
66 #define A_PWR_USB       36
67 #define A_FILESYSTEM    37
68 #define A_NET_FC        38
69
70
71 /* Macro used to flag an activity that should be collected */
72 #define COLLECT_ACTIVITY(m)     act[get_activity_position(act, m, EXIT_IF_NOT_FOUND)]->options |= AO_COLLECTED
73
74 /* Macro used to flag an activity that should be selected */
75 #define SELECT_ACTIVITY(m)      act[get_activity_position(act, m, EXIT_IF_NOT_FOUND)]->options |= AO_SELECTED
76
77
78 /*
79  ***************************************************************************
80  * Flags.
81  ***************************************************************************
82  */
83
84 #define S_F_SINCE_BOOT          0x00000001
85 #define S_F_SA_ROTAT            0x00000002
86 #define S_F_DEV_PRETTY          0x00000004
87 #define S_F_FORCE_FILE          0x00000008
88 #define S_F_INTERVAL_SET        0x00000010
89 #define S_F_TRUE_TIME           0x00000020
90 #define S_F_LOCK_FILE           0x00000040
91 #define S_F_SEC_EPOCH           0x00000080
92 #define S_F_HDR_ONLY            0x00000100
93 #define S_F_FILE_LOCKED         0x00000200
94 #define S_F_SA_YYYYMMDD         0x00000400
95 #define S_F_HORIZONTALLY        0x00000800
96 #define S_F_COMMENT             0x00001000
97 #define S_F_PERSIST_NAME        0x00002000
98 #define S_F_LOCAL_TIME          0x00004000
99 #define S_F_PREFD_TIME_OUTPUT   0x00008000
100 #define S_F_SVG_SKIP            0x00010000
101 #define S_F_SVG_AUTOSCALE       0x00020000
102
103 #define WANT_SINCE_BOOT(m)              (((m) & S_F_SINCE_BOOT)   == S_F_SINCE_BOOT)
104 #define WANT_SA_ROTAT(m)                (((m) & S_F_SA_ROTAT)     == S_F_SA_ROTAT)
105 #define USE_PRETTY_OPTION(m)            (((m) & S_F_DEV_PRETTY)   == S_F_DEV_PRETTY)
106 #define FORCE_FILE(m)                   (((m) & S_F_FORCE_FILE)   == S_F_FORCE_FILE)
107 #define INTERVAL_SET(m)                 (((m) & S_F_INTERVAL_SET) == S_F_INTERVAL_SET)
108 #define PRINT_TRUE_TIME(m)              (((m) & S_F_TRUE_TIME)    == S_F_TRUE_TIME)
109 #define LOCK_FILE(m)                    (((m) & S_F_LOCK_FILE)    == S_F_LOCK_FILE)
110 #define PRINT_SEC_EPOCH(m)              (((m) & S_F_SEC_EPOCH)    == S_F_SEC_EPOCH)
111 #define DISPLAY_HDR_ONLY(m)             (((m) & S_F_HDR_ONLY)     == S_F_HDR_ONLY)
112 #define FILE_LOCKED(m)                  (((m) & S_F_FILE_LOCKED)  == S_F_FILE_LOCKED)
113 #define USE_SA_YYYYMMDD(m)              (((m) & S_F_SA_YYYYMMDD)  == S_F_SA_YYYYMMDD)
114 #define DISPLAY_HORIZONTALLY(m)         (((m) & S_F_HORIZONTALLY) == S_F_HORIZONTALLY)
115 #define DISPLAY_COMMENT(m)              (((m) & S_F_COMMENT)      == S_F_COMMENT)
116 #define DISPLAY_PERSIST_NAME_S(m)       (((m) & S_F_PERSIST_NAME) == S_F_PERSIST_NAME)
117 #define PRINT_LOCAL_TIME(m)             (((m) & S_F_LOCAL_TIME)   == S_F_LOCAL_TIME)
118 #define USE_PREFD_TIME_OUTPUT(m)        (((m) & S_F_PREFD_TIME_OUTPUT)   == S_F_PREFD_TIME_OUTPUT)
119 #define SKIP_EMPTY_VIEWS(m)             (((m) & S_F_SVG_SKIP)     == S_F_SVG_SKIP)
120 #define AUTOSCALE_ON(m)                 (((m) & S_F_SVG_AUTOSCALE) == S_F_SVG_AUTOSCALE)
121
122 #define AO_F_NULL               0x00000000
123
124 /* Output flags for options -R / -r / -S */
125 #define AO_F_MEM_DIA            0x00000001
126 #define AO_F_MEM_AMT            0x00000002
127 #define AO_F_MEM_SWAP           0x00000004
128 /* AO_F_MEM_ALL: See opt_flags in struct activity below */
129 #define AO_F_MEM_ALL            (AO_F_MEM_AMT << 8)
130
131 #define DISPLAY_MEMORY(m)       (((m) & AO_F_MEM_DIA)     == AO_F_MEM_DIA)
132 #define DISPLAY_MEM_AMT(m)      (((m) & AO_F_MEM_AMT)     == AO_F_MEM_AMT)
133 #define DISPLAY_SWAP(m)         (((m) & AO_F_MEM_SWAP)    == AO_F_MEM_SWAP)
134 #define DISPLAY_MEM_ALL(m)      (((m) & AO_F_MEM_ALL)     == AO_F_MEM_ALL)
135
136 /* Output flags for option -u [ ALL ] */
137 #define AO_F_CPU_DEF            0x00000001
138 #define AO_F_CPU_ALL            0x00000002
139
140 #define DISPLAY_CPU_DEF(m)      (((m) & AO_F_CPU_DEF)     == AO_F_CPU_DEF)
141 #define DISPLAY_CPU_ALL(m)      (((m) & AO_F_CPU_ALL)     == AO_F_CPU_ALL)
142
143 /* Output flags for option -d */
144 #define AO_F_DISK_PART          0x00000001
145
146 #define COLLECT_PARTITIONS(m)   (((m) & AO_F_DISK_PART)   == AO_F_DISK_PART)
147
148 /* Output flags for option -F */
149 #define AO_F_MOUNT              0x00000001
150
151 #define DISPLAY_MOUNT(m)        (((m) & AO_F_MOUNT)       == AO_F_MOUNT)
152
153 /*
154  ***************************************************************************
155  * Various keywords and constants.
156  ***************************************************************************
157  */
158
159 /* Keywords */
160 #define K_XALL          "XALL"
161 #define K_SUM           "SUM"
162 #define K_DEV           "DEV"
163 #define K_EDEV          "EDEV"
164 #define K_NFS           "NFS"
165 #define K_NFSD          "NFSD"
166 #define K_SOCK          "SOCK"
167 #define K_IP            "IP"
168 #define K_EIP           "EIP"
169 #define K_ICMP          "ICMP"
170 #define K_EICMP         "EICMP"
171 #define K_TCP           "TCP"
172 #define K_ETCP          "ETCP"
173 #define K_UDP           "UDP"
174 #define K_SOCK6         "SOCK6"
175 #define K_IP6           "IP6"
176 #define K_EIP6          "EIP6"
177 #define K_ICMP6         "ICMP6"
178 #define K_EICMP6        "EICMP6"
179 #define K_UDP6          "UDP6"
180 #define K_CPU           "CPU"
181 #define K_FAN           "FAN"
182 #define K_TEMP          "TEMP"
183 #define K_IN            "IN"
184 #define K_FREQ          "FREQ"
185 #define K_MOUNT         "MOUNT"
186 #define K_FC            "FC"
187
188 #define K_INT           "INT"
189 #define K_DISK          "DISK"
190 #define K_XDISK         "XDISK"
191 #define K_SNMP          "SNMP"
192 #define K_IPV6          "IPV6"
193 #define K_POWER         "POWER"
194 #define K_USB           "USB"
195
196 #define K_SKIP_EMPTY    "skipempty"
197 #define K_AUTOSCALE     "autoscale"
198
199 /* Groups of activities */
200 #define G_DEFAULT       0x00
201 #define G_INT           0x01
202 #define G_DISK          0x02
203 #define G_SNMP          0x04
204 #define G_IPV6          0x08
205 #define G_POWER         0x10
206 #define G_XDISK         0x20
207
208 /* sadc program */
209 #define SADC            "sadc"
210
211 /* Time must have the format HH:MM:SS with HH in 24-hour format */
212 #define DEF_TMSTART     "08:00:00"
213 #define DEF_TMEND       "18:00:00"
214
215 /*
216  * Macro used to define activity bitmap size.
217  * All those bitmaps have an additional bit used for global activity
218  * (eg. CPU "all" or total number of interrupts). That's why we do "(m) + 1".
219  */
220 #define BITMAP_SIZE(m)  ((((m) + 1) / 8) + 1)
221
222 #define UTSNAME_LEN     65
223 #define TIMESTAMP_LEN   16
224 #define HEADER_LINE_LEN 512
225
226 /*
227  * Define upper limit for various items.
228  * Made necessary because we have to check the number of
229  * items for each activity when we read a (possibly tainted)
230  * sa data file.
231  */
232 #define MAX_NR_SERIAL_LINES     512
233 #define MAX_NR_DISKS            8192
234 #define MAX_NR_IFACES           512
235 #define MAX_NR_FANS             128
236 #define MAX_NR_TEMP_SENSORS     128
237 #define MAX_NR_IN_SENSORS       128
238 #define MAX_NR_USB              1024
239 #define MAX_NR_FS               8192
240 #define MAX_NR_FCHOSTS          8192
241
242 /* NR_MAX is the upper limit used for unknown activities */
243 #define NR_MAX          65536
244 #define NR2_MAX         128
245
246 /* Maximum number of args that can be passed to sadc */
247 #define MAX_ARGV_NR     32
248
249 /* Miscellaneous constants */
250 #define USE_SADC                0
251 #define USE_SA_FILE             1
252 #define NO_TM_START             0
253 #define NO_TM_END               0
254 #define NO_RESET                0
255 #define NON_FATAL               0
256 #define FATAL                   1
257 #define C_SAR                   0
258 #define C_SADF                  1
259 #define ALL_ACTIVITIES          ~0U
260 #define EXIT_IF_NOT_FOUND       1
261 #define RESUME_IF_NOT_FOUND     0
262
263 #define SOFT_SIZE       0
264 #define HARD_SIZE       1
265
266 #define CLOSE_XML_MARKUP        0
267 #define OPEN_XML_MARKUP         1
268
269 #define CLOSE_JSON_MARKUP       0
270 #define OPEN_JSON_MARKUP        1
271
272 #define COUNT_ACTIVITIES        0
273 #define COUNT_OUTPUTS           1
274
275 /* Type for all functions counting items */
276 #define __nr_t          int
277 /* Type for all functions reading statistics */
278 #define __read_funct_t  void
279 /* Type for all functions displaying statistics */
280 #define __print_funct_t void
281
282 /* Structure for SVG specific parameters */
283 struct svg_parm {
284         unsigned long dt;
285         int graph_no;
286         int restart;
287         struct record_header *record_hdr;
288 };
289
290
291 /*
292  ***************************************************************************
293  * Definitions of header structures.
294  *
295  * Format of system activity data files:
296  *       __
297  *      |
298  *      | file_magic structure
299  *      |
300  *      |--
301  *      |
302  *      | file_header structure
303  *      |
304  *      |--                         --|
305  *      |                             |
306  *      | file_activity structure     | * sa_act_nr
307  *      |                             |
308  *      |--                         --|
309  *      |                             |
310  *      | record_header structure     |
311  *      |                             |
312  *      |--                           | * <count>
313  *      |                             |
314  *      | Statistics structures...(*) |
315  *      |                             |
316  *      |--                         --|
317  *
318  * (*)Note: If it's a special record, we may find a comment instead of
319  * statistics (R_COMMENT record type) or, if it's a R_RESTART record type,
320  * <sa_nr_vol_act> structures (of type file_activity) for the volatile
321  * activities.
322  ***************************************************************************
323  */
324
325 /*
326  * Sysstat magic number. Should never be modified.
327  * Indicate that the file was created by sysstat.
328  */
329 #define SYSSTAT_MAGIC   0xd596
330
331 /*
332  * Datafile format magic number.
333  * Modified to indicate that the format of the file is
334  * no longer compatible with that of previous sysstat versions.
335  */
336 #define FORMAT_MAGIC    0x2173
337
338 /* Previous datafile format magic number used by older sysstat versions */
339 #define PREVIOUS_FORMAT_MAGIC   0x2171
340
341 /* Padding in file_magic structure. See below. */
342 #define FILE_MAGIC_PADDING      63
343
344 /* Structure for file magic header data */
345 struct file_magic {
346         /*
347          * This field identifies the file as a file created by sysstat.
348          */
349         unsigned short sysstat_magic;
350         /*
351          * The value of this field varies whenever datafile format changes.
352          */
353         unsigned short format_magic;
354         /*
355          * Sysstat version used to create the file.
356          */
357         unsigned char sysstat_version;
358         unsigned char sysstat_patchlevel;
359         unsigned char sysstat_sublevel;
360         unsigned char sysstat_extraversion;
361         /*
362          * Size of file's header (size of file_header structure used by file).
363          */
364         unsigned int header_size;
365         /*
366          * Set to non zero if data file has been converted with "sadf -c" from
367          * an old format (version x.y.z) to a newest format (version X.Y.Z).
368          * In this case, the value is: Y*16 + Z + 1.
369          * The FORMAT_MAGIC value of the file can be used to determine X.
370          */
371         unsigned char upgraded;
372         /*
373          * Padding. Reserved for future use while avoiding a format change.
374          */
375         unsigned char pad[FILE_MAGIC_PADDING];
376 };
377
378 #define FILE_MAGIC_SIZE (sizeof(struct file_magic))
379
380
381 /* Header structure for system activity data file */
382 struct file_header {
383         /*
384          * Timestamp in seconds since the epoch.
385          */
386         unsigned long sa_ust_time       __attribute__ ((aligned (8)));
387         /*
388          * Number of CPU items (1 .. CPU_NR + 1) for the last sample in file.
389          */
390         unsigned int sa_last_cpu_nr     __attribute__ ((aligned (8)));
391         /*
392          * Number of activities saved in file.
393          */
394         unsigned int sa_act_nr;
395         /*
396          * Number of volatile activities in file. This is the number of
397          * file_activity structures saved after each restart mark in file.
398          */
399         unsigned int sa_vol_act_nr;
400         /*
401          * Current day, month and year.
402          * No need to save DST (Daylight Saving Time) flag, since it is not taken
403          * into account by the strftime() function used to print the timestamp.
404          */
405         unsigned char sa_day;
406         unsigned char sa_month;
407         unsigned char sa_year;
408         /*
409          * Size of a long integer. Useful to know the architecture on which
410          * the datafile was created.
411          */
412         char sa_sizeof_long;
413         /*
414          * Operating system name.
415          */
416         char sa_sysname[UTSNAME_LEN];
417         /*
418          * Machine hostname.
419          */
420         char sa_nodename[UTSNAME_LEN];
421         /*
422          * Operating system release number.
423          */
424         char sa_release[UTSNAME_LEN];
425         /*
426          * Machine architecture.
427          */
428         char sa_machine[UTSNAME_LEN];
429 };
430
431 #define FILE_HEADER_SIZE        (sizeof(struct file_header))
432 /* The value below is used for sanity check */
433 #define MAX_FILE_HEADER_SIZE    8192
434
435
436 /*
437  * Base magical number for activities.
438  */
439 #define ACTIVITY_MAGIC_BASE     0x8a
440 /*
441  * Magical value used for activities with
442  * unknown format (used for sadf -H only).
443  */
444 #define ACTIVITY_MAGIC_UNKNOWN  0x89
445
446 /* List of activities saved in file */
447 struct file_activity {
448         /*
449          * Identification value of activity.
450          */
451         unsigned int id         __attribute__ ((aligned (4)));
452         /*
453          * Activity magical number.
454          */
455         unsigned int magic      __attribute__ ((packed));
456         /*
457          * Number of items for this activity.
458          */
459         __nr_t nr               __attribute__ ((packed));
460         /*
461          * Number of sub-items for this activity.
462          */
463         __nr_t nr2              __attribute__ ((packed));
464         /*
465          * Size of an item structure.
466          */
467         int size                __attribute__ ((packed));
468 };
469
470 #define FILE_ACTIVITY_SIZE      (sizeof(struct file_activity))
471
472
473 /* Record type */
474 /*
475  * R_STATS means that this is a record of statistics.
476  */
477 #define R_STATS         1
478 /*
479  * R_RESTART means that this is a special record containing
480  * a LINUX RESTART message.
481  */
482 #define R_RESTART       2
483 /*
484  * R_LAST_STATS warns sar that this is the last record to be written
485  * to file before a file rotation, and that the next data to come will
486  * be a header file.
487  * Such a record is tagged R_STATS anyway before being written to file.
488  */
489 #define R_LAST_STATS    3
490 /*
491  * R_COMMENT means that this is a special record containing
492  * a comment.
493  */
494 #define R_COMMENT       4
495
496 /* Maximum length of a comment */
497 #define MAX_COMMENT_LEN 64
498
499 /* Header structure for every record */
500 struct record_header {
501         /*
502          * Machine uptime (multiplied by the # of proc).
503          */
504         unsigned long long uptime       __attribute__ ((aligned (16)));
505         /*
506          * Uptime reduced to one processor. Always set, even on UP machines.
507          */
508         unsigned long long uptime0      __attribute__ ((aligned (16)));
509         /*
510          * Timestamp (number of seconds since the epoch).
511          */
512         unsigned long ust_time          __attribute__ ((aligned (16)));
513         /*
514          * Record type: R_STATS, R_RESTART,...
515          */
516         unsigned char record_type       __attribute__ ((aligned (8)));
517         /*
518          * Timestamp: Hour (0-23), minute (0-59) and second (0-59).
519          * Used to determine TRUE time (immutable, non locale dependent time).
520          */
521         unsigned char hour;
522         unsigned char minute;
523         unsigned char second;
524 };
525
526 #define RECORD_HEADER_SIZE      (sizeof(struct record_header))
527
528
529 /*
530  ***************************************************************************
531  * Generic description of an activity.
532  ***************************************************************************
533  */
534
535 /* Activity options */
536 #define AO_NULL                 0x00
537 /*
538  * Indicate that corresponding activity should be collected by sadc.
539  */
540 #define AO_COLLECTED            0x01
541 /*
542  * Indicate that corresponding activity should be displayed by sar.
543  */
544 #define AO_SELECTED             0x02
545 /*
546  * When appending data to a file, the number of items (for every activity)
547  * is forced to that of the file (number of network interfaces, serial lines,
548  * etc.) Exceptions are volatile activities (like A_CPU) whose number of items
549  * is related to the number of CPUs: If current machine has a different number
550  * of CPU than that of the file (but is equal to sa_last_cpu_nr) then data
551  * will be appended with a number of items equal to that of the machine.
552  */
553 #define AO_VOLATILE             0x04
554 /*
555  * Indicate that the interval of time, given to f_print() function
556  * displaying statistics, should be the interval of time in jiffies
557  * multiplied by the number of processors.
558  */
559 #define AO_GLOBAL_ITV           0x08
560 /*
561  * This flag should be set for every activity closing a markup used
562  * by several activities. Used by sadf f_xml_print() functions to
563  * display XML output.
564  */
565 #define AO_CLOSE_MARKUP         0x10
566 /*
567  * Indicate that corresponding activity has multiple different
568  * output formats. This is the case for example for memory activity
569  * with options -r and -R.
570  */
571 #define AO_MULTIPLE_OUTPUTS     0x20
572 /*
573  * Indicate that one (SVG) graph will be displayed for each
574  * distinct item for this activity (sadf -g).
575  */
576 #define AO_GRAPH_PER_ITEM       0x40
577
578 #define IS_COLLECTED(m)         (((m) & AO_COLLECTED)        == AO_COLLECTED)
579 #define IS_SELECTED(m)          (((m) & AO_SELECTED)         == AO_SELECTED)
580 #define IS_VOLATILE(m)          (((m) & AO_VOLATILE)         == AO_VOLATILE)
581 #define NEED_GLOBAL_ITV(m)      (((m) & AO_GLOBAL_ITV)       == AO_GLOBAL_ITV)
582 #define CLOSE_MARKUP(m)         (((m) & AO_CLOSE_MARKUP)     == AO_CLOSE_MARKUP)
583 #define HAS_MULTIPLE_OUTPUTS(m) (((m) & AO_MULTIPLE_OUTPUTS) == AO_MULTIPLE_OUTPUTS)
584 #define ONE_GRAPH_PER_ITEM(m)   (((m) & AO_GRAPH_PER_ITEM)   == AO_GRAPH_PER_ITEM)
585
586 #define _buf0   buf[0]
587
588 /* Structure used to define a bitmap needed by an activity */
589 struct act_bitmap {
590         /*
591          * Bitmap for activities that need one. Remember to allocate it
592          * before use!
593          */
594         unsigned char *b_array;
595         /*
596          * Size of the bitmap in bits. In fact, bitmap is sized to b_size + 1
597          * to take into account CPU "all"
598          */
599         int b_size;
600 };
601
602 /*
603  * Structure used to define an activity.
604  * Note: This structure can be modified without changing the format of data files.
605  */
606 struct activity {
607         /*
608          * This variable contains the identification value (A_...) for this activity.
609          */
610         unsigned int id;
611         /*
612          * Activity options (AO_...)
613          */
614         unsigned int options;
615         /*
616          * Activity magical number. This number changes when activity format in file
617          * is no longer compatible with the format of that same activity from
618          * previous versions.
619          */
620         unsigned int magic;
621         /*
622          * An activity belongs to a group (and only one).
623          * Groups are those selected with option -S of sadc.
624          */
625         unsigned int group;
626         /*
627          * Index in f_count[] array to determine function used to count
628          * the number of items (serial lines, network interfaces, etc.) -> @nr
629          * Such a function should _always_ return a value greater than
630          * or equal to 0.
631          *
632          * A value of -1 indicates that the number of items
633          * is a constant (and @nr is set to this value).
634          *
635          * These functions are called even if corresponding activities have not
636          * been selected, to make sure that all items have been calculated
637          * (including #CPU, etc.)
638          */
639         int f_count_index;
640         /*
641          * The f_count2() function is used to count the number of
642          * sub-items -> @nr2
643          * Such a function should _always_ return a value greater than
644          * or equal to 0.
645          *
646          * A NULL value for this function pointer indicates that the number of items
647          * is a constant (and @nr2 is set to this value).
648          */
649         __nr_t (*f_count2) (struct activity *);
650         /*
651          * This function reads the relevant file and fill the buffer
652          * with statistics corresponding to given activity.
653          */
654         __read_funct_t (*f_read) (struct activity *);
655         /*
656          * This function displays activity statistics onto the screen.
657          */
658         __print_funct_t (*f_print) (struct activity *, int, int, unsigned long long);
659         /*
660          * This function displays average activity statistics onto the screen.
661          */
662         __print_funct_t (*f_print_avg) (struct activity *, int, int, unsigned long long);
663         /*
664          * This function is used by sadf to display activity in a format that can
665          * easily be ingested by a relational database, or a format that can be
666          * handled by pattern processing commands like "awk".
667          */
668         __print_funct_t (*f_render) (struct activity *, int, char *, int, unsigned long long);
669         /*
670          * This function is used by sadf to display activity statistics in XML.
671          */
672         __print_funct_t (*f_xml_print) (struct activity *, int, int, unsigned long long);
673         /*
674          * This function is used by sadf to display activity statistics in JSON.
675          */
676         __print_funct_t (*f_json_print) (struct activity *, int, int, unsigned long long);
677         /*
678          * This function is used by sadf to display activity statistics in SVG.
679          */
680         __print_funct_t (*f_svg_print) (struct activity *, int, int, struct svg_parm *,
681                                         unsigned long long, struct record_header *);
682         /*
683          * Header string displayed by sadf -d.
684          * Header lines for each output (for activities with multiple outputs) are
685          * separated with a '|' character.
686          * For a given output, the first field corresponding to extended statistics
687          * (eg. -r ALL) begins with a '&' character.
688          */
689         char *hdr_line;
690         /*
691          * Name of activity.
692          */
693         char *name;
694         /*
695          * Number of SVG graphs for this activity. The total number of graphs for
696          * the activity can be greater though if flag AO_GRAPH_PER_ITEM is set, in
697          * which case the total number will  be @g_nr * @nr.
698          */
699         int g_nr;
700         /*
701          * Number of items on the system.
702          * A negative value (-1) is the default value and indicates that this number
703          * has still not been calculated by the f_count() function.
704          * A value of 0 means that this number has been calculated, but no items have
705          * been found.
706          * A positive value (>0) has either been calculated or is a constant.
707          */
708         __nr_t nr;
709         /*
710          * Number of sub-items on the system.
711          * @nr2 is in fact the second dimension of a matrix of items, the first
712          * one being @nr. @nr is the number of lines, and @nr2 the number of columns.
713          * A negative value (-1) is the default value and indicates that this number
714          * has still not been calculated by the f_count2() function.
715          * A value of 0 means that this number has been calculated, but no sub-items have
716          * been found.
717          * A positive value (>0) has either been calculated or is a constant.
718          * Rules:
719          * 1) IF @nr2 = 0 THEN @nr = 0
720          *    Note: If @nr = 0, then @nr2 is undetermined (may be -1, 0 or >0).
721          * 2) IF @nr > 0 THEN @nr2 > 0.
722          *    Note: If @nr2 > 0 then @nr is undetermined (may be -1, 0 or >0).
723          * 3) IF @nr <= 0 THEN @nr2 = -1 (this is the default value for @nr2,
724          * meaning that it has not been calculated).
725          */
726         __nr_t nr2;
727         /*
728          * Maximum number of elements that sar can handle for this item.
729          * NB: The maximum number of elements that sar can handle for sub-items
730          * is NR2_MAX.
731          */
732         __nr_t nr_max;
733         /*
734          * Size of an item.
735          * This is the size of the corresponding structure, as read from or written
736          * to a file, or read from or written by the data collector.
737          */
738         int fsize;
739         /*
740          * Size of an item.
741          * This is the size of the corresponding structure as mapped into memory.
742          * @msize can be different from @fsize when data are read from or written to
743          * a data file from a different sysstat version.
744          */
745         int msize;
746         /*
747          * Optional flags for activity. This is eg. used when AO_MULTIPLE_OUTPUTS
748          * option is set.
749          * 0x0001 - 0x0080 : Multiple outputs (eg. AO_F_MEM_AMT, AO_F_MEM_SWAP...)
750          * 0x0100 - 0x8000 : If bit set then display complete header (hdr_line) for
751          *                   corresponding output
752          * 0x010000+       : Optional flags
753          */
754         unsigned int opt_flags;
755         /*
756          * Buffers that will contain the statistics read. Its size is @nr * @nr2 * @size each.
757          * [0]: used by sadc.
758          * [0] and [1]: current/previous statistics values (used by sar).
759          * [2]: Used by sar to save first collected stats (used later to
760          * compute average).
761          */
762         void *buf[3];
763         /*
764          * Bitmap for activities that need one. Such a bitmap is needed by activity
765          * if @bitmap is not NULL.
766          */
767         struct act_bitmap *bitmap;
768 };
769
770
771 /*
772  ***************************************************************************
773  * Generic description of an output format for sadf (and sar).
774  ***************************************************************************
775  */
776
777 /* Type for all functions used by sadf to display stats in various formats */
778 #define __printf_funct_t void
779 #define __tm_funct_t char *
780
781 /*
782  * Structure used to define a report.
783  * A XML-like report has the following format:
784  *       __
785  *      |
786  *      | Header block
787  *      |  __
788  *      | |
789  *      | | Statistics block
790  *      | |  __
791  *      | | |
792  *      | | | Timestamp block
793  *      | | |  __
794  *      | | | |
795  *      | | | | Activity #1
796  *      | | | |__
797  *      | | | |
798  *      | | | | ...
799  *      | | | |__
800  *      | | | |
801  *      | | | | Activity #n
802  *      | | | |__
803  *      | | |__
804  *      | |__
805  *      | |
806  *      | | Restart messages block
807  *      | |__
808  *      | |
809  *      | | Comments block
810  *      | |__
811  *      |__
812  */
813 struct report_format {
814         /*
815          * This variable contains the identification value (F_...) for this report format.
816          */
817         unsigned int id;
818         /*
819          * Format options (FO_...).
820          */
821         unsigned int options;
822         /*
823          * This function displays the report header
824          * (data displayed once at the beginning of the report).
825          */
826         __printf_funct_t (*f_header) (void *, int, char *, struct file_magic *, struct file_header *,
827                                       __nr_t, struct activity * [], unsigned int []);
828         /*
829          * This function defines the statistics part of the report.
830          * Used only with textual (XML-like) reports.
831          */
832         __printf_funct_t (*f_statistics) (int *, int);
833         /*
834          * This function defines the timestamp part of the report.
835          * Used only with textual (XML-like) reports.
836          */
837         __tm_funct_t (*f_timestamp) (void *, int, char *, char *, unsigned long long,
838                                      struct file_header *, unsigned int);
839         /*
840          * This function displays the restart messages.
841          */
842         __printf_funct_t (*f_restart) (int *, int, char *, char *, int, struct file_header *,
843                                        unsigned int);
844         /*
845          * This function displays the comments.
846          */
847         __printf_funct_t (*f_comment) (int *, int, char *, char *, int, char *, struct file_header *);
848 };
849
850 /* Possible actions for functions used to display reports */
851 #define F_BEGIN 0x01
852 #define F_MAIN  0x02
853 #define F_END   0x04
854
855 /*
856  ***************************************************************************
857  * SVG output definitions
858  ***************************************************************************
859  */
860
861 /*
862  *   ^
863  * 1 | General header
864  *   v
865  *   ^   ^   ^
866  *   |   | 4 | Graph title
867  *   |   |   v
868  *   |   |   ^    |                                Caption
869  *   | 3 |   |    |
870  *   |   |   |  G |Y
871  * 2 |   | 5 |  r |
872  *   |   |   |  a |A
873  *   |   |   |  d |x
874  *   |   |   |  . |i
875  *   |   |   |    |s          X Axis
876  *   |   |   v    |-------------------------------
877  *   |   |              Grad.
878  *   |   v   <---><------------------------------>
879  *   |         6                8
880  *   | Gap
881  *   v<--------------------------------------------------------------->
882  *                                    7
883  */
884
885 /* #8 */
886 #define SVG_G_XSIZE     720
887 /* #6 */
888 #define SVG_M_XSIZE     70
889 /* #7 */
890 #define SVG_V_XSIZE     1050
891
892 /* #5 */
893 #define SVG_G_YSIZE     200
894 /* #1 */
895 #define SVG_H_YSIZE     50
896 /* #4 */
897 #define SVG_M_YSIZE     50
898 /* #2 */
899 #define SVG_T_YSIZE     310
900 /* #3 */
901 #define SVG_V_YSIZE     300
902
903 /* Grid: Nr of horizontal lines */
904 #define SVG_H_GRIDNR    3
905 /* Grid: Nr of vertical lines */
906 #define SVG_V_GRIDNR    10
907
908 /* Block size used to allocate arrays for graphs data */
909 #define CHUNKSIZE       4096
910
911 #define SVG_LINE_GRAPH  1
912 #define SVG_BAR_GRAPH   2
913
914 #define MAYBE   0x80
915
916 /*
917  ***************************************************************************
918  * Macro functions definitions.
919  *
920  * Note: Using 'do ... while' makes the macros safer to use
921  * (remember that macro use is followed by a semicolon).
922  ***************************************************************************
923  */
924
925 /* Close file descriptors */
926 #define CLOSE_ALL(_fd_)         do {                    \
927                                         close(_fd_[0]); \
928                                         close(_fd_[1]); \
929                                 } while (0)
930
931 #define CLOSE(_fd_)             if (_fd_ >= 0)          \
932                                         close(_fd_)
933
934
935 /*
936  ***************************************************************************
937  * Various structure definitions.
938  ***************************************************************************
939  */
940
941 /* Structure for timestamps */
942 struct tstamp {
943         int tm_sec;
944         int tm_min;
945         int tm_hour;
946         int use;
947 };
948
949
950 /*
951  ***************************************************************************
952  * Functions prototypes.
953  ***************************************************************************
954  */
955
956 /* Functions used to count number of items */
957 __nr_t wrap_get_cpu_nr
958         (struct activity *);
959 __nr_t wrap_get_irq_nr
960         (struct activity *);
961 __nr_t wrap_get_serial_nr
962         (struct activity *);
963 __nr_t wrap_get_disk_nr
964         (struct activity *);
965 __nr_t wrap_get_iface_nr
966         (struct activity *);
967 __nr_t wrap_get_fan_nr
968         (struct activity *);
969 __nr_t wrap_get_temp_nr
970         (struct activity *);
971 __nr_t wrap_get_in_nr
972         (struct activity *);
973 __nr_t wrap_get_freq_nr
974         (struct activity *);
975 __nr_t wrap_get_usb_nr
976         (struct activity *);
977 __nr_t wrap_get_filesystem_nr
978         (struct activity *);
979 __nr_t wrap_get_fchost_nr
980         (struct activity *);
981
982 /* Functions used to read activities statistics */
983 __read_funct_t wrap_read_stat_cpu
984         (struct activity *);
985 __read_funct_t wrap_read_stat_pcsw
986         (struct activity *);
987 __read_funct_t wrap_read_stat_irq
988         (struct activity *);
989 __read_funct_t wrap_read_swap
990         (struct activity *);
991 __read_funct_t wrap_read_paging
992         (struct activity *);
993 __read_funct_t wrap_read_io
994         (struct activity *);
995 __read_funct_t wrap_read_meminfo
996         (struct activity *);
997 __read_funct_t wrap_read_kernel_tables
998         (struct activity *);
999 __read_funct_t wrap_read_loadavg
1000         (struct activity *);
1001 __read_funct_t wrap_read_tty_driver_serial
1002         (struct activity *);
1003 __read_funct_t wrap_read_disk
1004         (struct activity *);
1005 __read_funct_t wrap_read_net_dev
1006         (struct activity *);
1007 __read_funct_t wrap_read_net_edev
1008         (struct activity *);
1009 __read_funct_t wrap_read_net_nfs
1010         (struct activity *);
1011 __read_funct_t wrap_read_net_nfsd
1012         (struct activity *);
1013 __read_funct_t wrap_read_net_sock
1014         (struct activity *);
1015 __read_funct_t wrap_read_net_ip
1016         (struct activity *);
1017 __read_funct_t wrap_read_net_eip
1018         (struct activity *);
1019 __read_funct_t wrap_read_net_icmp
1020         (struct activity *);
1021 __read_funct_t wrap_read_net_eicmp
1022         (struct activity *);
1023 __read_funct_t wrap_read_net_tcp
1024         (struct activity *);
1025 __read_funct_t wrap_read_net_etcp
1026         (struct activity *);
1027 __read_funct_t wrap_read_net_udp
1028         (struct activity *);
1029 __read_funct_t wrap_read_net_sock6
1030         (struct activity *);
1031 __read_funct_t wrap_read_net_ip6
1032         (struct activity *);
1033 __read_funct_t wrap_read_net_eip6
1034         (struct activity *);
1035 __read_funct_t wrap_read_net_icmp6
1036         (struct activity *);
1037 __read_funct_t wrap_read_net_eicmp6
1038         (struct activity *);
1039 __read_funct_t wrap_read_net_udp6
1040         (struct activity *);
1041 __read_funct_t wrap_read_cpuinfo
1042         (struct activity *);
1043 __read_funct_t wrap_read_fan
1044         (struct activity *);
1045 __read_funct_t wrap_read_temp
1046         (struct activity *);
1047 __read_funct_t wrap_read_in
1048         (struct activity *);
1049 __read_funct_t wrap_read_meminfo_huge
1050         (struct activity *);
1051 __read_funct_t wrap_read_time_in_state
1052         (struct activity *);
1053 __read_funct_t wrap_read_bus_usb_dev
1054         (struct activity *);
1055 __read_funct_t wrap_read_filesystem
1056         (struct activity *);
1057 __read_funct_t wrap_read_fchost
1058         (struct activity *);
1059
1060 /* Other functions */
1061 void allocate_bitmaps
1062         (struct activity * []);
1063 void allocate_structures
1064         (struct activity * []);
1065 int check_alt_sa_dir
1066         (char *, int, int);
1067 int check_disk_reg
1068         (struct activity *, int, int, int);
1069 void check_file_actlst
1070         (int *, char *, struct activity * [], struct file_magic *, struct file_header *,
1071          struct file_activity **, unsigned int [], int);
1072 unsigned int check_net_dev_reg
1073         (struct activity *, int, int, unsigned int);
1074 unsigned int check_net_edev_reg
1075         (struct activity *, int, int, unsigned int);
1076 double compute_ifutil
1077         (struct stats_net_dev *, double, double);
1078 void copy_structures
1079         (struct activity * [], unsigned int [], struct record_header [], int, int);
1080 int datecmp
1081         (struct tm *, struct tstamp *);
1082 void display_sa_file_version
1083         (FILE *, struct file_magic *);
1084 void enum_version_nr
1085         (struct file_magic *);
1086 void free_bitmaps
1087         (struct activity * []);
1088 void free_structures
1089         (struct activity * []);
1090 int get_activity_nr
1091         (struct activity * [], unsigned int, int);
1092 int get_activity_position
1093         (struct activity * [], unsigned int, int);
1094 char *get_devname
1095         (unsigned int, unsigned int, int);
1096 void get_file_timestamp_struct
1097         (unsigned int, struct tm *, struct file_header *);
1098 void get_itv_value
1099         (struct record_header *, struct record_header *, unsigned int,
1100          unsigned long long *, unsigned long long *);
1101 void handle_invalid_sa_file
1102         (int *, struct file_magic *, char *, int);
1103 int next_slice
1104         (unsigned long long, unsigned long long, int, long);
1105 int parse_sar_opt
1106         (char * [], int *, struct activity * [], unsigned int *, int);
1107 int parse_sar_I_opt
1108         (char * [], int *, struct activity * []);
1109 int parse_sa_P_opt
1110         (char * [], int *, unsigned int *, struct activity * []);
1111 int parse_sar_m_opt
1112         (char * [], int *, struct activity * []);
1113 int parse_sar_n_opt
1114         (char * [], int *, struct activity * []);
1115 int parse_timestamp
1116         (char * [], int *, struct tstamp *, const char *);
1117 void print_report_hdr
1118         (unsigned int, struct tm *, struct file_header *, int);
1119 void print_sar_comment
1120         (int *, int, char *, char *, int, char *, struct file_header *);
1121 void print_sar_restart
1122         (int *, int, char *, char *, int, struct file_header *, unsigned int);
1123 int print_special_record
1124         (struct record_header *, unsigned int, struct tstamp *, struct tstamp *,
1125          int, int, struct tm *, struct tm *, char *, int, struct file_magic *,
1126          struct file_header *, struct activity * [], struct report_format *);
1127 void read_file_stat_bunch
1128         (struct activity * [], int, int, int, struct file_activity *);
1129 __nr_t read_vol_act_structures
1130         (int, struct activity * [], char *, struct file_magic *, unsigned int);
1131 int reallocate_vol_act_structures
1132         (struct activity * [], unsigned int, unsigned int);
1133 void replace_nonprintable_char
1134         (int, char *);
1135 int sa_fread
1136         (int, void *, int, int);
1137 int sa_get_record_timestamp_struct
1138         (unsigned int, struct record_header *, struct tm *, struct tm *);
1139 int sa_open_read_magic
1140         (int *, char *, struct file_magic *, int);
1141 void select_all_activities
1142         (struct activity * []);
1143 void select_default_activity
1144         (struct activity * []);
1145 void set_bitmap
1146         (unsigned char [], unsigned char, unsigned int);
1147 void set_default_file
1148         (char *, int, int);
1149 void set_hdr_rectime
1150         (unsigned int, struct tm *, struct file_header *);
1151 void set_record_timestamp_string
1152         (unsigned int, struct record_header *, char *, char *, int, struct tm *);
1153
1154 #endif  /* _SA_H */