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 */
24 ***************************************************************************
25 * Output format identification values.
26 ***************************************************************************
29 /* Number of output formats */
34 #define F_HEADER_OUTPUT 2
35 #define F_PPC_OUTPUT 3
36 #define F_XML_OUTPUT 4
37 #define F_JSON_OUTPUT 5
38 #define F_CONV_OUTPUT 6
41 ***************************************************************************
42 * Generic description of an output format.
43 ***************************************************************************
49 * Indicate that all statistics data for one activity should be displayed before
50 * displaying stats for next activity. This is what sar does in its report.
51 * Example: If stats for activities A and B at time t and t' have been collected,
52 * setting AO_GROUPED_STATS for a format will result in the following output:
53 * stats for activity A at t
54 * stats for activity A at t'
55 * stats for activity B at t
56 * stats for activity B at t'
57 * Without this option, output would be:
58 * stats for activity A at t
59 * stats for activity B at t
60 * stats for activity A at t'
61 * stats for activity B at t'
63 #define FO_GROUPED_STATS 0x01
66 * Indicate that output should stop after the header is displayed.
68 #define FO_HEADER_ONLY 0x02
71 * Indicate that a true sysstat activity file but with a bad
72 * format should not yield an error message.
74 #define FO_BAD_FILE_FORMAT 0x04
77 * Indicate that timestamp can be displayed in local time instead of UTC
78 * if option -T or -t has been used.
80 #define FO_LOCAL_TIME 0x08
83 * Indicate that all activities will be displayed horizontally
84 * if option -h is used.
86 #define FO_HORIZONTALLY 0x10
89 * Indicate that the timestamp can be displayed in seconds since the epoch
90 * if option -U has been used.
92 #define FO_SEC_EPOCH 0x20
95 * Indicate that the list of fields should be displayed before the first
98 #define FO_FIELD_LIST 0x40
100 #define DISPLAY_GROUPED_STATS(m) (((m) & FO_GROUPED_STATS) == FO_GROUPED_STATS)
101 #define ACCEPT_HEADER_ONLY(m) (((m) & FO_HEADER_ONLY) == FO_HEADER_ONLY)
102 #define ACCEPT_BAD_FILE_FORMAT(m) (((m) & FO_BAD_FILE_FORMAT) == FO_BAD_FILE_FORMAT)
103 #define ACCEPT_LOCAL_TIME(m) (((m) & FO_LOCAL_TIME) == FO_LOCAL_TIME)
104 #define ACCEPT_HORIZONTALLY(m) (((m) & FO_HORIZONTALLY) == FO_HORIZONTALLY)
105 #define ACCEPT_SEC_EPOCH(m) (((m) & FO_SEC_EPOCH) == FO_SEC_EPOCH)
106 #define DISPLAY_FIELD_LIST(m) (((m) & FO_FIELD_LIST) == FO_FIELD_LIST)
108 /* Type for all functions used by sadf to display stats in various formats */
109 #define __printf_funct_t void
112 * Structure used to define a report.
113 * A XML-like report has the following format:
119 * | | Statistics block
122 * | | | Timestamp block
125 * | | | | Activity #1
131 * | | | | Activity #n
136 * | | Restart messages block
143 struct report_format {
145 * This variable contains the identification value (F_...) for this report format.
149 * Format options (FO_...).
151 unsigned int options;
153 * This function displays the report header
154 * (data displayed once at the beginning of the report).
156 __printf_funct_t (*f_header) (int *, int, char *, struct file_magic *, struct file_header *,
157 __nr_t, struct activity * [], unsigned int []);
159 * This function defines the statistics part of the report.
160 * Used only with textual (XML-like) reports.
162 __printf_funct_t (*f_statistics) (int *, int);
164 * This function defines the timestamp part of the report.
165 * Used only with textual (XML-like) reports.
167 __printf_funct_t (*f_timestamp) (int *, int, char *, char *, int, unsigned long long);
169 * This function displays the restart messages.
171 __printf_funct_t (*f_restart) (int *, int, char *, char *, int, struct file_header *,
174 * This function displays the comments.
176 __printf_funct_t (*f_comment) (int *, int, char *, char *, int, char *, struct file_header *);
180 ***************************************************************************
181 * Various function prototypes
182 ***************************************************************************
186 convert_file(char [], struct activity *[]);
188 xprintf(int, const char *, ...);
190 xprintf0(int, const char *, ...);
193 * Prototypes used to display restart messages
196 print_db_restart(int *, int, char *, char *, int, struct file_header *, unsigned int);
198 print_ppc_restart(int *, int, char *, char *, int, struct file_header *, unsigned int);
200 print_xml_restart(int *, int, char *, char *, int, struct file_header *, unsigned int);
202 print_json_restart(int *, int, char *, char *, int, struct file_header *, unsigned int);
205 * Prototypes used to display comments
208 print_db_comment(int *, int, char *, char *, int, char *, struct file_header *);
210 print_ppc_comment(int *, int, char *, char *, int, char *, struct file_header *);
212 print_xml_comment(int *, int, char *, char *, int, char *, struct file_header *);
214 print_json_comment(int *, int, char *, char *, int, char *, struct file_header *);
217 * Prototypes used to display the statistics part of the report
220 print_xml_statistics(int *, int);
222 print_json_statistics(int *, int);
225 * Prototypes used to display the timestamp part of the report
228 print_xml_timestamp(int *, int, char *, char *, int, unsigned long long);
230 print_json_timestamp(int *, int, char *, char *, int, unsigned long long);
233 * Prototypes used to display the report header
236 print_xml_header(int *, int, char *, struct file_magic *, struct file_header *,
237 __nr_t, struct activity * [], unsigned int []);
239 print_json_header(int *, int, char *, struct file_magic *, struct file_header *,
240 __nr_t, struct activity * [], unsigned int []);
242 print_hdr_header(int *, int, char *, struct file_magic *, struct file_header *,
243 __nr_t, struct activity * [], unsigned int []);