]> granicus.if.org Git - sysstat/blob - sa.h
sadc/sar: New format (part 3): Use 64-bit time fields
[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  * Format of system activity data files:
321  *       __
322  *      |
323  *      | file_magic structure
324  *      |
325  *      |--
326  *      |
327  *      | file_header structure
328  *      |
329  *      |--                         --|
330  *      |                             |
331  *      | file_activity structure     | * sa_act_nr
332  *      |                             |
333  *      |--                         --|
334  *      |                             |
335  *      | record_header structure     |
336  *      |                             |
337  *      |--                           | * <count>
338  *      |                             |
339  *      | Statistics structures...(*) |
340  *      |                             |
341  *      |--                         --|
342  *
343  * (*)Note: If it's a special record, we may find a comment instead of
344  * statistics (R_COMMENT record type) or, if it's a R_RESTART record type,
345  * <sa_nr_vol_act> structures (of type file_activity) for the volatile
346  * activities.
347  ***************************************************************************
348  */
349
350 /*
351  * Sysstat magic number. Should never be modified.
352  * Indicate that the file was created by sysstat.
353  */
354 #define SYSSTAT_MAGIC   0xd596
355 #define SYSSTAT_MAGIC_SWAPPED   (((SYSSTAT_MAGIC << 8) | (SYSSTAT_MAGIC >> 8)) & 0xffff)
356
357 /*
358  * Datafile format magic number.
359  * Modified to indicate that the format of the file is
360  * no longer compatible with that of previous sysstat versions.
361  */
362 #define FORMAT_MAGIC    0x2175
363 #define FORMAT_MAGIC_SWAPPED    (((FORMAT_MAGIC << 8) | (FORMAT_MAGIC >> 8)) & 0xffff)
364
365 /* Previous datafile format magic number used by older sysstat versions */
366 #define PREVIOUS_FORMAT_MAGIC   0x2173
367
368 /* Padding in file_magic structure. See below. */
369 #define FILE_MAGIC_PADDING      63
370
371 /* Structure for file magic header data */
372 struct file_magic {
373         /*
374          * This field identifies the file as a file created by sysstat.
375          */
376         unsigned short sysstat_magic;
377         /*
378          * The value of this field varies whenever datafile format changes.
379          */
380         unsigned short format_magic;
381         /*
382          * Sysstat version used to create the file.
383          */
384         unsigned char sysstat_version;
385         unsigned char sysstat_patchlevel;
386         unsigned char sysstat_sublevel;
387         unsigned char sysstat_extraversion;
388         /*
389          * Size of file's header (size of file_header structure used by file).
390          */
391         unsigned int header_size;
392         /*
393          * Set to non zero if data file has been converted with "sadf -c" from
394          * an old format (version x.y.z) to a newest format (version X.Y.Z).
395          * In this case, the value is: Y*16 + Z + 1.
396          * The FORMAT_MAGIC value of the file can be used to determine X.
397          */
398         unsigned char upgraded;
399         /*
400          * Padding. Reserved for future use while avoiding a format change.
401          */
402         unsigned char pad[FILE_MAGIC_PADDING];
403 };
404
405 #define FILE_MAGIC_SIZE (sizeof(struct file_magic))
406
407
408 /* Header structure for system activity data file */
409 struct file_header {
410         /*
411          * Timestamp in seconds since the epoch.
412          */
413         unsigned long long sa_ust_time;
414         /*
415          * Number of CPU items (1 .. CPU_NR + 1) for the last sample in file.
416          */
417         unsigned int sa_last_cpu_nr;
418         /*
419          * Number of activities saved in file.
420          */
421         unsigned int sa_act_nr;
422         /*
423          * Number of volatile activities in file. This is the number of
424          * file_activity structures saved after each restart mark in file.
425          */
426         unsigned int sa_vol_act_nr;
427         /*
428          * Current day, month and year.
429          * No need to save DST (Daylight Saving Time) flag, since it is not taken
430          * into account by the strftime() function used to print the timestamp.
431          */
432         int sa_year;
433         unsigned char sa_day;
434         unsigned char sa_month;
435         /*
436          * Size of a long integer. Useful to know the architecture on which
437          * the datafile was created.
438          */
439         char sa_sizeof_long;
440         /*
441          * Operating system name.
442          */
443         char sa_sysname[UTSNAME_LEN];
444         /*
445          * Machine hostname.
446          */
447         char sa_nodename[UTSNAME_LEN];
448         /*
449          * Operating system release number.
450          */
451         char sa_release[UTSNAME_LEN];
452         /*
453          * Machine architecture.
454          */
455         char sa_machine[UTSNAME_LEN];
456 };
457
458 #define FILE_HEADER_SIZE        (sizeof(struct file_header))
459 #define FILE_HEADER_ULL_NR      1       /* Nr of unsigned long long in file_header structure */
460 #define FILE_HEADER_UL_NR       0       /* Nr of unsigned long in file_header structure */
461 #define FILE_HEADER_U_NR        4       /* Nr of [unsigned] int in file_header structure */
462 /* The values below are used for sanity check */
463 #define MIN_FILE_HEADER_SIZE    0
464 #define MAX_FILE_HEADER_SIZE    8192
465
466
467 /*
468  * Base magical number for activities.
469  */
470 #define ACTIVITY_MAGIC_BASE     0x8a
471 /*
472  * Magical value used for activities with
473  * unknown format (used for sadf -H only).
474  */
475 #define ACTIVITY_MAGIC_UNKNOWN  0x89
476
477 /* List of activities saved in file */
478 struct file_activity {
479         /*
480          * Identification value of activity.
481          */
482         unsigned int id;
483         /*
484          * Activity magical number.
485          */
486         unsigned int magic;
487         /*
488          * Number of items for this activity.
489          */
490         __nr_t nr;
491         /*
492          * Number of sub-items for this activity.
493          */
494         __nr_t nr2;
495         /*
496          * Size of an item structure.
497          */
498         int size;
499         /*
500          * Description of the structure containing statistics for the
501          * given activity (nr of "long long", nr of "long" and nr of "int").
502          */
503         int types_nr[3];
504 };
505
506 #define FILE_ACTIVITY_SIZE      (sizeof(struct file_activity))
507 #define FILE_ACTIVITY_ULL_NR    0       /* Nr of unsigned long long in file_activity structure */
508 #define FILE_ACTIVITY_UL_NR     0       /* Nr of unsigned long in file_activity structure */
509 #define FILE_ACTIVITY_U_NR      8       /* Nr of [unsigned] int in file_activity structure */
510
511
512 /* Record type */
513 /*
514  * R_STATS means that this is a record of statistics.
515  */
516 #define R_STATS         1
517 /*
518  * R_RESTART means that this is a special record containing
519  * a LINUX RESTART message.
520  */
521 #define R_RESTART       2
522 /*
523  * R_LAST_STATS warns sar that this is the last record to be written
524  * to file before a file rotation, and that the next data to come will
525  * be a header file.
526  * Such a record is tagged R_STATS anyway before being written to file.
527  */
528 #define R_LAST_STATS    3
529 /*
530  * R_COMMENT means that this is a special record containing
531  * a comment.
532  */
533 #define R_COMMENT       4
534
535 /* Maximum length of a comment */
536 #define MAX_COMMENT_LEN 64
537
538 /* Header structure for every record */
539 struct record_header {
540         /*
541          * Machine uptime (multiplied by the # of proc).
542          */
543         unsigned long long uptime;
544         /*
545          * Uptime reduced to one processor. Always set, even on UP machines.
546          */
547         unsigned long long uptime0;
548         /*
549          * Timestamp (number of seconds since the epoch).
550          */
551         unsigned long long ust_time;
552         /*
553          * Record type: R_STATS, R_RESTART,...
554          */
555         unsigned char record_type;
556         /*
557          * Timestamp: Hour (0-23), minute (0-59) and second (0-59).
558          * Used to determine TRUE time (immutable, non locale dependent time).
559          */
560         unsigned char hour;
561         unsigned char minute;
562         unsigned char second;
563 };
564
565 #define RECORD_HEADER_SIZE      (sizeof(struct record_header))
566 #define RECORD_HEADER_ULL_NR    3       /* Nr of unsigned long long in record_header structure */
567 #define RECORD_HEADER_UL_NR     0       /* Nr of unsigned long in record_header structure */
568 #define RECORD_HEADER_U_NR      0       /* Nr of unsigned int in record_header structure */
569
570
571 /*
572  ***************************************************************************
573  * Generic description of an activity.
574  ***************************************************************************
575  */
576
577 /* Activity options */
578 #define AO_NULL                 0x00
579 /*
580  * Indicate that corresponding activity should be collected by sadc.
581  */
582 #define AO_COLLECTED            0x01
583 /*
584  * Indicate that corresponding activity should be displayed by sar.
585  */
586 #define AO_SELECTED             0x02
587 /*
588  * When appending data to a file, the number of items (for every activity)
589  * is forced to that of the file (number of network interfaces, serial lines,
590  * etc.) Exceptions are volatile activities (like A_CPU) whose number of items
591  * is related to the number of CPUs: If current machine has a different number
592  * of CPU than that of the file (but is equal to sa_last_cpu_nr) then data
593  * will be appended with a number of items equal to that of the machine.
594  */
595 #define AO_VOLATILE             0x04
596 /*
597  * Indicate that the interval of time, given to f_print() function
598  * displaying statistics, should be the interval of time in jiffies
599  * multiplied by the number of processors.
600  */
601 #define AO_GLOBAL_ITV           0x08
602 /*
603  * This flag should be set for every activity closing a markup used
604  * by several activities. Used by sadf f_xml_print() functions to
605  * display XML output.
606  */
607 #define AO_CLOSE_MARKUP         0x10
608 /*
609  * Indicate that corresponding activity has multiple different
610  * output formats. This is the case for example for memory activity
611  * with options -r and -R.
612  * PS: Such an activity should appear in the list of activities that
613  * sar -A is supposed to display.
614  */
615 #define AO_MULTIPLE_OUTPUTS     0x20
616 /*
617  * Indicate that one (SVG) graph will be displayed for each
618  * distinct item for this activity (sadf -g).
619  */
620 #define AO_GRAPH_PER_ITEM       0x40
621
622 #define IS_COLLECTED(m)         (((m) & AO_COLLECTED)        == AO_COLLECTED)
623 #define IS_SELECTED(m)          (((m) & AO_SELECTED)         == AO_SELECTED)
624 #define IS_VOLATILE(m)          (((m) & AO_VOLATILE)         == AO_VOLATILE)
625 #define NEED_GLOBAL_ITV(m)      (((m) & AO_GLOBAL_ITV)       == AO_GLOBAL_ITV)
626 #define CLOSE_MARKUP(m)         (((m) & AO_CLOSE_MARKUP)     == AO_CLOSE_MARKUP)
627 #define HAS_MULTIPLE_OUTPUTS(m) (((m) & AO_MULTIPLE_OUTPUTS) == AO_MULTIPLE_OUTPUTS)
628 #define ONE_GRAPH_PER_ITEM(m)   (((m) & AO_GRAPH_PER_ITEM)   == AO_GRAPH_PER_ITEM)
629
630 #define _buf0   buf[0]
631
632 /* Structure used to define a bitmap needed by an activity */
633 struct act_bitmap {
634         /*
635          * Bitmap for activities that need one. Remember to allocate it
636          * before use!
637          */
638         unsigned char *b_array;
639         /*
640          * Size of the bitmap in bits. In fact, bitmap is sized to b_size + 1
641          * to take into account CPU "all"
642          */
643         int b_size;
644 };
645
646 /*
647  * Structure used to define an activity.
648  * Note: This structure can be modified without changing the format of data files.
649  */
650 struct activity {
651         /*
652          * This variable contains the identification value (A_...) for this activity.
653          */
654         unsigned int id;
655         /*
656          * Activity options (AO_...)
657          */
658         unsigned int options;
659         /*
660          * Activity magical number. This number changes when activity format in file
661          * is no longer compatible with the format of that same activity from
662          * previous versions.
663          */
664         unsigned int magic;
665         /*
666          * An activity belongs to a group (and only one).
667          * Groups are those selected with option -S of sadc.
668          */
669         unsigned int group;
670         /*
671          * Index in f_count[] array to determine function used to count
672          * the number of items (serial lines, network interfaces, etc.) -> @nr
673          * Such a function should _always_ return a value greater than
674          * or equal to 0.
675          *
676          * A value of -1 indicates that the number of items
677          * is a constant (and @nr is set to this value).
678          *
679          * These functions are called even if corresponding activities have not
680          * been selected, to make sure that all items have been calculated
681          * (including #CPU, etc.)
682          */
683         int f_count_index;
684         /*
685          * The f_count2() function is used to count the number of
686          * sub-items -> @nr2
687          * Such a function should _always_ return a value greater than
688          * or equal to 0.
689          *
690          * A NULL value for this function pointer indicates that the number of items
691          * is a constant (and @nr2 is set to this value).
692          */
693         __nr_t (*f_count2) (struct activity *);
694         /*
695          * This function reads the relevant file and fill the buffer
696          * with statistics corresponding to given activity.
697          */
698         __read_funct_t (*f_read) (struct activity *);
699         /*
700          * This function displays activity statistics onto the screen.
701          */
702         __print_funct_t (*f_print) (struct activity *, int, int, unsigned long long);
703         /*
704          * This function displays average activity statistics onto the screen.
705          */
706         __print_funct_t (*f_print_avg) (struct activity *, int, int, unsigned long long);
707         /*
708          * This function is used by sadf to display activity in a format that can
709          * easily be ingested by a relational database, or a format that can be
710          * handled by pattern processing commands like "awk".
711          */
712         __print_funct_t (*f_render) (struct activity *, int, char *, int, unsigned long long);
713         /*
714          * This function is used by sadf to display activity statistics in XML.
715          */
716         __print_funct_t (*f_xml_print) (struct activity *, int, int, unsigned long long);
717         /*
718          * This function is used by sadf to display activity statistics in JSON.
719          */
720         __print_funct_t (*f_json_print) (struct activity *, int, int, unsigned long long);
721         /*
722          * This function is used by sadf to display activity statistics in SVG.
723          */
724         __print_funct_t (*f_svg_print) (struct activity *, int, int, struct svg_parm *,
725                                         unsigned long long, struct record_header *);
726         /*
727          * This function is used by sadf to display activity statistics in raw format.
728          */
729         __print_funct_t (*f_raw_print) (struct activity *, char *, int);
730         /*
731          * Header string displayed by sadf -d.
732          * Header lines for each output (for activities with multiple outputs) are
733          * separated with a '|' character.
734          * For a given output, the first field corresponding to extended statistics
735          * (eg. -r ALL) begins with a '&' character.
736          */
737         char *hdr_line;
738         /*
739          * Name of activity.
740          */
741         char *name;
742         /*
743          * Description of the corresponding structure containing statistics (as defined
744          * in rd_stats.h or rd_sensors.h). Such a structure has 0+ fields of type
745          * "long long", followed by 0+ fields of type "long", followed by 0+ fields of
746          * type "int", followed by 0+ other fields (e.g. of type char). The array below
747          * gives the number of "long long" fields composing the structure, then the number
748          * of "long" fields, then the number of "int" fields.
749          */
750         int gtypes_nr[3];
751         /*
752          * This array has the same meaning as @gtypes_nr[] above, but the values are those
753          * read from current data file. They may be different from those of @gtypes_nr[]
754          * because we can read data from a different sysstat version (older or newer).
755          */
756         int ftypes_nr[3];
757         /*
758          * Number of SVG graphs for this activity. The total number of graphs for
759          * the activity can be greater though if flag AO_GRAPH_PER_ITEM is set, in
760          * which case the total number will  be @g_nr * @nr.
761          */
762         int g_nr;
763         /*
764          * Number of items on the system.
765          * A negative value (-1) is the default value and indicates that this number
766          * has still not been calculated by the f_count() function.
767          * A value of 0 means that this number has been calculated, but no items have
768          * been found.
769          * A positive value (>0) has either been calculated or is a constant.
770          */
771         __nr_t nr;
772         /*
773          * Number of sub-items on the system.
774          * @nr2 is in fact the second dimension of a matrix of items, the first
775          * one being @nr. @nr is the number of lines, and @nr2 the number of columns.
776          * A negative value (-1) is the default value and indicates that this number
777          * has still not been calculated by the f_count2() function.
778          * A value of 0 means that this number has been calculated, but no sub-items have
779          * been found.
780          * A positive value (>0) has either been calculated or is a constant.
781          * Rules:
782          * 1) IF @nr2 = 0 THEN @nr = 0
783          *    Note: If @nr = 0, then @nr2 is undetermined (may be -1, 0 or >0).
784          * 2) IF @nr > 0 THEN @nr2 > 0.
785          *    Note: If @nr2 > 0 then @nr is undetermined (may be -1, 0 or >0).
786          * 3) IF @nr <= 0 THEN @nr2 = -1 (this is the default value for @nr2,
787          * meaning that it has not been calculated).
788          */
789         __nr_t nr2;
790         /*
791          * Maximum number of elements that sar can handle for this item.
792          * NB: The maximum number of elements that sar can handle for sub-items
793          * is NR2_MAX.
794          */
795         __nr_t nr_max;
796         /*
797          * Size of an item.
798          * This is the size of the corresponding structure, as read from or written
799          * to a file, or read from or written by the data collector.
800          */
801         int fsize;
802         /*
803          * Size of an item.
804          * This is the size of the corresponding structure as mapped into memory.
805          * @msize can be different from @fsize when data are read from or written to
806          * a data file from a different sysstat version.
807          */
808         int msize;
809         /*
810          * Optional flags for activity. This is eg. used when AO_MULTIPLE_OUTPUTS
811          * option is set.
812          * 0x0001 - 0x0080 : Multiple outputs (eg. AO_F_MEMORY, AO_F_SWAP...)
813          * 0x0100 - 0x8000 : If bit set then display complete header (hdr_line) for
814          *                   corresponding output
815          * 0x010000+       : Optional flags
816          */
817         unsigned int opt_flags;
818         /*
819          * Buffers that will contain the statistics read. Its size is @nr * @nr2 * @size each.
820          * [0]: used by sadc.
821          * [0] and [1]: current/previous statistics values (used by sar).
822          * [2]: Used by sar to save first collected stats (used later to
823          * compute average).
824          */
825         void *buf[3];
826         /*
827          * Bitmap for activities that need one. Such a bitmap is needed by activity
828          * if @bitmap is not NULL.
829          */
830         struct act_bitmap *bitmap;
831 };
832
833
834 /*
835  ***************************************************************************
836  * Generic description of an output format for sadf (and sar).
837  ***************************************************************************
838  */
839
840 /* Type for all functions used by sadf to display stats in various formats */
841 #define __printf_funct_t void
842 #define __tm_funct_t char *
843
844 /*
845  * Structure used to define a report.
846  * A XML-like report has the following format:
847  *       __
848  *      |
849  *      | Header block
850  *      |  __
851  *      | |
852  *      | | Statistics block
853  *      | |  __
854  *      | | |
855  *      | | | Timestamp block
856  *      | | |  __
857  *      | | | |
858  *      | | | | Activity #1
859  *      | | | |__
860  *      | | | |
861  *      | | | | ...
862  *      | | | |__
863  *      | | | |
864  *      | | | | Activity #n
865  *      | | | |__
866  *      | | |__
867  *      | |__
868  *      | |
869  *      | | Restart messages block
870  *      | |__
871  *      | |
872  *      | | Comments block
873  *      | |__
874  *      |__
875  */
876 struct report_format {
877         /*
878          * This variable contains the identification value (F_...) for this report format.
879          */
880         unsigned int id;
881         /*
882          * Format options (FO_...).
883          */
884         unsigned int options;
885         /*
886          * This function displays the report header
887          * (data displayed once at the beginning of the report).
888          */
889         __printf_funct_t (*f_header) (void *, int, char *, struct file_magic *, struct file_header *,
890                                       __nr_t, struct activity * [], unsigned int []);
891         /*
892          * This function defines the statistics part of the report.
893          * Used only with textual (XML-like) reports.
894          */
895         __printf_funct_t (*f_statistics) (int *, int);
896         /*
897          * This function defines the timestamp part of the report.
898          * Used only with textual (XML-like) reports.
899          */
900         __tm_funct_t (*f_timestamp) (void *, int, char *, char *, unsigned long long,
901                                      struct file_header *, unsigned int);
902         /*
903          * This function displays the restart messages.
904          */
905         __printf_funct_t (*f_restart) (int *, int, char *, char *, int, struct file_header *,
906                                        unsigned int);
907         /*
908          * This function displays the comments.
909          */
910         __printf_funct_t (*f_comment) (int *, int, char *, char *, int, char *, struct file_header *);
911 };
912
913 /* Possible actions for functions used to display reports */
914 #define F_BEGIN 0x01
915 #define F_MAIN  0x02
916 #define F_END   0x04
917
918 /*
919  ***************************************************************************
920  * SVG output definitions
921  ***************************************************************************
922  */
923
924 /*
925  *   ^
926  * 1 | General header
927  *   v
928  *   ^   ^   ^
929  *   |   | 4 | Graph title
930  *   |   |   v
931  *   |   |   ^    |                                Caption
932  *   | 3 |   |    |
933  *   |   |   |  G |Y
934  * 2 |   | 5 |  r |
935  *   |   |   |  a |A
936  *   |   |   |  d |x
937  *   |   |   |  . |i
938  *   |   |   |    |s          X Axis
939  *   |   |   v    |-------------------------------
940  *   |   |              Grad.
941  *   |   v   <---><------------------------------>
942  *   |         6                8
943  *   | Gap
944  *   v<---------------------------------------------------------------> Gap
945  *                                    7
946  *    <--------------------------------------------------------------------->
947  *                                      8
948  */
949
950 /* #8 */
951 #define SVG_G_XSIZE     720
952 /* #6 */
953 #define SVG_M_XSIZE     70
954 /* #7 */
955 #define SVG_V_XSIZE     1050
956 /* #8 */
957 #define SVG_T_XSIZE     1060
958
959 /* #5 */
960 #define SVG_G_YSIZE     200
961 /* #1 */
962 #define SVG_H_YSIZE     50
963 /* #4 */
964 #define SVG_M_YSIZE     50
965 /* #2 */
966 #define SVG_T_YSIZE     310
967 /* #3 */
968 #define SVG_V_YSIZE     300
969
970 /* Grid: Nr of horizontal lines */
971 #define SVG_H_GRIDNR    3
972 /* Grid: Nr of vertical lines */
973 #define SVG_V_GRIDNR    10
974
975 /* Block size used to allocate arrays for graphs data */
976 #define CHUNKSIZE       4096
977
978 /* Maximum number of views on a single row */
979 #define MAX_VIEWS_ON_A_ROW      6
980
981 #define SVG_LINE_GRAPH  1
982 #define SVG_BAR_GRAPH   2
983
984 /* Maximum number of horizontal lines for the background grid */
985 #define MAX_HLINES_NR   10
986
987 #define MAYBE   0x80
988
989 /*
990  ***************************************************************************
991  * Macro functions definitions.
992  *
993  * Note: Using 'do ... while' makes the macros safer to use
994  * (remember that macro use is followed by a semicolon).
995  ***************************************************************************
996  */
997
998 /* Close file descriptors */
999 #define CLOSE_ALL(_fd_)         do {                    \
1000                                         close(_fd_[0]); \
1001                                         close(_fd_[1]); \
1002                                 } while (0)
1003
1004 #define CLOSE(_fd_)             if (_fd_ >= 0)          \
1005                                         close(_fd_)
1006
1007
1008 /*
1009  ***************************************************************************
1010  * Various structure definitions.
1011  ***************************************************************************
1012  */
1013
1014 /* Structure for timestamps */
1015 struct tstamp {
1016         int tm_sec;
1017         int tm_min;
1018         int tm_hour;
1019         int use;
1020 };
1021
1022
1023 /*
1024  ***************************************************************************
1025  * Functions prototypes.
1026  ***************************************************************************
1027  */
1028
1029 /* Functions used to count number of items */
1030 __nr_t wrap_get_cpu_nr
1031         (struct activity *);
1032 __nr_t wrap_get_irq_nr
1033         (struct activity *);
1034 __nr_t wrap_get_serial_nr
1035         (struct activity *);
1036 __nr_t wrap_get_disk_nr
1037         (struct activity *);
1038 __nr_t wrap_get_iface_nr
1039         (struct activity *);
1040 __nr_t wrap_get_fan_nr
1041         (struct activity *);
1042 __nr_t wrap_get_temp_nr
1043         (struct activity *);
1044 __nr_t wrap_get_in_nr
1045         (struct activity *);
1046 __nr_t wrap_get_freq_nr
1047         (struct activity *);
1048 __nr_t wrap_get_usb_nr
1049         (struct activity *);
1050 __nr_t wrap_get_filesystem_nr
1051         (struct activity *);
1052 __nr_t wrap_get_fchost_nr
1053         (struct activity *);
1054
1055 /* Functions used to read activities statistics */
1056 __read_funct_t wrap_read_stat_cpu
1057         (struct activity *);
1058 __read_funct_t wrap_read_stat_pcsw
1059         (struct activity *);
1060 __read_funct_t wrap_read_stat_irq
1061         (struct activity *);
1062 __read_funct_t wrap_read_swap
1063         (struct activity *);
1064 __read_funct_t wrap_read_paging
1065         (struct activity *);
1066 __read_funct_t wrap_read_io
1067         (struct activity *);
1068 __read_funct_t wrap_read_meminfo
1069         (struct activity *);
1070 __read_funct_t wrap_read_kernel_tables
1071         (struct activity *);
1072 __read_funct_t wrap_read_loadavg
1073         (struct activity *);
1074 __read_funct_t wrap_read_tty_driver_serial
1075         (struct activity *);
1076 __read_funct_t wrap_read_disk
1077         (struct activity *);
1078 __read_funct_t wrap_read_net_dev
1079         (struct activity *);
1080 __read_funct_t wrap_read_net_edev
1081         (struct activity *);
1082 __read_funct_t wrap_read_net_nfs
1083         (struct activity *);
1084 __read_funct_t wrap_read_net_nfsd
1085         (struct activity *);
1086 __read_funct_t wrap_read_net_sock
1087         (struct activity *);
1088 __read_funct_t wrap_read_net_ip
1089         (struct activity *);
1090 __read_funct_t wrap_read_net_eip
1091         (struct activity *);
1092 __read_funct_t wrap_read_net_icmp
1093         (struct activity *);
1094 __read_funct_t wrap_read_net_eicmp
1095         (struct activity *);
1096 __read_funct_t wrap_read_net_tcp
1097         (struct activity *);
1098 __read_funct_t wrap_read_net_etcp
1099         (struct activity *);
1100 __read_funct_t wrap_read_net_udp
1101         (struct activity *);
1102 __read_funct_t wrap_read_net_sock6
1103         (struct activity *);
1104 __read_funct_t wrap_read_net_ip6
1105         (struct activity *);
1106 __read_funct_t wrap_read_net_eip6
1107         (struct activity *);
1108 __read_funct_t wrap_read_net_icmp6
1109         (struct activity *);
1110 __read_funct_t wrap_read_net_eicmp6
1111         (struct activity *);
1112 __read_funct_t wrap_read_net_udp6
1113         (struct activity *);
1114 __read_funct_t wrap_read_cpuinfo
1115         (struct activity *);
1116 __read_funct_t wrap_read_fan
1117         (struct activity *);
1118 __read_funct_t wrap_read_temp
1119         (struct activity *);
1120 __read_funct_t wrap_read_in
1121         (struct activity *);
1122 __read_funct_t wrap_read_meminfo_huge
1123         (struct activity *);
1124 __read_funct_t wrap_read_time_in_state
1125         (struct activity *);
1126 __read_funct_t wrap_read_bus_usb_dev
1127         (struct activity *);
1128 __read_funct_t wrap_read_filesystem
1129         (struct activity *);
1130 __read_funct_t wrap_read_fchost
1131         (struct activity *);
1132 __read_funct_t wrap_read_softnet
1133         (struct activity *);
1134
1135 /* Other functions */
1136 void allocate_bitmaps
1137         (struct activity * []);
1138 void allocate_structures
1139         (struct activity * []);
1140 int check_alt_sa_dir
1141         (char *, int, int);
1142 int check_disk_reg
1143         (struct activity *, int, int, int);
1144 void check_file_actlst
1145         (int *, char *, struct activity * [], struct file_magic *, struct file_header *,
1146          struct file_activity **, unsigned int [], int, int *, int *);
1147 int check_net_dev_reg
1148         (struct activity *, int, int, int);
1149 int check_net_edev_reg
1150         (struct activity *, int, int, int);
1151 double compute_ifutil
1152         (struct stats_net_dev *, double, double);
1153 void copy_structures
1154         (struct activity * [], unsigned int [], struct record_header [], int, int);
1155 int datecmp
1156         (struct tm *, struct tstamp *);
1157 void display_sa_file_version
1158         (FILE *, struct file_magic *);
1159 void enum_version_nr
1160         (struct file_magic *);
1161 void free_bitmaps
1162         (struct activity * []);
1163 void free_structures
1164         (struct activity * []);
1165 int get_activity_nr
1166         (struct activity * [], unsigned int, int);
1167 int get_activity_position
1168         (struct activity * [], unsigned int, int);
1169 char *get_devname
1170         (unsigned int, unsigned int, int);
1171 void get_file_timestamp_struct
1172         (unsigned int, struct tm *, struct file_header *);
1173 void get_itv_value
1174         (struct record_header *, struct record_header *, unsigned int,
1175          unsigned long long *, unsigned long long *);
1176 void handle_invalid_sa_file
1177         (int *, struct file_magic *, char *, int);
1178 int next_slice
1179         (unsigned long long, unsigned long long, int, long);
1180 int parse_sar_opt
1181         (char * [], int *, struct activity * [], unsigned int *, int);
1182 int parse_sar_I_opt
1183         (char * [], int *, struct activity * []);
1184 int parse_sa_P_opt
1185         (char * [], int *, unsigned int *, struct activity * []);
1186 int parse_sar_m_opt
1187         (char * [], int *, struct activity * []);
1188 int parse_sar_n_opt
1189         (char * [], int *, struct activity * []);
1190 int parse_timestamp
1191         (char * [], int *, struct tstamp *, const char *);
1192 void print_report_hdr
1193         (unsigned int, struct tm *, struct file_header *, int);
1194 void print_sar_comment
1195         (int *, int, char *, char *, int, char *, struct file_header *);
1196 void print_sar_restart
1197         (int *, int, char *, char *, int, struct file_header *, unsigned int);
1198 int print_special_record
1199         (struct record_header *, unsigned int, struct tstamp *, struct tstamp *,
1200          int, int, struct tm *, struct tm *, char *, int, struct file_magic *,
1201          struct file_header *, struct activity * [], struct report_format *, int, int);
1202 void read_file_stat_bunch
1203         (struct activity * [], int, int, int, struct file_activity *, int, int);
1204 __nr_t read_vol_act_structures
1205         (int, struct activity * [], char *, struct file_magic *, unsigned int, int, int);
1206 int reallocate_vol_act_structures
1207         (struct activity * [], unsigned int, unsigned int);
1208 void remap_struct
1209         (int [], int [], void *, int);
1210 void replace_nonprintable_char
1211         (int, char *);
1212 int sa_fread
1213         (int, void *, int, int);
1214 int sa_get_record_timestamp_struct
1215         (unsigned int, struct record_header *, struct tm *, struct tm *);
1216 int sa_open_read_magic
1217         (int *, char *, struct file_magic *, int, int *);
1218 void select_all_activities
1219         (struct activity * []);
1220 void select_default_activity
1221         (struct activity * []);
1222 void set_bitmap
1223         (unsigned char [], unsigned char, unsigned int);
1224 void set_default_file
1225         (char *, int, int);
1226 void set_hdr_rectime
1227         (unsigned int, struct tm *, struct file_header *);
1228 void set_record_timestamp_string
1229         (unsigned int, struct record_header *, char *, char *, int, struct tm *);
1230 void swap_struct
1231         (int [], void *, int);
1232
1233 #endif  /* _SA_H */