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