2 * sar/sadc: Report system activity
3 * (C) 1999-2016 by Sebastien Godard (sysstat <at> orange.fr)
14 #include "rd_sensors.h"
17 ***************************************************************************
18 * Activity identification values.
19 ***************************************************************************
22 /* Number of activities */
24 /* The value below is used for sanity check */
25 #define MAX_NR_ACT 256
27 /* Number of functions used to count items */
50 #define A_NET_EICMP 20
54 #define A_NET_SOCK6 24
57 #define A_NET_ICMP6 27
58 #define A_NET_EICMP6 28
60 #define A_PWR_CPUFREQ 30
65 #define A_PWR_WGHFREQ 35
67 #define A_FILESYSTEM 37
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
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
80 ***************************************************************************
82 ***************************************************************************
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 #define S_F_SVG_AUTOSCALE 0x00020000
103 #define S_F_SVG_ONE_DAY 0x00040000
104 #define S_F_SVG_SHOW_IDLE 0x00080000
105 #define S_F_UNIT 0x00100000
107 #define WANT_SINCE_BOOT(m) (((m) & S_F_SINCE_BOOT) == S_F_SINCE_BOOT)
108 #define WANT_SA_ROTAT(m) (((m) & S_F_SA_ROTAT) == S_F_SA_ROTAT)
109 #define USE_PRETTY_OPTION(m) (((m) & S_F_DEV_PRETTY) == S_F_DEV_PRETTY)
110 #define FORCE_FILE(m) (((m) & S_F_FORCE_FILE) == S_F_FORCE_FILE)
111 #define INTERVAL_SET(m) (((m) & S_F_INTERVAL_SET) == S_F_INTERVAL_SET)
112 #define PRINT_TRUE_TIME(m) (((m) & S_F_TRUE_TIME) == S_F_TRUE_TIME)
113 #define LOCK_FILE(m) (((m) & S_F_LOCK_FILE) == S_F_LOCK_FILE)
114 #define PRINT_SEC_EPOCH(m) (((m) & S_F_SEC_EPOCH) == S_F_SEC_EPOCH)
115 #define DISPLAY_HDR_ONLY(m) (((m) & S_F_HDR_ONLY) == S_F_HDR_ONLY)
116 #define FILE_LOCKED(m) (((m) & S_F_FILE_LOCKED) == S_F_FILE_LOCKED)
117 #define USE_SA_YYYYMMDD(m) (((m) & S_F_SA_YYYYMMDD) == S_F_SA_YYYYMMDD)
118 #define DISPLAY_HORIZONTALLY(m) (((m) & S_F_HORIZONTALLY) == S_F_HORIZONTALLY)
119 #define DISPLAY_COMMENT(m) (((m) & S_F_COMMENT) == S_F_COMMENT)
120 #define DISPLAY_PERSIST_NAME_S(m) (((m) & S_F_PERSIST_NAME) == S_F_PERSIST_NAME)
121 #define PRINT_LOCAL_TIME(m) (((m) & S_F_LOCAL_TIME) == S_F_LOCAL_TIME)
122 #define USE_PREFD_TIME_OUTPUT(m) (((m) & S_F_PREFD_TIME_OUTPUT) == S_F_PREFD_TIME_OUTPUT)
123 #define SKIP_EMPTY_VIEWS(m) (((m) & S_F_SVG_SKIP) == S_F_SVG_SKIP)
124 #define AUTOSCALE_ON(m) (((m) & S_F_SVG_AUTOSCALE) == S_F_SVG_AUTOSCALE)
125 #define DISPLAY_ONE_DAY(m) (((m) & S_F_SVG_ONE_DAY) == S_F_SVG_ONE_DAY)
126 #define DISPLAY_IDLE(m) (((m) & S_F_SVG_SHOW_IDLE) == S_F_SVG_SHOW_IDLE)
127 #define DISPLAY_UNIT(m) (((m) & S_F_UNIT) == S_F_UNIT)
129 #define AO_F_NULL 0x00000000
131 /* Output flags for options -R / -r / -S */
132 #define AO_F_MEM_DIA 0x00000001
133 #define AO_F_MEM_AMT 0x00000002
134 #define AO_F_MEM_SWAP 0x00000004
135 /* AO_F_MEM_ALL: See opt_flags in struct activity below */
136 #define AO_F_MEM_ALL (AO_F_MEM_AMT << 8)
138 #define DISPLAY_MEMORY(m) (((m) & AO_F_MEM_DIA) == AO_F_MEM_DIA)
139 #define DISPLAY_MEM_AMT(m) (((m) & AO_F_MEM_AMT) == AO_F_MEM_AMT)
140 #define DISPLAY_SWAP(m) (((m) & AO_F_MEM_SWAP) == AO_F_MEM_SWAP)
141 #define DISPLAY_MEM_ALL(m) (((m) & AO_F_MEM_ALL) == AO_F_MEM_ALL)
143 /* Output flags for option -u [ ALL ] */
144 #define AO_F_CPU_DEF 0x00000001
145 #define AO_F_CPU_ALL 0x00000002
147 #define DISPLAY_CPU_DEF(m) (((m) & AO_F_CPU_DEF) == AO_F_CPU_DEF)
148 #define DISPLAY_CPU_ALL(m) (((m) & AO_F_CPU_ALL) == AO_F_CPU_ALL)
150 /* Output flags for option -d */
151 #define AO_F_DISK_PART 0x00000001
153 #define COLLECT_PARTITIONS(m) (((m) & AO_F_DISK_PART) == AO_F_DISK_PART)
155 /* Output flags for option -F */
156 #define AO_F_FILESYSTEM 0x00000001
157 #define AO_F_MOUNT 0x00000002
159 #define DISPLAY_MOUNT(m) (((m) & AO_F_MOUNT) == AO_F_MOUNT)
162 ***************************************************************************
163 * Various keywords and constants.
164 ***************************************************************************
168 #define K_XALL "XALL"
171 #define K_EDEV "EDEV"
173 #define K_NFSD "NFSD"
174 #define K_SOCK "SOCK"
177 #define K_ICMP "ICMP"
178 #define K_EICMP "EICMP"
180 #define K_ETCP "ETCP"
182 #define K_SOCK6 "SOCK6"
184 #define K_EIP6 "EIP6"
185 #define K_ICMP6 "ICMP6"
186 #define K_EICMP6 "EICMP6"
187 #define K_UDP6 "UDP6"
190 #define K_TEMP "TEMP"
192 #define K_FREQ "FREQ"
193 #define K_MOUNT "MOUNT"
195 #define K_SOFT "SOFT"
198 #define K_DISK "DISK"
199 #define K_XDISK "XDISK"
200 #define K_SNMP "SNMP"
201 #define K_IPV6 "IPV6"
202 #define K_POWER "POWER"
205 #define K_SKIP_EMPTY "skipempty"
206 #define K_AUTOSCALE "autoscale"
207 #define K_ONEDAY "oneday"
208 #define K_SHOWIDLE "showidle"
210 /* Groups of activities */
211 #define G_DEFAULT 0x00
222 /* Time must have the format HH:MM:SS with HH in 24-hour format */
223 #define DEF_TMSTART "08:00:00"
224 #define DEF_TMEND "18:00:00"
226 #define UTSNAME_LEN 65
227 #define HEADER_LINE_LEN 512
230 * Define upper limit for various items.
231 * Made necessary because we have to check the number of
232 * items for each activity when we read a (possibly tainted)
235 #define MAX_NR_SERIAL_LINES 512
236 #define MAX_NR_DISKS 8192
237 #define MAX_NR_IFACES 512
238 #define MAX_NR_FANS 128
239 #define MAX_NR_TEMP_SENSORS 128
240 #define MAX_NR_IN_SENSORS 128
241 #define MAX_NR_USB 1024
242 #define MAX_NR_FS 8192
243 #define MAX_NR_FCHOSTS 8192
245 /* NR_MAX is the upper limit used for unknown activities */
249 /* Maximum number of args that can be passed to sadc */
250 #define MAX_ARGV_NR 32
252 /* Miscellaneous constants */
254 #define USE_SA_FILE 1
255 #define NO_TM_START 0
262 #define ALL_ACTIVITIES ~0U
263 #define EXIT_IF_NOT_FOUND 1
264 #define RESUME_IF_NOT_FOUND 0
273 #define CLOSE_XML_MARKUP 0
274 #define OPEN_XML_MARKUP 1
276 #define CLOSE_JSON_MARKUP 0
277 #define OPEN_JSON_MARKUP 1
279 #define COUNT_ACTIVITIES 0
280 #define COUNT_OUTPUTS 1
282 /* Type for all functions counting items */
284 /* Type for all functions reading statistics */
285 #define __read_funct_t void
286 /* Type for all functions displaying statistics */
287 #define __print_funct_t void
289 /* Structure for SVG specific parameters */
291 unsigned long dt; /* Interval of time for current sample */
292 unsigned long ust_time_ref; /* X axis start time in seconds since the epoch */
293 unsigned long ust_time_end; /* X axis end time in seconds since the epoch */
294 unsigned long ust_time_first; /* Time (in seconds since the epoch) for first sample */
295 int graph_no; /* Total number of views already displayed */
296 int restart; /* TRUE if we have just met a RESTART record */
301 ***************************************************************************
302 * Definitions of header structures.
304 * Format of system activity data files:
307 * | file_magic structure
311 * | file_header structure
315 * | file_activity structure | * sa_act_nr
319 * | record_header structure |
323 * | Statistics structures...(*) |
327 * (*)Note: If it's a special record, we may find a comment instead of
328 * statistics (R_COMMENT record type) or, if it's a R_RESTART record type,
329 * <sa_nr_vol_act> structures (of type file_activity) for the volatile
331 ***************************************************************************
335 * Sysstat magic number. Should never be modified.
336 * Indicate that the file was created by sysstat.
338 #define SYSSTAT_MAGIC 0xd596
341 * Datafile format magic number.
342 * Modified to indicate that the format of the file is
343 * no longer compatible with that of previous sysstat versions.
345 #define FORMAT_MAGIC 0x2173
347 /* Previous datafile format magic number used by older sysstat versions */
348 #define PREVIOUS_FORMAT_MAGIC 0x2171
350 /* Padding in file_magic structure. See below. */
351 #define FILE_MAGIC_PADDING 63
353 /* Structure for file magic header data */
356 * This field identifies the file as a file created by sysstat.
358 unsigned short sysstat_magic;
360 * The value of this field varies whenever datafile format changes.
362 unsigned short format_magic;
364 * Sysstat version used to create the file.
366 unsigned char sysstat_version;
367 unsigned char sysstat_patchlevel;
368 unsigned char sysstat_sublevel;
369 unsigned char sysstat_extraversion;
371 * Size of file's header (size of file_header structure used by file).
373 unsigned int header_size;
375 * Set to non zero if data file has been converted with "sadf -c" from
376 * an old format (version x.y.z) to a newest format (version X.Y.Z).
377 * In this case, the value is: Y*16 + Z + 1.
378 * The FORMAT_MAGIC value of the file can be used to determine X.
380 unsigned char upgraded;
382 * Padding. Reserved for future use while avoiding a format change.
384 unsigned char pad[FILE_MAGIC_PADDING];
387 #define FILE_MAGIC_SIZE (sizeof(struct file_magic))
390 /* Header structure for system activity data file */
393 * Timestamp in seconds since the epoch.
395 unsigned long sa_ust_time __attribute__ ((aligned (8)));
397 * Number of CPU items (1 .. CPU_NR + 1) for the last sample in file.
399 unsigned int sa_last_cpu_nr __attribute__ ((aligned (8)));
401 * Number of activities saved in file.
403 unsigned int sa_act_nr;
405 * Number of volatile activities in file. This is the number of
406 * file_activity structures saved after each restart mark in file.
408 unsigned int sa_vol_act_nr;
410 * Current day, month and year.
411 * No need to save DST (Daylight Saving Time) flag, since it is not taken
412 * into account by the strftime() function used to print the timestamp.
414 unsigned char sa_day;
415 unsigned char sa_month;
416 unsigned char sa_year;
418 * Size of a long integer. Useful to know the architecture on which
419 * the datafile was created.
423 * Operating system name.
425 char sa_sysname[UTSNAME_LEN];
429 char sa_nodename[UTSNAME_LEN];
431 * Operating system release number.
433 char sa_release[UTSNAME_LEN];
435 * Machine architecture.
437 char sa_machine[UTSNAME_LEN];
440 #define FILE_HEADER_SIZE (sizeof(struct file_header))
441 /* The values below are used for sanity check */
442 #define MIN_FILE_HEADER_SIZE 0
443 #define MAX_FILE_HEADER_SIZE 8192
447 * Base magical number for activities.
449 #define ACTIVITY_MAGIC_BASE 0x8a
451 * Magical value used for activities with
452 * unknown format (used for sadf -H only).
454 #define ACTIVITY_MAGIC_UNKNOWN 0x89
456 /* List of activities saved in file */
457 struct file_activity {
459 * Identification value of activity.
461 unsigned int id __attribute__ ((aligned (4)));
463 * Activity magical number.
465 unsigned int magic __attribute__ ((packed));
467 * Number of items for this activity.
469 __nr_t nr __attribute__ ((packed));
471 * Number of sub-items for this activity.
473 __nr_t nr2 __attribute__ ((packed));
475 * Size of an item structure.
477 int size __attribute__ ((packed));
480 #define FILE_ACTIVITY_SIZE (sizeof(struct file_activity))
485 * R_STATS means that this is a record of statistics.
489 * R_RESTART means that this is a special record containing
490 * a LINUX RESTART message.
494 * R_LAST_STATS warns sar that this is the last record to be written
495 * to file before a file rotation, and that the next data to come will
497 * Such a record is tagged R_STATS anyway before being written to file.
499 #define R_LAST_STATS 3
501 * R_COMMENT means that this is a special record containing
506 /* Maximum length of a comment */
507 #define MAX_COMMENT_LEN 64
509 /* Header structure for every record */
510 struct record_header {
512 * Machine uptime (multiplied by the # of proc).
514 unsigned long long uptime __attribute__ ((aligned (16)));
516 * Uptime reduced to one processor. Always set, even on UP machines.
518 unsigned long long uptime0 __attribute__ ((aligned (16)));
520 * Timestamp (number of seconds since the epoch).
522 unsigned long ust_time __attribute__ ((aligned (16)));
524 * Record type: R_STATS, R_RESTART,...
526 unsigned char record_type __attribute__ ((aligned (8)));
528 * Timestamp: Hour (0-23), minute (0-59) and second (0-59).
529 * Used to determine TRUE time (immutable, non locale dependent time).
532 unsigned char minute;
533 unsigned char second;
536 #define RECORD_HEADER_SIZE (sizeof(struct record_header))
540 ***************************************************************************
541 * Generic description of an activity.
542 ***************************************************************************
545 /* Activity options */
548 * Indicate that corresponding activity should be collected by sadc.
550 #define AO_COLLECTED 0x01
552 * Indicate that corresponding activity should be displayed by sar.
554 #define AO_SELECTED 0x02
556 * When appending data to a file, the number of items (for every activity)
557 * is forced to that of the file (number of network interfaces, serial lines,
558 * etc.) Exceptions are volatile activities (like A_CPU) whose number of items
559 * is related to the number of CPUs: If current machine has a different number
560 * of CPU than that of the file (but is equal to sa_last_cpu_nr) then data
561 * will be appended with a number of items equal to that of the machine.
563 #define AO_VOLATILE 0x04
565 * Indicate that the interval of time, given to f_print() function
566 * displaying statistics, should be the interval of time in jiffies
567 * multiplied by the number of processors.
569 #define AO_GLOBAL_ITV 0x08
571 * This flag should be set for every activity closing a markup used
572 * by several activities. Used by sadf f_xml_print() functions to
573 * display XML output.
575 #define AO_CLOSE_MARKUP 0x10
577 * Indicate that corresponding activity has multiple different
578 * output formats. This is the case for example for memory activity
579 * with options -r and -R.
580 * PS: Such an activity should appear in the list of activities that
581 * sar -A is supposed to display.
583 #define AO_MULTIPLE_OUTPUTS 0x20
585 * Indicate that one (SVG) graph will be displayed for each
586 * distinct item for this activity (sadf -g).
588 #define AO_GRAPH_PER_ITEM 0x40
590 #define IS_COLLECTED(m) (((m) & AO_COLLECTED) == AO_COLLECTED)
591 #define IS_SELECTED(m) (((m) & AO_SELECTED) == AO_SELECTED)
592 #define IS_VOLATILE(m) (((m) & AO_VOLATILE) == AO_VOLATILE)
593 #define NEED_GLOBAL_ITV(m) (((m) & AO_GLOBAL_ITV) == AO_GLOBAL_ITV)
594 #define CLOSE_MARKUP(m) (((m) & AO_CLOSE_MARKUP) == AO_CLOSE_MARKUP)
595 #define HAS_MULTIPLE_OUTPUTS(m) (((m) & AO_MULTIPLE_OUTPUTS) == AO_MULTIPLE_OUTPUTS)
596 #define ONE_GRAPH_PER_ITEM(m) (((m) & AO_GRAPH_PER_ITEM) == AO_GRAPH_PER_ITEM)
600 /* Structure used to define a bitmap needed by an activity */
603 * Bitmap for activities that need one. Remember to allocate it
606 unsigned char *b_array;
608 * Size of the bitmap in bits. In fact, bitmap is sized to b_size + 1
609 * to take into account CPU "all"
615 * Structure used to define an activity.
616 * Note: This structure can be modified without changing the format of data files.
620 * This variable contains the identification value (A_...) for this activity.
624 * Activity options (AO_...)
626 unsigned int options;
628 * Activity magical number. This number changes when activity format in file
629 * is no longer compatible with the format of that same activity from
634 * An activity belongs to a group (and only one).
635 * Groups are those selected with option -S of sadc.
639 * Index in f_count[] array to determine function used to count
640 * the number of items (serial lines, network interfaces, etc.) -> @nr
641 * Such a function should _always_ return a value greater than
644 * A value of -1 indicates that the number of items
645 * is a constant (and @nr is set to this value).
647 * These functions are called even if corresponding activities have not
648 * been selected, to make sure that all items have been calculated
649 * (including #CPU, etc.)
653 * The f_count2() function is used to count the number of
655 * Such a function should _always_ return a value greater than
658 * A NULL value for this function pointer indicates that the number of items
659 * is a constant (and @nr2 is set to this value).
661 __nr_t (*f_count2) (struct activity *);
663 * This function reads the relevant file and fill the buffer
664 * with statistics corresponding to given activity.
666 __read_funct_t (*f_read) (struct activity *);
668 * This function displays activity statistics onto the screen.
670 __print_funct_t (*f_print) (struct activity *, int, int, unsigned long long);
672 * This function displays average activity statistics onto the screen.
674 __print_funct_t (*f_print_avg) (struct activity *, int, int, unsigned long long);
676 * This function is used by sadf to display activity in a format that can
677 * easily be ingested by a relational database, or a format that can be
678 * handled by pattern processing commands like "awk".
680 __print_funct_t (*f_render) (struct activity *, int, char *, int, unsigned long long);
682 * This function is used by sadf to display activity statistics in XML.
684 __print_funct_t (*f_xml_print) (struct activity *, int, int, unsigned long long);
686 * This function is used by sadf to display activity statistics in JSON.
688 __print_funct_t (*f_json_print) (struct activity *, int, int, unsigned long long);
690 * This function is used by sadf to display activity statistics in SVG.
692 __print_funct_t (*f_svg_print) (struct activity *, int, int, struct svg_parm *,
693 unsigned long long, struct record_header *);
695 * Header string displayed by sadf -d.
696 * Header lines for each output (for activities with multiple outputs) are
697 * separated with a '|' character.
698 * For a given output, the first field corresponding to extended statistics
699 * (eg. -r ALL) begins with a '&' character.
707 * Number of SVG graphs for this activity. The total number of graphs for
708 * the activity can be greater though if flag AO_GRAPH_PER_ITEM is set, in
709 * which case the total number will be @g_nr * @nr.
713 * Number of items on the system.
714 * A negative value (-1) is the default value and indicates that this number
715 * has still not been calculated by the f_count() function.
716 * A value of 0 means that this number has been calculated, but no items have
718 * A positive value (>0) has either been calculated or is a constant.
722 * Number of sub-items on the system.
723 * @nr2 is in fact the second dimension of a matrix of items, the first
724 * one being @nr. @nr is the number of lines, and @nr2 the number of columns.
725 * A negative value (-1) is the default value and indicates that this number
726 * has still not been calculated by the f_count2() function.
727 * A value of 0 means that this number has been calculated, but no sub-items have
729 * A positive value (>0) has either been calculated or is a constant.
731 * 1) IF @nr2 = 0 THEN @nr = 0
732 * Note: If @nr = 0, then @nr2 is undetermined (may be -1, 0 or >0).
733 * 2) IF @nr > 0 THEN @nr2 > 0.
734 * Note: If @nr2 > 0 then @nr is undetermined (may be -1, 0 or >0).
735 * 3) IF @nr <= 0 THEN @nr2 = -1 (this is the default value for @nr2,
736 * meaning that it has not been calculated).
740 * Maximum number of elements that sar can handle for this item.
741 * NB: The maximum number of elements that sar can handle for sub-items
747 * This is the size of the corresponding structure, as read from or written
748 * to a file, or read from or written by the data collector.
753 * This is the size of the corresponding structure as mapped into memory.
754 * @msize can be different from @fsize when data are read from or written to
755 * a data file from a different sysstat version.
759 * Optional flags for activity. This is eg. used when AO_MULTIPLE_OUTPUTS
761 * 0x0001 - 0x0080 : Multiple outputs (eg. AO_F_MEM_AMT, AO_F_MEM_SWAP...)
762 * 0x0100 - 0x8000 : If bit set then display complete header (hdr_line) for
763 * corresponding output
764 * 0x010000+ : Optional flags
766 unsigned int opt_flags;
768 * Buffers that will contain the statistics read. Its size is @nr * @nr2 * @size each.
770 * [0] and [1]: current/previous statistics values (used by sar).
771 * [2]: Used by sar to save first collected stats (used later to
776 * Bitmap for activities that need one. Such a bitmap is needed by activity
777 * if @bitmap is not NULL.
779 struct act_bitmap *bitmap;
784 ***************************************************************************
785 * Generic description of an output format for sadf (and sar).
786 ***************************************************************************
789 /* Type for all functions used by sadf to display stats in various formats */
790 #define __printf_funct_t void
791 #define __tm_funct_t char *
794 * Structure used to define a report.
795 * A XML-like report has the following format:
801 * | | Statistics block
804 * | | | Timestamp block
807 * | | | | Activity #1
813 * | | | | Activity #n
818 * | | Restart messages block
825 struct report_format {
827 * This variable contains the identification value (F_...) for this report format.
831 * Format options (FO_...).
833 unsigned int options;
835 * This function displays the report header
836 * (data displayed once at the beginning of the report).
838 __printf_funct_t (*f_header) (void *, int, char *, struct file_magic *, struct file_header *,
839 __nr_t, struct activity * [], unsigned int []);
841 * This function defines the statistics part of the report.
842 * Used only with textual (XML-like) reports.
844 __printf_funct_t (*f_statistics) (int *, int);
846 * This function defines the timestamp part of the report.
847 * Used only with textual (XML-like) reports.
849 __tm_funct_t (*f_timestamp) (void *, int, char *, char *, unsigned long long,
850 struct file_header *, unsigned int);
852 * This function displays the restart messages.
854 __printf_funct_t (*f_restart) (int *, int, char *, char *, int, struct file_header *,
857 * This function displays the comments.
859 __printf_funct_t (*f_comment) (int *, int, char *, char *, int, char *, struct file_header *);
862 /* Possible actions for functions used to display reports */
868 ***************************************************************************
869 * SVG output definitions
870 ***************************************************************************
878 * | | 4 | Graph title
888 * | | v |-------------------------------
890 * | v <---><------------------------------>
893 * v<--------------------------------------------------------------->
898 #define SVG_G_XSIZE 720
900 #define SVG_M_XSIZE 70
902 #define SVG_V_XSIZE 1050
905 #define SVG_G_YSIZE 200
907 #define SVG_H_YSIZE 50
909 #define SVG_M_YSIZE 50
911 #define SVG_T_YSIZE 310
913 #define SVG_V_YSIZE 300
915 /* Grid: Nr of horizontal lines */
916 #define SVG_H_GRIDNR 3
917 /* Grid: Nr of vertical lines */
918 #define SVG_V_GRIDNR 10
920 /* Block size used to allocate arrays for graphs data */
921 #define CHUNKSIZE 4096
923 #define SVG_LINE_GRAPH 1
924 #define SVG_BAR_GRAPH 2
929 ***************************************************************************
930 * Macro functions definitions.
932 * Note: Using 'do ... while' makes the macros safer to use
933 * (remember that macro use is followed by a semicolon).
934 ***************************************************************************
937 /* Close file descriptors */
938 #define CLOSE_ALL(_fd_) do { \
943 #define CLOSE(_fd_) if (_fd_ >= 0) \
948 ***************************************************************************
949 * Various structure definitions.
950 ***************************************************************************
953 /* Structure for timestamps */
963 ***************************************************************************
964 * Functions prototypes.
965 ***************************************************************************
968 /* Functions used to count number of items */
969 __nr_t wrap_get_cpu_nr
971 __nr_t wrap_get_irq_nr
973 __nr_t wrap_get_serial_nr
975 __nr_t wrap_get_disk_nr
977 __nr_t wrap_get_iface_nr
979 __nr_t wrap_get_fan_nr
981 __nr_t wrap_get_temp_nr
983 __nr_t wrap_get_in_nr
985 __nr_t wrap_get_freq_nr
987 __nr_t wrap_get_usb_nr
989 __nr_t wrap_get_filesystem_nr
991 __nr_t wrap_get_fchost_nr
994 /* Functions used to read activities statistics */
995 __read_funct_t wrap_read_stat_cpu
997 __read_funct_t wrap_read_stat_pcsw
999 __read_funct_t wrap_read_stat_irq
1000 (struct activity *);
1001 __read_funct_t wrap_read_swap
1002 (struct activity *);
1003 __read_funct_t wrap_read_paging
1004 (struct activity *);
1005 __read_funct_t wrap_read_io
1006 (struct activity *);
1007 __read_funct_t wrap_read_meminfo
1008 (struct activity *);
1009 __read_funct_t wrap_read_kernel_tables
1010 (struct activity *);
1011 __read_funct_t wrap_read_loadavg
1012 (struct activity *);
1013 __read_funct_t wrap_read_tty_driver_serial
1014 (struct activity *);
1015 __read_funct_t wrap_read_disk
1016 (struct activity *);
1017 __read_funct_t wrap_read_net_dev
1018 (struct activity *);
1019 __read_funct_t wrap_read_net_edev
1020 (struct activity *);
1021 __read_funct_t wrap_read_net_nfs
1022 (struct activity *);
1023 __read_funct_t wrap_read_net_nfsd
1024 (struct activity *);
1025 __read_funct_t wrap_read_net_sock
1026 (struct activity *);
1027 __read_funct_t wrap_read_net_ip
1028 (struct activity *);
1029 __read_funct_t wrap_read_net_eip
1030 (struct activity *);
1031 __read_funct_t wrap_read_net_icmp
1032 (struct activity *);
1033 __read_funct_t wrap_read_net_eicmp
1034 (struct activity *);
1035 __read_funct_t wrap_read_net_tcp
1036 (struct activity *);
1037 __read_funct_t wrap_read_net_etcp
1038 (struct activity *);
1039 __read_funct_t wrap_read_net_udp
1040 (struct activity *);
1041 __read_funct_t wrap_read_net_sock6
1042 (struct activity *);
1043 __read_funct_t wrap_read_net_ip6
1044 (struct activity *);
1045 __read_funct_t wrap_read_net_eip6
1046 (struct activity *);
1047 __read_funct_t wrap_read_net_icmp6
1048 (struct activity *);
1049 __read_funct_t wrap_read_net_eicmp6
1050 (struct activity *);
1051 __read_funct_t wrap_read_net_udp6
1052 (struct activity *);
1053 __read_funct_t wrap_read_cpuinfo
1054 (struct activity *);
1055 __read_funct_t wrap_read_fan
1056 (struct activity *);
1057 __read_funct_t wrap_read_temp
1058 (struct activity *);
1059 __read_funct_t wrap_read_in
1060 (struct activity *);
1061 __read_funct_t wrap_read_meminfo_huge
1062 (struct activity *);
1063 __read_funct_t wrap_read_time_in_state
1064 (struct activity *);
1065 __read_funct_t wrap_read_bus_usb_dev
1066 (struct activity *);
1067 __read_funct_t wrap_read_filesystem
1068 (struct activity *);
1069 __read_funct_t wrap_read_fchost
1070 (struct activity *);
1071 __read_funct_t wrap_read_softnet
1072 (struct activity *);
1074 /* Other functions */
1075 void allocate_bitmaps
1076 (struct activity * []);
1077 void allocate_structures
1078 (struct activity * []);
1079 int check_alt_sa_dir
1082 (struct activity *, int, int, int);
1083 void check_file_actlst
1084 (int *, char *, struct activity * [], struct file_magic *, struct file_header *,
1085 struct file_activity **, unsigned int [], int);
1086 int check_net_dev_reg
1087 (struct activity *, int, int, int);
1088 int check_net_edev_reg
1089 (struct activity *, int, int, int);
1090 double compute_ifutil
1091 (struct stats_net_dev *, double, double);
1092 void copy_structures
1093 (struct activity * [], unsigned int [], struct record_header [], int, int);
1095 (struct tm *, struct tstamp *);
1096 void display_sa_file_version
1097 (FILE *, struct file_magic *);
1098 void enum_version_nr
1099 (struct file_magic *);
1101 (struct activity * []);
1102 void free_structures
1103 (struct activity * []);
1105 (struct activity * [], unsigned int, int);
1106 int get_activity_position
1107 (struct activity * [], unsigned int, int);
1109 (unsigned int, unsigned int, int);
1110 void get_file_timestamp_struct
1111 (unsigned int, struct tm *, struct file_header *);
1113 (struct record_header *, struct record_header *, unsigned int,
1114 unsigned long long *, unsigned long long *);
1115 void handle_invalid_sa_file
1116 (int *, struct file_magic *, char *, int);
1118 (unsigned long long, unsigned long long, int, long);
1120 (char * [], int *, struct activity * [], unsigned int *, int);
1122 (char * [], int *, struct activity * []);
1124 (char * [], int *, unsigned int *, struct activity * []);
1126 (char * [], int *, struct activity * []);
1128 (char * [], int *, struct activity * []);
1130 (char * [], int *, struct tstamp *, const char *);
1131 void print_report_hdr
1132 (unsigned int, struct tm *, struct file_header *, int);
1133 void print_sar_comment
1134 (int *, int, char *, char *, int, char *, struct file_header *);
1135 void print_sar_restart
1136 (int *, int, char *, char *, int, struct file_header *, unsigned int);
1137 int print_special_record
1138 (struct record_header *, unsigned int, struct tstamp *, struct tstamp *,
1139 int, int, struct tm *, struct tm *, char *, int, struct file_magic *,
1140 struct file_header *, struct activity * [], struct report_format *);
1141 void read_file_stat_bunch
1142 (struct activity * [], int, int, int, struct file_activity *);
1143 __nr_t read_vol_act_structures
1144 (int, struct activity * [], char *, struct file_magic *, unsigned int);
1145 int reallocate_vol_act_structures
1146 (struct activity * [], unsigned int, unsigned int);
1147 void replace_nonprintable_char
1150 (int, void *, int, int);
1151 int sa_get_record_timestamp_struct
1152 (unsigned int, struct record_header *, struct tm *, struct tm *);
1153 int sa_open_read_magic
1154 (int *, char *, struct file_magic *, int);
1155 void select_all_activities
1156 (struct activity * []);
1157 void select_default_activity
1158 (struct activity * []);
1160 (unsigned char [], unsigned char, unsigned int);
1161 void set_default_file
1163 void set_hdr_rectime
1164 (unsigned int, struct tm *, struct file_header *);
1165 void set_record_timestamp_string
1166 (unsigned int, struct record_header *, char *, char *, int, struct tm *);