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