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