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