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