2 * sar/sadc: Report system activity
3 * (C) 1999-2019 by Sebastien Godard (sysstat <at> orange.fr)
13 #include "rd_sensors.h"
16 ***************************************************************************
17 * Activity identification values.
18 ***************************************************************************
21 /* Number of activities */
23 /* The value below is used for sanity check */
24 #define MAX_NR_ACT 256
26 /* Number of functions used to count items */
49 #define A_NET_EICMP 20
53 #define A_NET_SOCK6 24
56 #define A_NET_ICMP6 27
57 #define A_NET_EICMP6 28
71 /* Macro used to flag an activity that should be collected */
72 #define COLLECT_ACTIVITY(m) act[get_activity_position(act, m, EXIT_IF_NOT_FOUND)]->options |= AO_COLLECTED
74 /* Macro used to flag an activity that should be selected */
75 #define SELECT_ACTIVITY(m) act[get_activity_position(act, m, EXIT_IF_NOT_FOUND)]->options |= AO_SELECTED
79 ***************************************************************************
81 ***************************************************************************
84 #define S_F_SINCE_BOOT 0x00000001
85 #define S_F_SA_ROTAT 0x00000002
86 #define S_F_DEV_PRETTY 0x00000004
87 #define S_F_FORCE_FILE 0x00000008
88 #define S_F_INTERVAL_SET 0x00000010
89 #define S_F_TRUE_TIME 0x00000020
90 #define S_F_LOCK_FILE 0x00000040
91 #define S_F_SEC_EPOCH 0x00000080
92 #define S_F_HDR_ONLY 0x00000100
93 #define S_F_FILE_LOCKED 0x00000200
94 #define S_F_SA_YYYYMMDD 0x00000400
95 #define S_F_HORIZONTALLY 0x00000800
96 #define S_F_COMMENT 0x00001000
97 #define S_F_PERSIST_NAME 0x00002000
98 #define S_F_LOCAL_TIME 0x00004000
99 #define S_F_PREFD_TIME_OUTPUT 0x00008000
100 #define S_F_SVG_SKIP 0x00010000
101 /* Same value as S_F_SVG_SKIP above. Used for a different output format */
102 #define S_F_RAW_DEBUG_MODE 0x00010000
103 #define S_F_SVG_AUTOSCALE 0x00020000
104 #define S_F_SVG_ONE_DAY 0x00040000
105 #define S_F_SVG_SHOW_IDLE 0x00080000
106 #define S_F_UNIT 0x00100000
107 #define S_F_SVG_HEIGHT 0x00200000
108 #define S_F_SVG_PACKED 0x00400000
109 #define S_F_SVG_SHOW_INFO 0x00800000
110 #define S_F_HUMAN_READ 0x01000000
111 #define S_F_ZERO_OMIT 0x02000000
112 #define S_F_SVG_SHOW_TOC 0x04000000
113 #define S_F_FDATASYNC 0x08000000
115 #define WANT_SINCE_BOOT(m) (((m) & S_F_SINCE_BOOT) == S_F_SINCE_BOOT)
116 #define WANT_SA_ROTAT(m) (((m) & S_F_SA_ROTAT) == S_F_SA_ROTAT)
117 #define USE_PRETTY_OPTION(m) (((m) & S_F_DEV_PRETTY) == S_F_DEV_PRETTY)
118 #define FORCE_FILE(m) (((m) & S_F_FORCE_FILE) == S_F_FORCE_FILE)
119 #define INTERVAL_SET(m) (((m) & S_F_INTERVAL_SET) == S_F_INTERVAL_SET)
120 #define PRINT_TRUE_TIME(m) (((m) & S_F_TRUE_TIME) == S_F_TRUE_TIME)
121 #define LOCK_FILE(m) (((m) & S_F_LOCK_FILE) == S_F_LOCK_FILE)
122 #define PRINT_SEC_EPOCH(m) (((m) & S_F_SEC_EPOCH) == S_F_SEC_EPOCH)
123 #define DISPLAY_HDR_ONLY(m) (((m) & S_F_HDR_ONLY) == S_F_HDR_ONLY)
124 #define FILE_LOCKED(m) (((m) & S_F_FILE_LOCKED) == S_F_FILE_LOCKED)
125 #define USE_SA_YYYYMMDD(m) (((m) & S_F_SA_YYYYMMDD) == S_F_SA_YYYYMMDD)
126 #define DISPLAY_HORIZONTALLY(m) (((m) & S_F_HORIZONTALLY) == S_F_HORIZONTALLY)
127 #define DISPLAY_COMMENT(m) (((m) & S_F_COMMENT) == S_F_COMMENT)
128 #define DISPLAY_PERSIST_NAME_S(m) (((m) & S_F_PERSIST_NAME) == S_F_PERSIST_NAME)
129 #define PRINT_LOCAL_TIME(m) (((m) & S_F_LOCAL_TIME) == S_F_LOCAL_TIME)
130 #define USE_PREFD_TIME_OUTPUT(m) (((m) & S_F_PREFD_TIME_OUTPUT) == S_F_PREFD_TIME_OUTPUT)
131 #define SKIP_EMPTY_VIEWS(m) (((m) & S_F_SVG_SKIP) == S_F_SVG_SKIP)
132 #define DISPLAY_ZERO_OMIT(m) (((m) & S_F_ZERO_OMIT) == S_F_ZERO_OMIT)
133 #define DISPLAY_DEBUG_MODE(m) (((m) & S_F_RAW_DEBUG_MODE) == S_F_RAW_DEBUG_MODE)
134 #define AUTOSCALE_ON(m) (((m) & S_F_SVG_AUTOSCALE) == S_F_SVG_AUTOSCALE)
135 #define DISPLAY_ONE_DAY(m) (((m) & S_F_SVG_ONE_DAY) == S_F_SVG_ONE_DAY)
136 #define DISPLAY_IDLE(m) (((m) & S_F_SVG_SHOW_IDLE) == S_F_SVG_SHOW_IDLE)
137 #define DISPLAY_INFO(m) (((m) & S_F_SVG_SHOW_INFO) == S_F_SVG_SHOW_INFO)
138 #define DISPLAY_UNIT(m) (((m) & S_F_UNIT) == S_F_UNIT)
139 #define SET_CANVAS_HEIGHT(m) (((m) & S_F_SVG_HEIGHT) == S_F_SVG_HEIGHT)
140 #define PACK_VIEWS(m) (((m) & S_F_SVG_PACKED) == S_F_SVG_PACKED)
141 #define DISPLAY_HUMAN_READ(m) (((m) & S_F_HUMAN_READ) == S_F_HUMAN_READ)
142 #define DISPLAY_TOC(m) (((m) & S_F_SVG_SHOW_TOC) == S_F_SVG_SHOW_TOC)
143 #define FDATASYNC(m) (((m) & S_F_FDATASYNC) == S_F_FDATASYNC)
145 #define AO_F_NULL 0x00000000
147 /* Output flags for options -r / -S */
148 #define AO_F_MEMORY 0x00000001
149 #define AO_F_SWAP 0x00000002
150 /* AO_F_MEM_ALL: See opt_flags in struct activity below */
151 #define AO_F_MEM_ALL (AO_F_MEMORY << 8)
153 #define DISPLAY_MEMORY(m) (((m) & AO_F_MEMORY) == AO_F_MEMORY)
154 #define DISPLAY_SWAP(m) (((m) & AO_F_SWAP) == AO_F_SWAP)
155 #define DISPLAY_MEM_ALL(m) (((m) & AO_F_MEM_ALL) == AO_F_MEM_ALL)
157 /* Output flags for option -u [ ALL ] */
158 #define AO_F_CPU_DEF 0x00000001
159 #define AO_F_CPU_ALL 0x00000002
161 #define DISPLAY_CPU_DEF(m) (((m) & AO_F_CPU_DEF) == AO_F_CPU_DEF)
162 #define DISPLAY_CPU_ALL(m) (((m) & AO_F_CPU_ALL) == AO_F_CPU_ALL)
164 /* Output flags for option -d */
165 #define AO_F_DISK_PART 0x00000001
167 #define COLLECT_PARTITIONS(m) (((m) & AO_F_DISK_PART) == AO_F_DISK_PART)
169 /* Output flags for option -F */
170 #define AO_F_FILESYSTEM 0x00000001
171 #define AO_F_MOUNT 0x00000002
173 #define DISPLAY_MOUNT(m) (((m) & AO_F_MOUNT) == AO_F_MOUNT)
176 ***************************************************************************
177 * Various keywords and constants.
178 ***************************************************************************
182 #define K_A_NULL "A_NULL"
183 #define K_XALL "XALL"
186 #define K_EDEV "EDEV"
188 #define K_NFSD "NFSD"
189 #define K_SOCK "SOCK"
192 #define K_ICMP "ICMP"
193 #define K_EICMP "EICMP"
195 #define K_ETCP "ETCP"
197 #define K_SOCK6 "SOCK6"
199 #define K_EIP6 "EIP6"
200 #define K_ICMP6 "ICMP6"
201 #define K_EICMP6 "EICMP6"
202 #define K_UDP6 "UDP6"
205 #define K_TEMP "TEMP"
207 #define K_FREQ "FREQ"
208 #define K_MOUNT "MOUNT"
210 #define K_SOFT "SOFT"
213 #define K_DISK "DISK"
214 #define K_XDISK "XDISK"
215 #define K_SNMP "SNMP"
216 #define K_IPV6 "IPV6"
217 #define K_POWER "POWER"
220 #define K_SKIP_EMPTY "skipempty"
221 #define K_AUTOSCALE "autoscale"
222 #define K_ONEDAY "oneday"
223 #define K_SHOWIDLE "showidle"
224 #define K_SHOWINFO "showinfo"
225 #define K_DEBUG "debug"
226 #define K_HEIGHT "height="
227 #define K_PACKED "packed"
228 #define K_SHOWTOC "showtoc"
229 #define K_CUSTOMCOL "customcol"
230 #define K_BWCOL "bwcol"
231 #define K_PCPARCHIVE "pcparchive="
233 /* Environment variables */
234 #define ENV_COLORS_PALETTE "S_COLORS_PALETTE"
236 /* Groups of activities */
237 #define G_DEFAULT 0x00
248 /* Time must have the format HH:MM:SS with HH in 24-hour format */
249 #define DEF_TMSTART "08:00:00"
250 #define DEF_TMEND "18:00:00"
252 #define UTSNAME_LEN 65
253 #define HEADER_LINE_LEN 512
256 * Define upper limit for various items.
257 * Made necessary because we have to check the number of
258 * items for each activity when we read a (possibly tainted)
261 #define MAX_NR_SERIAL_LINES 65536
262 #define MAX_NR_DISKS (65536 * 4096)
263 #define MAX_NR_IFACES 65536
264 #define MAX_NR_FANS 4096
265 #define MAX_NR_TEMP_SENSORS 4096
266 #define MAX_NR_IN_SENSORS 4096
267 #define MAX_NR_USB 65536
268 #define MAX_NR_FS (65536 * 4096)
269 #define MAX_NR_FCHOSTS 65536
271 /* NR_MAX is the upper limit used for unknown activities */
272 #define NR_MAX (65536 * 4096)
275 /* Maximum number of args that can be passed to sadc */
276 #define MAX_ARGV_NR 32
278 /* Miscellaneous constants */
280 #define USE_SA_FILE 1
281 #define NO_TM_START 0
288 #define ALL_ACTIVITIES ~0U
289 #define EXIT_IF_NOT_FOUND 1
290 #define RESUME_IF_NOT_FOUND 0
298 #define END_OF_DATA_UNEXPECTED 1
299 #define INCONSISTENT_INPUT_DATA 2
304 #define CLOSE_XML_MARKUP 0
305 #define OPEN_XML_MARKUP 1
307 #define CLOSE_JSON_MARKUP 0
308 #define OPEN_JSON_MARKUP 1
310 #define COUNT_ACTIVITIES 0
311 #define COUNT_OUTPUTS 1
313 /* Type for all functions reading statistics */
314 #define __read_funct_t void
315 /* Type for all functions displaying statistics */
316 #define __print_funct_t void
318 /* Structure for SVG specific parameters */
320 unsigned long long dt; /* Interval of time for current sample */
321 unsigned long long ust_time_ref; /* X axis start time in seconds since the epoch */
322 unsigned long long ust_time_end; /* X axis end time in seconds since the epoch */
323 unsigned long long ust_time_first; /* Time (in seconds since the epoch) for first sample */
324 int graph_no; /* Total number of views already displayed */
325 int restart; /* TRUE if we have just met a RESTART record */
326 int nr_act_dispd; /* Number of activities that will be displayed */
327 struct file_header *file_hdr; /* Pointer on file header structure */
330 /* Structure used when displaying SVG header */
331 struct svg_hdr_parm {
332 int graph_nr; /* Number of rows of views to display or canvas height entered on the command line */
333 int views_per_row; /* Maximum number of views on a single row */
334 int nr_act_dispd; /* Number of activities that will be displayed */
338 ***************************************************************************
339 * System activity data files
341 * The rule is: "strict writing, read any", meaning that sar/sadc can
342 * only append data to a datafile whose format is strictly the same as that
343 * of current version (checking FORMAT_MAGIC is not enough), but sar/sadf
344 * can read data from different versions, providing that FORMAT_MAGIC value
345 * has not changed (note that we are talking here of data read from a file,
346 * not data that sar reads from sadc, in which case the "strict" rule applies).
348 * Format of system activity data files:
351 * | file_magic structure
355 * | file_header structure
359 * | file_activity structure | * sa_act_nr
363 * | record_header structure |
369 * | Statistics structure(s) | * <count>
375 * | Statistics structure(s)... |
379 * Note: For activities with varying number of items, a __nr_t value, giving
380 * the number of items, arrives before the statistics structures so that
381 * we know how many of them have to be read.
382 * NB: This value exists for all the activities even if they share the same
383 * count function (e.g. A_NET_DEV and A_NET_EDEV). Indeed, statistics are not
384 * read atomically and the number of items (e.g. network interfaces) may have
387 * If the record header's type is R_COMMENT then we find only a comment
388 * following the record_header structure.
389 * If the record_header's type is R_RESTART then we find only the number of CPU
390 * (of type __nr_t) of the machine following the record_header structure.
391 ***************************************************************************
395 * Sysstat magic number. Should never be modified.
396 * Indicate that the file was created by sysstat.
398 #define SYSSTAT_MAGIC 0xd596
399 #define SYSSTAT_MAGIC_SWAPPED (((SYSSTAT_MAGIC << 8) | (SYSSTAT_MAGIC >> 8)) & 0xffff)
402 * Datafile format magic number.
403 * Modified to indicate that the format of the file is
404 * no longer compatible with that of previous sysstat versions.
406 #define FORMAT_MAGIC 0x2175
407 #define FORMAT_MAGIC_SWAPPED (((FORMAT_MAGIC << 8) | (FORMAT_MAGIC >> 8)) & 0xffff)
409 /* Previous datafile format magic numbers used by older sysstat versions */
410 #define FORMAT_MAGIC_2171 0x2171
411 #define FORMAT_MAGIC_2171_SWAPPED (((FORMAT_MAGIC_2171 << 8) | (FORMAT_MAGIC_2171 >> 8)) & 0xffff)
412 #define FORMAT_MAGIC_2173 0x2173
413 #define FORMAT_MAGIC_2173_SWAPPED (((FORMAT_MAGIC_2173 << 8) | (FORMAT_MAGIC_2173 >> 8)) & 0xffff)
415 /* Padding in file_magic structure. See below. */
416 #define FILE_MAGIC_PADDING 48
418 /* Structure for file magic header data */
421 * This field identifies the file as a file created by sysstat.
423 unsigned short sysstat_magic;
425 * The value of this field varies whenever datafile format changes.
427 unsigned short format_magic;
429 * Sysstat version used to create the file.
431 unsigned char sysstat_version;
432 unsigned char sysstat_patchlevel;
433 unsigned char sysstat_sublevel;
434 unsigned char sysstat_extraversion;
435 #define FILE_MAGIC_ULL_NR 0 /* Nr of unsigned long long below */
436 #define FILE_MAGIC_UL_NR 0 /* Nr of unsigned long below */
437 #define FILE_MAGIC_U_NR 5 /* Nr of [unsigned] int below */
439 * Size of file's header (size of file_header structure used by file).
441 unsigned int header_size;
443 * Set to non zero if data file has been converted with "sadf -c" from
444 * an old format (version x.y.z) to a newest format (version X.Y.Z).
445 * In this case, the value is: Y*256 + Z + 1.
446 * The FORMAT_MAGIC value of the file can be used to determine X.
448 unsigned int upgraded;
450 * Description of the file_header structure
451 * (nr of "long long", nr of "long" and nr of "int").
453 unsigned int hdr_types_nr[3];
455 * Padding. Reserved for future use while avoiding a format change.
456 * sysstat always reads a number of bytes which is that expected for
457 * current sysstat version (FILE_MAGIC_SIZE). We cannot guess if we
458 * are going to read a file from current, an older or a newer version.
460 unsigned char pad[FILE_MAGIC_PADDING];
463 #define FILE_MAGIC_SIZE (sizeof(struct file_magic))
465 /* Header structure for system activity data file */
468 * Timestamp in seconds since the epoch.
470 unsigned long long sa_ust_time;
472 * Number of jiffies per second.
474 unsigned long sa_hz __attribute__ ((aligned (8)));
476 * Number of [online or offline] CPU (1 .. CPU_NR + 1)
477 * when the datafile has been created.
478 * When reading a datafile, this value is updated (in memory)
479 * whenever a RESTART record is found.
480 * When writing or appending data to a file, this field is updated
481 * neither in file nor in memory.
483 unsigned int sa_cpu_nr __attribute__ ((aligned (8)));
485 * Number of activities saved in file.
487 unsigned int sa_act_nr;
493 * Description of the file_activity and record_header structures
494 * (nr of "long long", nr of "long" and nr of "int").
496 unsigned int act_types_nr[3];
497 unsigned int rec_types_nr[3];
499 * Size of file_activity and record_header structures used by file.
501 unsigned int act_size;
502 unsigned int rec_size;
504 * Current day and month.
505 * No need to save DST (Daylight Saving Time) flag, since it is not taken
506 * into account by the strftime() function used to print the timestamp.
508 unsigned char sa_day;
509 unsigned char sa_month;
511 * Size of a long integer. Useful to know the architecture on which
512 * the datafile was created.
516 * Operating system name.
518 char sa_sysname[UTSNAME_LEN];
522 char sa_nodename[UTSNAME_LEN];
524 * Operating system release number.
526 char sa_release[UTSNAME_LEN];
528 * Machine architecture.
530 char sa_machine[UTSNAME_LEN];
533 #define FILE_HEADER_SIZE (sizeof(struct file_header))
534 #define FILE_HEADER_ULL_NR 1 /* Nr of unsigned long long in file_header structure */
535 #define FILE_HEADER_UL_NR 1 /* Nr of unsigned long in file_header structure */
536 #define FILE_HEADER_U_NR 11 /* Nr of [unsigned] int in file_header structure */
537 /* The values below are used for sanity check */
538 #define MIN_FILE_HEADER_SIZE 0
539 #define MAX_FILE_HEADER_SIZE 8192
543 * Base magical number for activities.
545 #define ACTIVITY_MAGIC_BASE 0x8a
547 * Magical value used for activities with
548 * unknown format (used for sadf -H only).
550 #define ACTIVITY_MAGIC_UNKNOWN 0x89
552 /* List of activities saved in file */
553 struct file_activity {
555 * Identification value of activity.
559 * Activity magical number.
563 * Number of items for this activity
564 * when the data file has been created.
568 * Number of sub-items for this activity.
572 * Set to TRUE if statistics are preceded by
573 * a value giving the number of structures to read.
577 * Size of an item structure.
581 * Description of the structure containing statistics for the
582 * given activity (nr of "long long", nr of "long" and nr of "int").
584 unsigned int types_nr[3];
587 #define FILE_ACTIVITY_SIZE (sizeof(struct file_activity))
588 #define MAX_FILE_ACTIVITY_SIZE 1024 /* Used for sanity check */
589 #define FILE_ACTIVITY_ULL_NR 0 /* Nr of unsigned long long in file_activity structure */
590 #define FILE_ACTIVITY_UL_NR 0 /* Nr of unsigned long in file_activity structure */
591 #define FILE_ACTIVITY_U_NR 9 /* Nr of [unsigned] int in file_activity structure */
596 * R_STATS means that this is a record of statistics.
600 * R_RESTART means that this is a special record containing
601 * a LINUX RESTART message.
605 * R_LAST_STATS warns sar that this is the last record to be written
606 * to file before a file rotation, and that the next data to come will
608 * Such a record is tagged R_STATS anyway before being written to file.
610 #define R_LAST_STATS 3
612 * R_COMMENT means that this is a special record containing
617 /* Maximum length of a comment */
618 #define MAX_COMMENT_LEN 64
620 /* Header structure for every record */
621 struct record_header {
623 * Machine uptime in 1/100th of a second.
625 unsigned long long uptime_cs;
627 * Timestamp (number of seconds since the epoch).
629 unsigned long long ust_time;
631 * Record type: R_STATS, R_RESTART,...
633 unsigned char record_type;
635 * Timestamp: Hour (0-23), minute (0-59) and second (0-59).
636 * Used to determine TRUE time (immutable, non locale dependent time).
639 unsigned char minute;
640 unsigned char second;
643 #define RECORD_HEADER_SIZE (sizeof(struct record_header))
644 #define MAX_RECORD_HEADER_SIZE 512 /* Used for sanity check */
645 #define RECORD_HEADER_ULL_NR 2 /* Nr of unsigned long long in record_header structure */
646 #define RECORD_HEADER_UL_NR 0 /* Nr of unsigned long in record_header structure */
647 #define RECORD_HEADER_U_NR 0 /* Nr of unsigned int in record_header structure */
651 ***************************************************************************
652 * Generic description of an activity.
653 ***************************************************************************
656 /* Activity options */
659 * Indicate that corresponding activity should be collected by sadc.
661 #define AO_COLLECTED 0x01
663 * Indicate that corresponding activity should be displayed by sar.
665 #define AO_SELECTED 0x02
667 * Indicate that corresponding activity has items that need to be counted.
668 * This means that its @f_count_index values is >= 0.
669 * (We use AO_COUNTED instead of @f_count_index because @f_count_index
670 * is available (initialized) only for sadc).
672 #define AO_COUNTED 0x04
674 * Indicate that activity's metrics have persistent values when devices
675 * are registered again (this means that when the device is registered again,
676 * the metrics pick the values they had when they had been unregistered).
677 * Exclusively used for CPU related statistics at the present time.
679 #define AO_PERSISTENT 0x08
681 * This flag should be set for every activity closing a markup used
682 * by several activities. Used by sadf f_xml_print() functions to
683 * display XML output.
685 #define AO_CLOSE_MARKUP 0x10
687 * Indicate that corresponding activity has multiple different
688 * output formats. This is the case for example for memory activity
689 * with options -r and -R.
690 * PS: Such an activity should appear in the list of activities that
691 * sar -A is supposed to display.
693 #define AO_MULTIPLE_OUTPUTS 0x20
695 * Indicate that one (SVG) graph will be displayed for each
696 * distinct item for this activity (sadf -g).
698 #define AO_GRAPH_PER_ITEM 0x40
700 * Indicate that this activity may have sub-items.
702 #define AO_MATRIX 0x80
704 * Indicate that a list of devices has been entered on the command
705 * line for this activity (see options --dev=, --iface=, ...)
707 #define AO_LIST_ON_CMDLINE 0x100
709 #define IS_COLLECTED(m) (((m) & AO_COLLECTED) == AO_COLLECTED)
710 #define IS_SELECTED(m) (((m) & AO_SELECTED) == AO_SELECTED)
711 #define HAS_COUNT_FUNCTION(m) (((m) & AO_COUNTED) == AO_COUNTED)
712 #define HAS_PERSISTENT_VALUES(m) (((m) & AO_PERSISTENT) == AO_PERSISTENT)
713 #define CLOSE_MARKUP(m) (((m) & AO_CLOSE_MARKUP) == AO_CLOSE_MARKUP)
714 #define HAS_MULTIPLE_OUTPUTS(m) (((m) & AO_MULTIPLE_OUTPUTS) == AO_MULTIPLE_OUTPUTS)
715 #define ONE_GRAPH_PER_ITEM(m) (((m) & AO_GRAPH_PER_ITEM) == AO_GRAPH_PER_ITEM)
716 #define IS_MATRIX(m) (((m) & AO_MATRIX) == AO_MATRIX)
717 #define HAS_LIST_ON_CMDLINE(m) (((m) & AO_LIST_ON_CMDLINE) == AO_LIST_ON_CMDLINE)
722 /* Structure used to define a bitmap needed by an activity */
725 * Bitmap for activities that need one. Remember to allocate it
728 unsigned char *b_array;
730 * Size of the bitmap in bits. In fact, bitmap is sized to b_size + 1
731 * to take into account CPU "all"
737 * Structure used to define an activity.
738 * Note: This structure can be modified without changing the format of data files.
742 * This variable contains the identification value (A_...) for this activity.
746 * Activity options (AO_...)
748 unsigned int options;
750 * Activity magical number. This number changes when activity format in file
751 * is no longer compatible with the format of that same activity from
756 * An activity belongs to a group (and only one).
757 * Groups are those selected with option -S of sadc.
761 * Index in f_count[] array to determine function used to count
762 * the number of items (serial lines, network interfaces, etc.) -> @nr
763 * Such a function should _always_ return a value greater than
766 * A value of -1 indicates that the number of items
767 * is a constant (and @nr is set to this value).
769 * These functions are called even if corresponding activities have not
770 * been selected, to make sure that all items have been calculated
771 * (including #CPU, etc.)
775 * The f_count2() function is used to count the number of
777 * Such a function should _always_ return a value greater than
780 * A NULL value for this function pointer indicates that the number of items
781 * is a constant (and @nr2 is set to this value).
783 __nr_t (*f_count2) (struct activity *);
785 * This function reads the relevant file and fill the buffer
786 * with statistics corresponding to given activity.
788 __read_funct_t (*f_read) (struct activity *);
790 * This function displays activity statistics onto the screen.
792 __print_funct_t (*f_print) (struct activity *, int, int, unsigned long long);
794 * This function displays average activity statistics onto the screen.
796 __print_funct_t (*f_print_avg) (struct activity *, int, int, unsigned long long);
798 * This function is used by sadf to display activity in a format that can
799 * easily be ingested by a relational database, or a format that can be
800 * handled by pattern processing commands like "awk".
802 __print_funct_t (*f_render) (struct activity *, int, char *, int, unsigned long long);
804 * This function is used by sadf to display activity statistics in XML.
806 __print_funct_t (*f_xml_print) (struct activity *, int, int, unsigned long long);
808 * This function is used by sadf to display activity statistics in JSON.
810 __print_funct_t (*f_json_print) (struct activity *, int, int, unsigned long long);
812 * This function is used by sadf to display activity statistics in SVG.
814 __print_funct_t (*f_svg_print) (struct activity *, int, int, struct svg_parm *,
815 unsigned long long, struct record_header *);
817 * This function is used by sadf to display activity statistics in raw format.
819 __print_funct_t (*f_raw_print) (struct activity *, char *, int);
821 * This function is used by sadf to count the number of new items in current
822 * sample and add them to the linked list @item_list.
824 __nr_t (*f_count_new) (struct activity *, int);
826 * Linked list containing item names. This is either all the different items
827 * found in a file for activities that have a @f_count_function() (used by sadf),
828 * or a list entered on the command line (used by sadf and sar).
830 struct sa_item *item_list;
832 * Number of different items found in file (calculated by sadf).
833 * This is also the number of items in @item_list if this list exists.
837 * Header string displayed by sadf -d.
838 * Header lines for each output (for activities with multiple outputs) are
839 * separated with a '|' character.
840 * For a given output, the first field corresponding to extended statistics
841 * (eg. -r ALL) begins with a '&' character.
845 * Description of activity.
853 * Description of the corresponding structure containing statistics (as defined
854 * in rd_stats.h or rd_sensors.h). Such a structure has 0+ fields of type
855 * "long long", followed by 0+ fields of type "long", followed by 0+ fields of
856 * type "int", followed by 0+ other fields (e.g. of type char). The array below
857 * gives the number of "long long" fields composing the structure, then the number
858 * of "long" fields, then the number of "int" fields.
860 unsigned int gtypes_nr[3];
862 * This array has the same meaning as @gtypes_nr[] above, but the values are those
863 * read from current data file. They may be different from those of @gtypes_nr[]
864 * because we can read data from a different sysstat version (older or newer).
866 unsigned int ftypes_nr[3];
868 * Number of SVG graphs for this activity. The total number of graphs for
869 * the activity can be greater though if flag AO_GRAPH_PER_ITEM is set, in
870 * which case the total number will be @g_nr * @nr.
874 * Number of items on the system, as counted when the system is initialized.
875 * A negative value (-1) is the default value and indicates that this number
876 * has still not been calculated by the f_count() function.
877 * A value of 0 means that this number has been calculated, but no items have
879 * A positive value (>0) has either been calculated or is a constant.
883 * Number of sub-items on the system.
884 * @nr2 is in fact the second dimension of a matrix of items, the first
885 * one being @nr. @nr is the number of lines, and @nr2 the number of columns.
886 * A negative value (-1) is the default value and indicates that this number
887 * has still not been calculated by the f_count2() function.
888 * A value of 0 means that this number has been calculated, but no sub-items have
890 * A positive value (>0) has either been calculated or is a constant.
892 * 1) IF @nr2 = 0 THEN @nr = 0
893 * Note: If @nr = 0, then @nr2 is undetermined (may be -1, 0 or >0).
894 * 2) IF @nr > 0 THEN @nr2 > 0.
895 * Note: If @nr2 > 0 then @nr is undetermined (may be -1, 0 or >0).
896 * 3) IF @nr <= 0 THEN @nr2 = -1 (this is the default value for @nr2,
897 * meaning that it has not been calculated).
901 * Maximum number of elements that sar can handle for this item.
902 * NB: The maximum number of elements that sar can handle for sub-items
907 * Number of items, as read and saved in corresponding buffer (@buf: See below).
908 * The value may be zero for a particular sample if no items have been found.
912 * Number of structures allocated in @buf[*]. This number should be greater
913 * than or equal to @nr[*].
918 * This is the size of the corresponding structure, as read from or written
919 * to a file, or read from or written by the data collector.
924 * This is the size of the corresponding structure as mapped into memory.
925 * @msize can be different from @fsize when data are read from or written to
926 * a data file from a different sysstat version.
930 * Optional flags for activity. This is eg. used when AO_MULTIPLE_OUTPUTS
932 * 0x0001 - 0x0080 : Multiple outputs (eg. AO_F_MEMORY, AO_F_SWAP...)
933 * 0x0100 - 0x8000 : If bit set then display complete header (hdr_line) for
934 * corresponding output
935 * 0x010000+ : Optional flags
937 unsigned int opt_flags;
939 * Buffers that will contain the statistics read. Its size is @nr * @nr2 * @size each.
941 * [0] and [1]: current/previous statistics values (used by sar).
942 * [2]: Used by sar to save first collected stats (used later to
947 * Bitmap for activities that need one. Such a bitmap is needed by activity
948 * if @bitmap is not NULL.
950 struct act_bitmap *bitmap;
955 ***************************************************************************
956 * Generic description of an output format for sadf (and sar).
957 ***************************************************************************
960 /* Type for all functions used by sadf to display stats in various formats */
961 #define __printf_funct_t void
962 #define __tm_funct_t char *
965 * Structure used to define a report.
966 * A XML-like report has the following format:
972 * | | Statistics block
975 * | | | Timestamp block
978 * | | | | Activity #1
984 * | | | | Activity #n
989 * | | Restart messages block
996 struct report_format {
998 * This variable contains the identification value (F_...) for this report format.
1002 * Format options (FO_...).
1004 unsigned int options;
1006 * This function displays the report header
1007 * (data displayed once at the beginning of the report).
1009 __printf_funct_t (*f_header) (void *, int, char *, struct file_magic *, struct file_header *,
1010 struct activity * [], unsigned int [], struct file_activity *);
1012 * This function defines the statistics part of the report.
1013 * Used only with textual (XML-like) reports.
1015 __printf_funct_t (*f_statistics) (int *, int);
1017 * This function defines the timestamp part of the report.
1018 * Used only with textual (XML-like) reports.
1020 __tm_funct_t (*f_timestamp) (void *, int, char *, char *, unsigned long long,
1021 struct file_header *, unsigned int);
1023 * This function displays the restart messages.
1025 __printf_funct_t (*f_restart) (int *, int, char *, char *, int, struct file_header *);
1027 * This function displays the comments.
1029 __printf_funct_t (*f_comment) (int *, int, char *, char *, int, char *, struct file_header *);
1032 /* Possible actions for functions used to display reports */
1033 #define F_BEGIN 0x01
1038 ***************************************************************************
1039 * SVG output definitions
1040 ***************************************************************************
1045 * 1 | General header
1048 * 9 | One line from table of contents (if any)
1051 * | | 4 | Graph title
1061 * | | v |-------------------------------
1063 * | v <---><------------------------------>
1066 * v<---------------------------------------------------------------> Gap
1068 * <--------------------------------------------------------------------->
1073 #define SVG_G_XSIZE 720
1075 #define SVG_M_XSIZE 70
1077 #define SVG_V_XSIZE 1050
1079 #define SVG_T_XSIZE 1060
1082 #define SVG_G_YSIZE 200
1084 #define SVG_H_YSIZE 60
1086 #define SVG_M_YSIZE 50
1088 #define SVG_T_YSIZE 310
1090 #define SVG_V_YSIZE 300
1092 #define SVG_C_YSIZE 20
1094 /* Grid: Nr of horizontal lines */
1095 #define SVG_H_GRIDNR 3
1096 /* Grid: Nr of vertical lines */
1097 #define SVG_V_GRIDNR 10
1099 /* Block size used to allocate arrays for graphs data */
1100 #define CHUNKSIZE 4096
1102 /* Maximum number of views on a single row */
1103 #define MAX_VIEWS_ON_A_ROW 6
1105 #define SVG_LINE_GRAPH 1
1106 #define SVG_BAR_GRAPH 2
1108 /* Maximum number of horizontal lines for the background grid */
1109 #define MAX_HLINES_NR 10
1111 /* Color palette constants */
1112 #define SVG_COLORS_IDX_MASK 0x0f
1113 #define SVG_COL_PALETTE_SIZE 24
1114 #define SVG_COL_PALETTE_NR 3
1115 #define SVG_COL_BCKGRD_IDX 16
1116 #define SVG_COL_AXIS_IDX 17
1117 #define SVG_COL_GRID_IDX 18
1118 #define SVG_COL_TITLE_IDX 19
1119 #define SVG_COL_INFO_IDX 20
1120 #define SVG_COL_DEFAULT_IDX 21
1121 #define SVG_COL_HEADER_IDX 22
1122 #define SVG_COL_ERROR_IDX 23
1124 #define SVG_DEFAULT_COL_PALETTE 0
1125 #define SVG_CUSTOM_COL_PALETTE 1
1126 #define SVG_BW_COL_PALETTE 2
1131 ***************************************************************************
1132 * Macro functions definitions.
1134 * Note: Using 'do ... while' makes the macros safer to use
1135 * (remember that macro use is followed by a semicolon).
1136 ***************************************************************************
1139 /* Close file descriptors */
1140 #define CLOSE_ALL(_fd_) do { \
1145 #define CLOSE(_fd_) if (_fd_ >= 0) \
1150 ***************************************************************************
1151 * Various structure definitions.
1152 ***************************************************************************
1155 /* Structure for timestamps */
1163 /* Structure for items in list */
1166 struct sa_item *next;
1171 ***************************************************************************
1172 * Functions prototypes.
1173 ***************************************************************************
1177 * Prototypes used to count new items
1179 __nr_t count_new_net_dev
1180 (struct activity *, int);
1181 __nr_t count_new_net_edev
1182 (struct activity *, int);
1183 __nr_t count_new_filesystem
1184 (struct activity *, int);
1185 __nr_t count_new_fchost
1186 (struct activity *, int);
1187 __nr_t count_new_disk
1188 (struct activity *, int);
1190 /* Functions used to count number of items */
1191 __nr_t wrap_get_cpu_nr
1192 (struct activity *);
1193 __nr_t wrap_get_irq_nr
1194 (struct activity *);
1195 __nr_t wrap_get_serial_nr
1196 (struct activity *);
1197 __nr_t wrap_get_disk_nr
1198 (struct activity *);
1199 __nr_t wrap_get_iface_nr
1200 (struct activity *);
1201 __nr_t wrap_get_fan_nr
1202 (struct activity *);
1203 __nr_t wrap_get_temp_nr
1204 (struct activity *);
1205 __nr_t wrap_get_in_nr
1206 (struct activity *);
1207 __nr_t wrap_get_freq_nr
1208 (struct activity *);
1209 __nr_t wrap_get_usb_nr
1210 (struct activity *);
1211 __nr_t wrap_get_filesystem_nr
1212 (struct activity *);
1213 __nr_t wrap_get_fchost_nr
1214 (struct activity *);
1216 /* Functions used to read activities statistics */
1217 __read_funct_t wrap_read_stat_cpu
1218 (struct activity *);
1219 __read_funct_t wrap_read_stat_pcsw
1220 (struct activity *);
1221 __read_funct_t wrap_read_stat_irq
1222 (struct activity *);
1223 __read_funct_t wrap_read_swap
1224 (struct activity *);
1225 __read_funct_t wrap_read_paging
1226 (struct activity *);
1227 __read_funct_t wrap_read_io
1228 (struct activity *);
1229 __read_funct_t wrap_read_meminfo
1230 (struct activity *);
1231 __read_funct_t wrap_read_kernel_tables
1232 (struct activity *);
1233 __read_funct_t wrap_read_loadavg
1234 (struct activity *);
1235 __read_funct_t wrap_read_tty_driver_serial
1236 (struct activity *);
1237 __read_funct_t wrap_read_disk
1238 (struct activity *);
1239 __read_funct_t wrap_read_net_dev
1240 (struct activity *);
1241 __read_funct_t wrap_read_net_edev
1242 (struct activity *);
1243 __read_funct_t wrap_read_net_nfs
1244 (struct activity *);
1245 __read_funct_t wrap_read_net_nfsd
1246 (struct activity *);
1247 __read_funct_t wrap_read_net_sock
1248 (struct activity *);
1249 __read_funct_t wrap_read_net_ip
1250 (struct activity *);
1251 __read_funct_t wrap_read_net_eip
1252 (struct activity *);
1253 __read_funct_t wrap_read_net_icmp
1254 (struct activity *);
1255 __read_funct_t wrap_read_net_eicmp
1256 (struct activity *);
1257 __read_funct_t wrap_read_net_tcp
1258 (struct activity *);
1259 __read_funct_t wrap_read_net_etcp
1260 (struct activity *);
1261 __read_funct_t wrap_read_net_udp
1262 (struct activity *);
1263 __read_funct_t wrap_read_net_sock6
1264 (struct activity *);
1265 __read_funct_t wrap_read_net_ip6
1266 (struct activity *);
1267 __read_funct_t wrap_read_net_eip6
1268 (struct activity *);
1269 __read_funct_t wrap_read_net_icmp6
1270 (struct activity *);
1271 __read_funct_t wrap_read_net_eicmp6
1272 (struct activity *);
1273 __read_funct_t wrap_read_net_udp6
1274 (struct activity *);
1275 __read_funct_t wrap_read_cpuinfo
1276 (struct activity *);
1277 __read_funct_t wrap_read_fan
1278 (struct activity *);
1279 __read_funct_t wrap_read_temp
1280 (struct activity *);
1281 __read_funct_t wrap_read_in
1282 (struct activity *);
1283 __read_funct_t wrap_read_meminfo_huge
1284 (struct activity *);
1285 __read_funct_t wrap_read_cpu_wghfreq
1286 (struct activity *);
1287 __read_funct_t wrap_read_bus_usb_dev
1288 (struct activity *);
1289 __read_funct_t wrap_read_filesystem
1290 (struct activity *);
1291 __read_funct_t wrap_read_fchost
1292 (struct activity *);
1293 __read_funct_t wrap_read_softnet
1294 (struct activity *);
1296 /* Other functions */
1297 int check_alt_sa_dir
1299 void enum_version_nr
1300 (struct file_magic *);
1302 (struct activity * [], unsigned int, int);
1303 int get_activity_position
1304 (struct activity * [], unsigned int, int);
1305 void handle_invalid_sa_file
1306 (int, struct file_magic *, char *, int);
1307 void print_collect_error
1309 int set_default_file
1312 (int, const void *, int);
1316 (struct sa_item **, char *, int);
1317 void allocate_bitmaps
1318 (struct activity * []);
1319 void allocate_structures
1320 (struct activity * []);
1322 (struct activity *, int, int, int);
1323 void check_file_actlst
1324 (int *, char *, struct activity * [], struct file_magic *, struct file_header *,
1325 struct file_activity **, unsigned int [], int, int *, int *);
1326 int check_net_dev_reg
1327 (struct activity *, int, int, int);
1328 int check_net_edev_reg
1329 (struct activity *, int, int, int);
1330 double compute_ifutil
1331 (struct stats_net_dev *, double, double);
1332 void copy_structures
1333 (struct activity * [], unsigned int [], struct record_header [], int, int);
1335 (struct tm *, struct tstamp *);
1336 void display_sa_file_version
1337 (FILE *, struct file_magic *);
1339 (struct activity * []);
1340 void free_structures
1341 (struct activity * []);
1343 (unsigned int, unsigned int, int);
1344 char *get_sa_devname
1345 (unsigned int, unsigned int, unsigned int);
1346 void get_file_timestamp_struct
1347 (unsigned int, struct tm *, struct file_header *);
1348 unsigned long long get_global_cpu_statistics
1349 (struct activity *, int, int, unsigned int, unsigned char []);
1350 void get_global_soft_statistics
1351 (struct activity *, int, int, unsigned int, unsigned char []);
1353 (struct record_header *, struct record_header *, unsigned long long *);
1354 void init_custom_color_palette
1357 (unsigned long long, unsigned long long, int, long);
1358 void parse_sa_devices
1359 (char *, struct activity *, int, int *, int);
1361 (char * [], int *, struct activity * [], unsigned int *, int);
1363 (char * [], int *, struct activity * []);
1365 (char * [], int *, unsigned int *, struct activity * []);
1367 (char * [], int *, struct activity * []);
1369 (char * [], int *, struct activity * []);
1371 (char * [], int *, struct tstamp *, const char *);
1372 void print_report_hdr
1373 (unsigned int, struct tm *, struct file_header *);
1374 void print_sar_comment
1375 (int *, int, char *, char *, int, char *, struct file_header *);
1376 __printf_funct_t print_sar_restart
1377 (int *, int, char *, char *, int, struct file_header *);
1378 int print_special_record
1379 (struct record_header *, unsigned int, struct tstamp *, struct tstamp *,
1380 int, int, struct tm *, struct tm *, char *, int, struct file_magic *,
1381 struct file_header *, struct activity * [], struct report_format *, int, int);
1382 int read_file_stat_bunch
1383 (struct activity * [], int, int, int, struct file_activity *, int, int,
1384 char *, struct file_magic *, int);
1385 __nr_t read_nr_value
1386 (int, char *, struct file_magic *, int, int, int);
1388 (int, void *, struct record_header *, struct file_header *, int, int,
1390 void reallocate_all_buffers
1391 (struct activity *, __nr_t);
1392 void replace_nonprintable_char
1395 (int, void *, size_t, int, int);
1396 int sa_get_record_timestamp_struct
1397 (unsigned int, struct record_header *, struct tm *, struct tm *);
1398 int sa_open_read_magic
1399 (int *, char *, struct file_magic *, int, int *, int);
1400 int search_list_item
1401 (struct sa_item *, char *);
1402 void select_all_activities
1403 (struct activity * []);
1404 void select_default_activity
1405 (struct activity * []);
1407 (unsigned char [], unsigned char, unsigned int);
1408 void set_hdr_rectime
1409 (unsigned int, struct tm *, struct file_header *);
1410 void set_record_timestamp_string
1411 (unsigned int, struct record_header *, char *, char *, int, struct tm *);
1413 (unsigned int [], void *, int);
1414 #endif /* SOURCE_SADC undefined */