2 * sadf: System activity data formatter
3 * (C) 1999-2015 by Sebastien Godard (sysstat <at> orange.fr)
11 /* DTD version for XML output */
12 #define XML_DTD_VERSION "3.1"
14 /* Possible actions for functions used to display reports */
19 /* Various constants */
23 #define IGNORE_NOTHING 0
24 #define IGNORE_RESTART 1
25 #define DONT_READ_VOLATILE 2
26 #define IGNORE_COMMENT 4
29 ***************************************************************************
30 * Output format identification values.
31 ***************************************************************************
34 /* Number of output formats */
39 #define F_HEADER_OUTPUT 2
40 #define F_PPC_OUTPUT 3
41 #define F_XML_OUTPUT 4
42 #define F_JSON_OUTPUT 5
43 #define F_CONV_OUTPUT 6
46 ***************************************************************************
47 * Generic description of an output format.
48 ***************************************************************************
54 * Indicate that all statistics data for one activity should be displayed before
55 * displaying stats for next activity. This is what sar does in its report.
56 * Example: If stats for activities A and B at time t and t' have been collected,
57 * setting AO_GROUPED_STATS for a format will result in the following output:
58 * stats for activity A at t
59 * stats for activity A at t'
60 * stats for activity B at t
61 * stats for activity B at t'
62 * Without this option, output would be:
63 * stats for activity A at t
64 * stats for activity B at t
65 * stats for activity A at t'
66 * stats for activity B at t'
68 #define FO_GROUPED_STATS 0x01
71 * Indicate that output should stop after the header is displayed.
73 #define FO_HEADER_ONLY 0x02
76 * Indicate that a true sysstat activity file but with a bad
77 * format should not yield an error message.
79 #define FO_BAD_FILE_FORMAT 0x04
82 * Indicate that timestamp can be displayed in local time instead of UTC
83 * if option -T or -t has been used.
85 #define FO_LOCAL_TIME 0x08
88 * Indicate that all activities will be displayed horizontally
89 * if option -h is used.
91 #define FO_HORIZONTALLY 0x10
94 * Indicate that the timestamp can be displayed in seconds since the epoch
95 * if option -U has been used.
97 #define FO_SEC_EPOCH 0x20
100 * Indicate that the list of fields should be displayed before the first
101 * line of statistics.
103 #define FO_FIELD_LIST 0x40
105 #define DISPLAY_GROUPED_STATS(m) (((m) & FO_GROUPED_STATS) == FO_GROUPED_STATS)
106 #define ACCEPT_HEADER_ONLY(m) (((m) & FO_HEADER_ONLY) == FO_HEADER_ONLY)
107 #define ACCEPT_BAD_FILE_FORMAT(m) (((m) & FO_BAD_FILE_FORMAT) == FO_BAD_FILE_FORMAT)
108 #define ACCEPT_LOCAL_TIME(m) (((m) & FO_LOCAL_TIME) == FO_LOCAL_TIME)
109 #define ACCEPT_HORIZONTALLY(m) (((m) & FO_HORIZONTALLY) == FO_HORIZONTALLY)
110 #define ACCEPT_SEC_EPOCH(m) (((m) & FO_SEC_EPOCH) == FO_SEC_EPOCH)
111 #define DISPLAY_FIELD_LIST(m) (((m) & FO_FIELD_LIST) == FO_FIELD_LIST)
113 /* Type for all functions used by sadf to display stats in various formats */
114 #define __printf_funct_t void
117 * Structure used to define a report.
118 * A XML-like report has the following format:
124 * | | Statistics block
127 * | | | Timestamp block
130 * | | | | Activity #1
136 * | | | | Activity #n
141 * | | Restart messages block
148 struct report_format {
150 * This variable contains the identification value (F_...) for this report format.
154 * Format options (FO_...).
156 unsigned int options;
158 * This function displays the report header
159 * (data displayed once at the beginning of the report).
161 __printf_funct_t (*f_header) (int *, int, char *, struct file_magic *, struct file_header *,
162 __nr_t, struct activity * [], unsigned int []);
164 * This function defines the statistics part of the report.
165 * Used only with textual (XML-like) reports.
167 __printf_funct_t (*f_statistics) (int *, int);
169 * This function defines the timestamp part of the report.
170 * Used only with textual (XML-like) reports.
172 __printf_funct_t (*f_timestamp) (int *, int, char *, char *, int, unsigned long long);
174 * This function displays the restart messages.
176 __printf_funct_t (*f_restart) (int *, int, char *, char *, int, struct file_header *,
179 * This function displays the comments.
181 __printf_funct_t (*f_comment) (int *, int, char *, char *, int, char *, struct file_header *);
185 ***************************************************************************
186 * Various function prototypes
187 ***************************************************************************
191 convert_file(char [], struct activity *[]);
193 xprintf(int, const char *, ...);
195 xprintf0(int, const char *, ...);
198 * Prototypes used to display restart messages
201 print_db_restart(int *, int, char *, char *, int, struct file_header *, unsigned int);
203 print_ppc_restart(int *, int, char *, char *, int, struct file_header *, unsigned int);
205 print_xml_restart(int *, int, char *, char *, int, struct file_header *, unsigned int);
207 print_json_restart(int *, int, char *, char *, int, struct file_header *, unsigned int);
210 * Prototypes used to display comments
213 print_db_comment(int *, int, char *, char *, int, char *, struct file_header *);
215 print_ppc_comment(int *, int, char *, char *, int, char *, struct file_header *);
217 print_xml_comment(int *, int, char *, char *, int, char *, struct file_header *);
219 print_json_comment(int *, int, char *, char *, int, char *, struct file_header *);
222 * Prototypes used to display the statistics part of the report
225 print_xml_statistics(int *, int);
227 print_json_statistics(int *, int);
230 * Prototypes used to display the timestamp part of the report
233 print_xml_timestamp(int *, int, char *, char *, int, unsigned long long);
235 print_json_timestamp(int *, int, char *, char *, int, unsigned long long);
238 * Prototypes used to display the report header
241 print_xml_header(int *, int, char *, struct file_magic *, struct file_header *,
242 __nr_t, struct activity * [], unsigned int []);
244 print_json_header(int *, int, char *, struct file_magic *, struct file_header *,
245 __nr_t, struct activity * [], unsigned int []);
247 print_hdr_header(int *, int, char *, struct file_magic *, struct file_header *,
248 __nr_t, struct activity * [], unsigned int []);